1
$\begingroup$

Here I present what I created:

DynamicModule[
 {sliderA = 1, sliderB = 1, animateTime = 2 Pi, player = 1, 
  turnMaxTime = 5, turnTime = 5},
 Column@{
   (* timer with remining turn time 
   NOTE: not sure if this is best implementation for such a task *)
   Row@{
     "Remaining time: ",
     Animator[Dynamic@turnTime, {turnMaxTime, 0, 1}, 
      AppearanceElements -> "ProgressSlider", 
      AnimationRunning -> 
       Dynamic@Which[animateTime < 2 Pi, False, animateTime == 2 Pi, True], 
      ImageSize -> 500],
     " " , 
     Dynamic@Which[animateTime < 2 Pi, False, animateTime == 2 Pi, 
       True], " ",
     Dynamic[turnTime]
     },
   (* sliders providing user input *)
   Row@{
     "sliderA ", 
     Slider[Dynamic@sliderA, {-1, 1}, Appearance -> "Labeled"],
     "sliderB ", 
     Slider[Dynamic@sliderB, {-1, 1}, Appearance -> "Labeled"]},
   (* second timer which is supposed to start when the first reaches 0,
   when this one reaches max value it should start again the first timer *)
   Row@{
     "Animate timer: ",
     Animator[Dynamic@animateTime, {0, 2 Pi, Pi/10}, 3, 
      AppearanceElements -> "ProgressSlider", 
      AnimationRunning -> 
       Dynamic@Which[turnTime < 5, False, turnTime == 5, True], 
      ImageSize -> 500],
     " " , Dynamic@Which[turnTime < 5, False, turnTime == 5, True], 
     " ",
     Dynamic[animateTime]},
   Dynamic[
    Plot[sliderA Sin[sliderB x], {x, 0, animateTime + .1}, 
     PlotRange -> {{0, 2 Pi}, {-1.1, 1.1}}, ImageSize -> 600, 
     AspectRatio -> 1/3]]
   }
 ]

What I was trying to achive, was some kind of turn-based user input, first user has a finite time to set sliderA and sliderB values, when the time reaches zero it should trigger an animation of plot being drawn with parameters set before (sliderA, sliderB). If you run this code you will see that I failed hard :D I find it rather complicated, probably because I'm new to Mathematica, however this one seems be working in some way. For example I dont know why the first Animator@turnTime seems to be running even when the statement of its AnimationRunning option is false (turnTime value is changing even if the slider is not moving). Can you tell me how can I implement such behaviour in Mathematica? I'll be gratefull for any kind of help - articles, sites, tutorials (I may add I've read these about Dynamic and Manipulate provided by Wolfram as well as function documentation) or code samples. Kind regards, M.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.