Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted
DynamicModule[{r, r2}, Manipulate[{Slider2D[Dynamic@r], 
    If[ToExpression@checked, Slider2D[Dynamic[1 - r]], Slider2D[Dynamic[r2]]]}, 
    {checked, {"True", "False"}}, ControlType -> Checkbox]]
share|improve this answer
    
Is there any reason why not True/False? –  Kuba Mar 26 at 19:52

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}]
share|improve this answer

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]}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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