2
$\begingroup$

I'd like the locator to update to its new position when k is altered:

Manipulate[ Graphics[{}, PlotRange -> 2, Frame -> True], 
{{c, If[k == 0, {0, 0}, If[k == 1, {0, 1}, {0, 2}]]}, Locator, 
Appearance -> Graphics[{Disk[{0, 0}]}, ImageSize -> 10]}, 
{{k, 0}, {0, 1, 2}}]

Have tried with Dynamic, but failing abysmally. Could someone please point me in the right direction?

$\endgroup$
4
$\begingroup$

Body of Manipulate is effectively wrapped with Dynamic so we can just put it there:

Manipulate[
 c = If[k == 0, {0, 0}, If[k == 1, {0, 1}, {0, 2}]];

 Graphics[{}, PlotRange -> 2, Frame -> True], 

 {{c, {0, 0}}, Locator, Appearance -> Graphics[{Disk[{0, 0}]}, ImageSize -> 10]}, 
 {{k,    0}, {0, 1, 2}}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ great - thank you - so simple! :) $\endgroup$ – martin Jun 10 '16 at 10:16
4
$\begingroup$

Example

Code

DynamicModule[
 {k = 0},
 Column[{
   (*Control*)
   SetterBar[Dynamic @ k, {0, 1}],
   (*Visual*)
   Dynamic @ Graphics[
     Switch[k,
      0,  Locator[{0, 0}],
      1, Locator[{0, 1}]],
     (*Graphics Options*)
     Axes -> True,
     PlotRange -> 2
     ]
   },
  (*Column Options*)
  Alignment -> Center]
 ]

Output

output example

| improve this answer | |
$\endgroup$
  • $\begingroup$ Wonderful - thanks very much $\endgroup$ – martin Jun 10 '16 at 10:15

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.