# how to hold previous lines in \multiframe in \tikz?

hi every1 with your previous help I managed to generate a animation of a rotating line using \multiframe within tikzpicture. In the following is a MWE for my animation.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}

\begin{document}
\begin{frame}
\centering
\begin{animateinline}[poster=first]{2}

% draw rotating line
\multiframe{20}{rt=0+5}{%
\resizebox{!}{.8\textheight}{\begin{tikzpicture}

%draw coordinate axis
\draw[thick, color=black, -latex] (-4.05,0) -- (4.05,0) node[right]{$x_1$};
\draw[thick, color=black, -latex] (0,-3.4) -- (0,3.4) node[above]{$x_2$};

%draw tilting red line
\draw[thick, color=red] ({4*cos(\rt)},{4*sin(\rt)}) -- ({-4*cos(\rt)},{-4*sin(\rt)});

\node at (5,5) {};
\node at (-5,-5) {};

\end{tikzpicture}}%
}
\end{animateinline}
\end{frame}
\end{document}


Does anyone know a way to hold the lines which are drawn on the previous frames such that on the first frame, there will only be one line, on the second frame there would be the line from the first frame plus the new drawn line and for the following frames respectively?

Is there a way other than generating the pdfs of all the frames individually and than use \animategraphics?

• put it in a foreach Jul 17 '15 at 16:37
• Thanks for the tip, i thought of the command 'foreach' too, but could you maybe be a little bit more specific.The problem with 'foreach' would be, that for each frame the 'foreach' argument changes, since with the frames increasing, the number of lines to be drawn also increases. But honestly speaking, i'm not very familiar with the 'foreach' command. Can you give a MWE to show me how this could be done with 'foreach'? Jul 17 '15 at 22:51
• Can you edit your question to show the problem? Jul 18 '15 at 9:30

For this application the \multido command (package multido) is better suited than PGF's \foreach:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage{multido}

\begin{document}
\begin{frame}
\centering
\begin{animateinline}[poster=first]{2}
% draw rotating line
\multiframe{20}{i=1+1}{%
\resizebox{!}{.8\textheight}{\begin{tikzpicture}

%draw coordinate axis
\draw[thick, color=black, -latex] (-4.05,0) -- (4.05,0) node[right]{$x_1$};
\draw[thick, color=black, -latex] (0,-3.4) -- (0,3.4) node[above]{$x_2$};

%draw tilting red lines
\multido{\rt=0+5}{\i}{
\draw[thick, color=red] ({4*cos(\rt)},{4*sin(\rt)}) -- ({-4*cos(\rt)},{-4*sin(\rt)});
}

\node at (5,5) {};
\node at (-5,-5) {};

\end{tikzpicture}}%
}
\end{animateinline}
\end{frame}
\end{document}