TransWikia.com

Can you dynamically display the value of the slider in Animate?

Mathematica Asked by Youvan on June 16, 2021

It would be nice to be able to see the value of t changing as the animation progresses even if it is updating so fast that you have to stop the slider to read the number.

Animate[Graphics[{Circle[], Point[{Cos[t], Sin[t]}]}], {t, 0, 6}, 
 AnimationRunning -> False]

3 Answers

1. You can simply add the option Appearance -> "Labeled" in Animator control:

Animate[Graphics[{Circle[], PointSize[Large], Point[{Cos[t], Sin[t]}]}],
  {t, 0, 6, Appearance -> "Labeled", AnimationRunning -> False}]

enter image description here

2. Alternatively, you can define a custom control with desired elements combining a labeled slider with animator elements:

ClearAll[labeledAnimator]
labeledAnimator = Row[{Slider[##, Appearance -> "Labeled"], 
     Animator[##, AnimationRunning -> False, 
      AppearanceElements -> {"StepLeftButton", "StepRightButton", 
        "PlayPauseButton", "FasterSlowerButtons", "DirectionButton"}]}, 
    Spacer[1]] &;

Use labeledAnimator with Manipulate (it does not work with Animator) and add the option AppearanceElements -> {} to get the Animator look/feel:

Manipulate[Graphics[{Circle[], PointSize[Large], Point[{Cos[t], Sin[t]}]}], 
   {t, 0, 6, labeledAnimator, AnimationRunning -> False}, 
 AppearanceElements -> {}]

enter image description here

3. Using a variation on Alexey Popkov's idea: use a LabeledSlider as control label and remove the progress slider default list of animator appearance elements:

Animate[Graphics[{Circle[], PointSize[Large], Point[{Cos[t], Sin[t]}]}],
 {{t, 0, Dynamic@LabeledSlider[t, {0, 10}]}, 0, 10, 
  AppearanceElements -> {"PlayPauseButton", "FasterSlowerButtons", 
    "DirectionButton", "ResetButton"}}, 
 AnimationRunning -> False]

enter image description here

Correct answer by kglr on June 16, 2021

In addition to the excellent solution described by @kglr, one can make a custom label. Try this:

Animate[Graphics[{Circle[], PointSize[Large], 
   Point[{Cos[t], Sin[t]}]}],
 {{t, 0, Dynamic@
    Panel[Row[{Style["Time: ", Blue, 14], Style[t, Red, 14]}], 
     ImageSize -> {180, 50}]}, 0, 10}]

with the effect of

enter image description here

Have fun!

Answered by Alexei Boulbitch on June 16, 2021

In case you are not aware, you can simply include t in the layout of the content area :

Animate[Column[{
   t,
   Graphics[{Circle[], Point[{Cos[t], Sin[t]}]}]
   }]
 , {t, 0, 6}, AnimationRunning -> False]  

[enter image description here][

Answered by andre314 on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP