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$

2 Answers 2

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}}]
$\endgroup$
1
  • $\begingroup$ great - thank you - so simple! :) $\endgroup$
    – martin
    Jun 10, 2016 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

$\endgroup$
1
  • $\begingroup$ Wonderful - thanks very much $\endgroup$
    – martin
    Jun 10, 2016 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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