2
$\begingroup$

This creates two locked sliders

DynamicModule[{p = {2 π, 0}, r},
 {Slider2D[Dynamic[r]], Slider2D[Dynamic[1 - r, (r = 1 - #) &]]}]

enter image description here

How can I add a check box so that I can control whether to lock them or not? If the check box is check, the second slider sync to the first one and then they are locked as above, and if the check box is unchecked, they they can move independently.

I tried something like this

DynamicModule[{p = {2 π, 0}, checked = True, r,r2 },
 {Slider2D[Dynamic[r]], Slider2D[Dynamic[If[checked, 1 - r, r2]]], 
  Checkbox[Dynamic[checked]]}]

or this

DynamicModule[{p = {2 π, 0}, r, r2, checked = True},
 {Slider2D[Dynamic[r]], 
  Refresh@If[checked, Slider2D[Dynamic[1 - r, (r = 1 - #) &]], 
    Slider2D[Dynamic[r2]]], Checkbox[Dynamic[checked]]}]

but neither of them worked.

$\endgroup$
3
$\begingroup$
DynamicModule[{r, r2}, Manipulate[{Slider2D[Dynamic@r], 
    If[ToExpression@checked, Slider2D[Dynamic[1 - r]], Slider2D[Dynamic[r2]]]}, 
    {checked, {"True", "False"}}, ControlType -> Checkbox]]
$\endgroup$
  • $\begingroup$ Is there any reason why not True/False? $\endgroup$ – Kuba Mar 26 '14 at 19:52
3
$\begingroup$

What about

x=y={0.5, 0.5}; locked = True;
Slider2D@Dynamic[x, (x = #; If[locked, y = 1-#]) &]
Slider2D@Dynamic[y, (y = #; If[locked, x = 1-#]) &]
Checkbox@Dynamic@locked
Dynamic[{x, y}]
$\endgroup$
2
$\begingroup$

Or..

DynamicModule[{f, lock, r, t}, 
 f = If[lock, Slider2D[Dynamic[1 - r, (r = 1 - #) &]], 
   Slider2D[Dynamic[t]]]; {Checkbox[Dynamic[lock]], 
  Slider2D[Dynamic[r]], Dynamic[f]}]
$\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.