6
$\begingroup$

enter image description here

How can I pause play at the specified location when export a gif file or using Animate? I want it to run automatically, no need to interact with the mouse. Here is an example:

Clear[f];
f[t_] := With[{angles = {0, -30 , -90 , -120 , 180 } Degree},
  Graphics[{
    Thick, Circle[],
    {Yellow, Disk[{0, 0}, 1, {0, -t } + Pi/2]}, PointSize[Large], 
    Point[{0, 0}],
    Arrow[{{0, 0}, AngleVector[Pi/2 - t]}],
    Line[{AngleVector[#], AngleVector[#] 1.1}] & /@ angles,
    MapThread[
     Text, {{1/4, 1/3, 1/2, 2/3, 3/4}, 1.4 (AngleVector /@ angles)}]
    }, PlotRange -> 1.7]]

Animate[f[t], {t, 0, 2 Pi, 0.01}, DisplayAllSteps -> True]
$\endgroup$
6
+100
$\begingroup$
tlist = Range[0, 2 Pi, 2 Pi/180];
pauseat = {Pi/2, 2 Pi/3, Pi, 7 Pi/6, 3 Pi/2};
pausepos = Nearest[tlist -> Automatic, #] & /@ pauseat;
reps = 10;
tlist2 = Flatten[MapAt[ConstantArray[#, reps] &, tlist, pausepos]];

You can use tlist2 in Animate iterator:

Animate[f[t], {t, tlist2}, DisplayAllSteps -> True]

or to generate a table of frames to be used in ListAnimate:

labeling = Thread[tlist[[Flatten @ pausepos]] -> {1/4, 1/3, 1/2, 2/3, 3/4}]; 

frames = Table[If[MemberQ[tlist[[Flatten @ pausepos]], t], 
   Replace[f[t], Text[txt : (t /. labeling), p_] :> 
     Text[Style[txt, 16, Blue, Bold], p], All], f[t]], 
  {t,  tlist2}];

ListAnimate[frames, DisplayAllSteps -> True]

Export frames as a gif file:

Export["stutteringclock.gif", frames]

enter image description here

A simpler alternative (but ... sometimes skips a stop):

pauseat = N @ {Pi/2, 2 Pi/3, Pi, 7 Pi/6, 3 Pi/2};
nF = Nearest[pauseat];

Animate[If[PossibleZeroQ[Chop[t - nF[t][[1]], Pi/620]], Pause[1]; f[t], f[t]], 
 {t, 0, 2 Pi, Pi/620}, DisplayAllSteps -> True, AnimationRate -> 100]
$\endgroup$
6
$\begingroup$

What I’ve done in the past is something like anim = Table[f[t], {t, 0, 2Pi, 0.01}] and then Export[“anim.gif”, anim, ImageResolution -> 300, “DisplayDurations” -> listOfTimes], where listOfTimes is generated so that most frames have the same display duration, but the frames of interest have a much longer display duration.

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