4

I'm trying to make a control item in a Manipulate that is a simple dial. I'm trying to mimic Manipulate[theta, {theta, 0, 360}], but with a dial instead of a Slider.

I've sort of done this (see code below), but my variable pt doesn't reset to its original value when I hit the ResetButton. Any help would be appreciated.

DynamicModule[
 {pt = {0.5, 0.5}},
 Manipulate[
  ArcTan @@ pt,
  DynamicModule[
   {},
   LocatorPane[
    Dynamic[pt],
    Graphics[
     {
      Line[{{1.1, 0}, {0, 0}}],
      EdgeForm[Thin],
      {LightGray, Disk[]},
      {Lighter@Lighter@LightGray, Disk[{0, 0}, 0.9]},
      Dynamic[Disk[0.7 Normalize[pt], 0.08]]
      },
     PlotRange -> 1.3,
     ImageSize -> 60],
    Appearance -> None
    ]
   ],
  AppearanceElements -> "ResetButton"
  ]
 ]
Kuba
  • 136,707
  • 13
  • 279
  • 740
rhomboidRhipper
  • 856
  • 4
  • 7

1 Answers1

4

It is because ResetButton refers to Manipulate`s initial state while pt is outer DynamicModule variable here. You can scope variables in Manipulate with a cool trick, which I've learned here: {{pt, {0.5, 0.5}}, None}

Manipulate[
  ArcTan @@ pt,
  {{pt, {0.5, 0.5}}, None},
  DynamicModule[{}, LocatorPane[   Dynamic[pt], 
                     Graphics[{Line[{{1.1, 0}, {0, 0}}], EdgeForm[Thin],
                           {LightGray, Disk[]}, {Lighter@Lighter@LightGray, 
                           Disk[{0, 0}, 0.9]}, Dynamic[Disk[0.7 Normalize[pt], 0.08]]}, 
                           PlotRange -> 1.3, ImageSize -> 60], Appearance -> None]], 
 AppearanceElements -> "ResetButton"]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740