0
$\begingroup$

I would like to have a Slider2D for a variable x but at the same time I have RadioButtonBar for another variable U. I want the Slider2D's range to change as I change U.

I wrote this code but it doesn't work. I assume I miss some basic knowledge here I might use DynamicWrapper or something else.

edges = Which[
   U == 1., 4,
   U == 10., 6,
   U == 100., 10,
   U == 1000., 23,
   U == 10000., 45,
   U == 100000., 100
   ];

DynamicModule[{x, U}, {

  Text@Item["U=" Dynamic@U], 
  RadioButtonBar[Dynamic@U, {1., 10., 100.}],
  Slider2D[Dynamic[x], {{0, 0}, {edges, edges}}, Appearance -> "Labeled"]

  }]
```
$\endgroup$
2
$\begingroup$

Make edges a function and wrap the second argument in DynamicModule with Dynamic:

DynamicModule[{x, U = 1.}, Dynamic @ 
 {Text@Item["U=" Dynamic[U]], 
   RadioButtonBar[Dynamic@U, {1., 10., 100.}], 
   Slider2D[Dynamic[x], {{0, 0}, {edges@U, edges@U}}, Appearance -> "Labeled"]}, 
 Initialization :> {edges[U_] := Which[U == 1., 4, U == 10., 6, U == 100., 10, U == 1000., 23, 
     U == 10000., 45, U == 100000., 100]}]

enter image description here

| 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.