2
$\begingroup$

I found a code to create multiple controls for a manipulate with a manipulate input and is working perfectly.

Manipulate[
 With[{value = Table[c[i], {i, 1, n}], 
   controls = Sequence @@ Table[{c[i], 0, 1}, {i, 1, n}]}, 
  Manipulate[value, controls]], {n, 1, 10, 1}]

But what I need is to do the same thing with locators instead of points and the motion of the locators should be constrained to vertical motion at their respective x points. The locator action can be viewed from the following code

Manipulate[
 Show[Graphics[{Line[{{0, point[1][[2]]}, {1, point[2][[2]]}, {2, 
       point[3][[2]]}, {3, point[4][[2]]}, {4, point[5][[2]]}}], 
    Locator[{0, point[1][[2]]}], Locator[{1, point[2][[2]]}], 
    Locator[{2, point[3][[2]]}], Locator[{3, point[4][[2]]}], 
    Locator[{4, point[5][[2]]}]}, 
   PlotRange -> {{0, 5}, {0, 2}}]], {{point[1], {0, 0}}, Locator, 
  Appearance -> None}, {{point[2], {1, 0}}, Locator, 
  Appearance -> None}, {{point[3], {2, 0}}, Locator, 
  Appearance -> None}, {{point[4], {3, 0}}, Locator, 
  Appearance -> None}, {{point[5], {4, 0}}, Locator, 
  Appearance -> None}]

Here, instead of the specified number of locator points, it should be updated on the go. The closest code I got is the following but it gives an error.

Manipulate[
 With[{pointlist = Table[{i - 1, point[i][[2]]}, {i, 1, n}], 
   Locatorlist = Table[Locator[{i - 1, point[i][[2]]}], {i, 1, n}],
   controls = 
    Sequence @@ 
     Table[{{point[i], {i - 1, 0}}, Locator, Appearance -> None}, {i, 
       1, n}]},
  Manipulate[{MatrixForm[pointlist], 
    Show[Graphics[{Line[pointlist], Locatorlist}, 
      PlotRange -> {{0, n}, {0, 10}}]]}, controls]], {n, 2, 10, 1}]

The error message generated are 1. "Coordinate $CellContext`point[2] should be a pair of numbers, or a Scaled or Offset form." 2. "Part 2 of point[1] does not exist. >>" Eventhough the error is generated I am able to get the motion constraint and the graph is getting plotted. I cannot use vertical sliders as this has to be plotted on a graph with multiple set of the same. Can anyone help me, please???

$\endgroup$
2
$\begingroup$

After a few hit and trials, I found the answer to my own question. I had to call the variables in the second Manipulate section. The code is:

Manipulate[With[{pointarr = Table[point[i], {i, 1, n}],
   controls = 
    Sequence @@ 
     Table[{{point[i], {i - 1, 0}}, Locator, Appearance -> None}, {i, 
       1, n}]},
  Manipulate[pointlist = Table[{i - 1, pointarr[[i, 2]]}, {i, 1, n}]; 
   Locatorlist = Table[Locator[{i - 1, pointarr[[i, 2]]}], {i, 1, n}];
    Show[Graphics[{Line[pointlist], Locatorlist}, 
     PlotRange -> {{0, n}, {0, 10}}]], controls]], {n, 2, 10, 1}]

Its working perfect now. Hope the solution might be useful to someone. Thanks and Happy new year.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.