1

This is somehow a follow-up to this question.

I am using some tikz drawing which I would like to animate using the animate package. The animation should start at the beginning, run through to the end of the animation and then jump to a frame somewhere in the middle and loop that last half of the frames.

Consider the following MWE which I build out of the mentioned question:

\documentclass{article} 
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{animate}

% mytimeline.txt
\begin{filecontents*}{mytimeline.txt}
%-------------------------------------------------------------------  
%[*]:[new frame rate]:[<list of transparencies>][:<JavaScript>]  
% `*' in the first column pauses animation
%-------------------------------------------------------------------  
::0
::1
::2
::3
::4 
::5 
::6 
::7 
::8 
::9
::9:  anim.myAnim.frameNum=5; %After last frame, return to frame #5
\end{filecontents*} 

\begin{document} 
\begin{center} 
\begin{animateinline}[ 
  label=myAnim, 
  autoplay, loop,  
  width=\linewidth, 
  begin={\begin{minipage}[c][5cm][c]{5cm}}, 
  end={\end{minipage}}, 
  timeline=mytimeline.txt
]{4}% 
%create "transparencies", to be arranged according to timeline 
  \multiframe{10}{Number=0+1}{% 
    \begin{tikzpicture}
      \foreach \i in {0.1, 0.2, ..., 180} 
        \draw (\i:2) -- (\i+180:2);
      \node[white, font=\Huge] at (0,0) {\Number};
    \end{tikzpicture}
  } 
\end{animateinline}% 
\end{center} 
\end{document}

The timeline.txt lets the animation start from the beginning and then loop the last 5 frames.

The animation itself here only draws the frame number and some hundred strokes to slow down display so you can see what I see with the real thing: After getting to the last frame, the animation briefly displays the very first frame and only then jumps to the 5th frame as commanded.

How can I make the animation not show that wrong slide?

For the record: I'm using a recent pdflatex and Adobe Reader DC.

2

The frame graphic (1800 radial lines simulating the filled circle) is quite demanding for AR's rendering engine. This may lead to a race between execution of anim.myAnim.frameNum=5 and the loop trigger. If the latter happens before the frame number setting, the animation briefly jumps back to #0.

This situation can be avoided if we repeat the last frame once more at the end of the timeline, pushing the loop event further behind the forced jump:

\documentclass{article} 
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{animate}

% mytimeline.txt
\begin{filecontents*}{mytimeline.txt}
%-------------------------------------------------------------------  
%[*]:[new frame rate]:[<list of transparencies>][:<JavaScript>]  
% `*' in the first column pauses animation
%-------------------------------------------------------------------  
::0
::1
::2
::3
::4 
::5 
::6 
::7 
::8 
::9
::9:  anim.myAnim.frameNum=5; %After last frame, return to frame #5
::9   % added
\end{filecontents*} 

\begin{document} 
\begin{center} 
\begin{animateinline}[ 
  label=myAnim, 
  autoplay, loop,  
  width=\linewidth, 
  begin={\begin{minipage}[c][5cm][c]{5cm}}, 
  end={\end{minipage}}, 
  timeline=mytimeline.txt
]{4}% 
%create "transparencies", to be arranged according to timeline 
  \multiframe{10}{Number=0+1}{% 
    \begin{tikzpicture}
      \foreach \i in {0.1, 0.2, ..., 180} 
        \draw (\i:2) -- (\i+180:2);
      \node[white, font=\Huge] at (0,0) {\Number};
    \end{tikzpicture}
  } 
\end{animateinline}% 
\end{center} 
\end{document}

The same visual result and animation performance, but saving compilation time and PDF file size (the "circle" is typeset only once):

\documentclass{article} 
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{animate}

% mytimeline.txt
\begin{filecontents*}{mytimeline.txt}
%-------------------------------------------------------------------  
%[*]:[new frame rate]:[<list of transparencies>][:<JavaScript>]  
% `*' in the first column pauses animation
%-------------------------------------------------------------------  
::0x0,1
::2
::3
::4 
::5
::6 
::7 
::8 
::9
::10
::10: anim.myAnim.frameNum=5; %After last frame, return to frame #5
::10
\end{filecontents*} 

\begin{document} 
\begin{center} 
\begin{animateinline}[ 
  label=myAnim, 
  autoplay, loop,
  width=\linewidth, 
  begin={\begin{minipage}[c][5cm][c]{5cm}}, 
  end={\end{minipage}}, 
  timeline=mytimeline.txt
]{4}% 
  %create "transparencies", to be arranged according to timeline 
  \begin{tikzpicture} % black "circle"
    \foreach \i in {0.1, 0.2, ..., 180} \draw (\i:2) -- (\i+180:2);
  \end{tikzpicture}
  \newframe
  \multiframe{10}{Number=0+1}{% numbers, to be overlaid
    \begin{tikzpicture}
      \useasboundingbox (-2,-2) rectangle (2,2);
      \node[white, font=\Huge] at (0,0) {\Number};
    \end{tikzpicture}
  } 
\end{animateinline}% 
\end{center} 
\end{document}

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.