5
$\begingroup$

Is there any way to stop an animation in Manipulate once it gets to the end? I assumed AnimationRepetitions would work like in ListAnimate, but it still loops for me. For Comparison:

ListAnimate[Table[i, {i, 0, 1, 0.1}], AnimationRepetitions -> 1](*Stops after one animation*)

Manipulate[i, {i, 0, 1, 0.1, Appearance -> "Open", AnimationRate -> 0.2, AnimationRunning -> True,   AnimationRepetitions -> 1}](*Loops Continuously*)
$\endgroup$
2
  • $\begingroup$ Ok, there's got to be a better way, but using Manipulate[i, {i, 0, 1, 0.1, Appearance -> "Open", AnimationRate -> 0.2, AnimationRunning -> (i < 1)}] works. Well, as long as you never touch the controls again... 🙃 $\endgroup$
    – thorimur
    Commented Mar 19, 2021 at 9:43
  • $\begingroup$ You received three answers and you’ve not upvoted, not accepted, not commented on whether any of them do what you want or don’t do what you want, or thanked them. These people are volunteering to help you. Pay them some respect. $\endgroup$
    – Michael E2
    Commented Mar 22, 2021 at 0:59

3 Answers 3

1
$\begingroup$

Update: Use DefaultOptions -> {Animator -> AnimationRepetitions -> 1} instead of AnimationRepetitions -> 1:

Manipulate[i, {i, 0, 1, 0.1, Appearance -> "Open", 
  AnimationRunning -> True, 
  DefaultOptions -> {Animator -> AnimationRepetitions -> 1}}]

enter image description here

Use AnimationRepetitions -> 2 to get

enter image description here

Original answer:

Manipulate[i, {i, 0, 1, 0.1, 
  Manipulator[##, 
    Appearance -> "Open", 
    AnimationRate -> 0.2, 
    AnimationRunning -> (i < 1)] &}]

enter image description here

$\endgroup$
1
  • $\begingroup$ This does exactly what I wanted, thanks! I'll have to look into these DefaultOptions/ControlType options. $\endgroup$
    – ChaSta
    Commented Mar 23, 2021 at 10:06
2
$\begingroup$

ListAnimate evidently constructs a Manipulate, and so we should be able to replicate its behavior. One way to figure out how ListAnimate works is to inspect its InputForm (click image to inspect output).

ListAnimate[Table[i, {i, 0, 1, 0.1}], 
  AnimationRepetitions -> 1] // InputForm

Unsurprisingly, ListAnimate uses a control of type Animator. The default Manipulate slider is a Manipulator (and Slider is distinct from both). If we specify an Animator in Manipulate, then we can use the AnimationRepetitions option. Here's a slimmed down version:

Manipulate[i, {i, 0, 1, 0.1, 
  ControlType -> Animator, AnimationRepetitions -> 1}]

Add options to achieve the appearance desired.

$\endgroup$
1
$\begingroup$

Ok, I figured out a hack—hopefully someone comes along with something nicer. The trick is to put an invisible flip-flop variable into our Manipulate, and have it become False at the end of the range of the actual variable.

Manipulate[x = x && (i < 1); (*start body*) i,
    {i, 0, 1, 0.1, Appearance -> "Open", AnimationRate -> 0.2, AnimationRunning -> x},
    {x, {True, False}, ControlType -> None}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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