# timeline and animate package

I'm trying to make some pdf with animate package controlling a loop with the timeline. The purpose is to have a loop but reaching the last frame, the color of the dot should change. My main questions are:

1. The animateinline environment does not accept label. What is the animation label that I should use in the Javascript time?
2. Is there any simple way to change mycolor after the last frame and then go to frame 1?

My tex file is:

\documentclass{article}
\usepackage{multido,pstricks,xcolor}
\usepackage{animate}

\newwrite\OutFile%
\immediate\openout\OutFile=mytimeline.txt%
\multido{\iMyFrame=0+1}{5}{%
\immediate\write\OutFile{::\iMyFrame x0}}
\immediate\write\OutFile{::5x0:anim.pageNum=1}
\immediate\closeout\OutFile%

\begin{document}
\definecolor{mycolor}{RGB}{100,0,100}
\begin{center}
\begin{animateinline}[poster=first, controls, %
begin={\SpecialCoor\begin{pspicture}(-5,-5)(5,5)},
%
end={\end{pspicture}},%
timeline=mytimeline.txt]{2}%
\psline{->}(0,-1.5)(0,1.5)\psline{->}(-1.5,0)(1.5,0)
\newframe
\multiframe{5}{iAngle=0+75}{%
\psdot[linecolor=mycolor](1;\iAngle)
\if iAngle=375 {\definecolor{mycolor}{RGB}{100,100,100}}\fi }
\end{animateinline}%
\end{center}
\end{document}

-
Of course, animateinline does accept a label (e. g. label=myanim). In the JavaScript interface use it as anim.myanim.frameNum=1 for example. –  AlexG Mar 4 at 13:08
I realized that I had an old version (last year) –  PCar Mar 5 at 15:15
Ok. As said in my answer, JavaScript is not required here. In other cases it makes sense though, such as restarting from a frame other than the first one. –  AlexG Mar 5 at 15:19

This is a nice example to illustrate the basic use of timeline files and of the animate JavaScript programming interface. JavaScript is being used to loop over a sub-range of animation frames.

Instead of repeating the animation from the very beginning, we want to jump back to the start of the second cycle which starts with a green dot at the zero degree position. To achieve this, we set the frameNum property of the animation object after reaching the end:

anim.myAnim.frameNum=18;


Whenever the timeline option is involved, we must distinguish between transparencies (created in the animateinline environment or embedded with \animategraphics) and the actual animation frames defined in the timeline file.

In the example below, the timeline file mytimeline.txt organizes the set of transparencies, which were created between \begin[...]{animateinline}{...} and \end{animateinline}, into the actual frames to be shown during the animation.

Note, that transparency and frame numbers are zero-based.

A final note on the execution time of JavaScript within a timeline file:

JavaScript is executed at the start of displaying a frame. In the current example, we want anim.myAnim.frameNum=18 to be executed at the end of the last frame in the sequence. To achieve this, we repeat the last frame description with the JavaScript added. This additional frame isn't actually shown, since we jump away from it right after its showing up.

\documentclass{article}
\usepackage{pstricks,xcolor}
\usepackage{filecontents}
\usepackage{animate}
\SpecialCoor\psset{unit=2}

% mytimeline.txt
\begin{filecontents*}{mytimeline.txt}
%-------------------------------------------------------------------
%[*]:[new frame rate]:[<list of transparencies>][:<JavaScript>]
% *' in the first column pauses animation
%-------------------------------------------------------------------
::0x0 , 1 % Frame #0: show axes (transparency #0) permanently (x0'),
% overlay dot at starting position (transp. #1)

::2       % Frame #1: overlay next dot position (transp. #2) on axes
::3       % Frame #2: ... and so on ...
::4
::5
::6
::7
::8
::9
::10
::11
::12
::13
::14
::15 % Frame #14: uses transp. #15 with the first green dot
::16
::17
::18
::19 % Frame #18: the second cycle starts with a green dot at 0° position (transp. #19)
::20
::21
::22
::23
::24
::25
::26
::27
::28
::29
::30
::31
::32
::15 % Re-use the green dots from the first cycle
::16
::17
::18 % Last frame #34
\end{filecontents*}

\begin{document}
\definecolor{mycolor}{RGB}{100,0,100}
\begin{center}
\begin{animateinline}[
label=myAnim,
controls, loop,
width=\linewidth,
begin={\SpecialCoor\begin{pspicture}(-2,-2)(2,2)},
end={\end{pspicture}},
timeline=mytimeline.txt
]{4}%
%create "transparencies", to be arranged according to timeline
%transparency #0: axes
\psline{->}(0,-1.5)(0,1.5)\psline{->}(-1.5,0)(1.5,0)
\newframe
%transparencies #1 through #18: dots for the first cycle
\multiframe{18}{iAngle=0+20}{%
%green dots on transp. #15 trough #18
\psdot[linecolor=\ifnum\iAngle>275 green\else mycolor\fi,dotscale=5](1;\iAngle)
}
\newframe
%transparencies #19 through #32: green dots for the second cycle
\multiframe{14}{iAngle=0+20}{%
\psdot[linecolor=green,dotscale=5](1;\iAngle)
}
\end{animateinline}%
\end{center}
\end{document}

-
As stated previously, my goal with this simple example, is to have control of the dot color when it passes 275 deg. Initially its purple and when finish the second loop all points should be green. That's why I cannot use loop option. The ultimate goal is to have the possibility of randomly choose color when a circle is completed, and that's why I need to understand and manage the timeline. This animation has been already made in flash, but I want a more general approach that might be seen on Linux. –  PCar Mar 5 at 15:21
I see. We need to extend the timeline to display the green dot after 275 deg and during the following cycles. Right? –  AlexG Mar 5 at 15:42
Correct... I'm planning to have a different color for each loop, but as stated in the manual pg 12 and 13 I cannot have a anim.myanim.frameNum=1 on the last frame. –  PCar Mar 5 at 18:02
@PCar I updated my answer. I hope you will get the idea. –  AlexG Mar 6 at 10:19
I got the idea. Just one question that I might misunderstanding. If you have a set of 3 frames for example, and in frame 2 you have TeX instruction and in 3 you have frameNum=1 (no loop option in animateline), all tex instructions (definecolor for example) suffer a reset. Is this correct? –  PCar Mar 12 at 17:37

What do you mean with "label"? However, I do not understand why you want for such a simple example a timeline. It is also possible without it:

\documentclass{article}
\usepackage{multido,pstricks,xcolor}
\usepackage{animate}
\SpecialCoor\psset{unit=2}

\begin{document}
\definecolor{mycolor}{RGB}{100,0,100}
\begin{center}
\begin{animateinline}[poster=first, controls, palindrome,
begin={\begin{pspicture}(-2,-2)(2,2)},
end={\end{pspicture}},%
%  timeline=mytimeline.txt
]{2}
\psline{->}(0,-1.5)(0,1.5)\psline{->}(-1.5,0)(1.5,0)
\psdot[linecolor=mycolor,dotscale=5](1;0)
\newframe
\multiframe{18}{iAngle=20+20}{%
\psline{->}(0,-1.5)(0,1.5)\psline{->}(-1.5,0)(1.5,0)
\psdot[linecolor=\ifnum\iAngle>275 green\else mycolor\fi,dotscale=5](1;\iAngle)
}
\end{animateinline}
\end{center}
\end{document}


-
as stated in pg 13 of Animated package documentation, if one need more elaborated control of the animation we should use the timeline and label together with JavaScript. My goal is to have the ability to change the circle color when it passes the 275 deg and maintain that color until next loop (not using the palindrome) –  PCar Feb 27 at 16:24