animate package does not allow nested loops. Only a single loop is allowed. However, we often need to simulate 2 dimensional space in a single loop.
Please see the following C# code that I want to implement in LaTeX.
static void Main()
{
const int M = 3;
const int N = 4;
int i = 0;
int j = 0;
for (int c = 0; c < M * N; c++)
{
if (i >= N)
{
j++;
i = 0;
//newline
}
//print i and j
i++;
}
}
The real scenario is to create a PDF animation using animate package instead of the GIF animation at this link.
Last edit:
Because I used Altermundus' answer in my real scenario below,
\documentclass{article}
\usepackage{graphicx}
\usepackage{animate}
\usepackage{pstricks}
\SpecialCoor
\newsavebox\IBox
\savebox\IBox{\includegraphics{Images/bald}}
\def\N{2}% columns
\def\M{3}% rows
\psset{xunit=\dimexpr\wd\IBox/\N\relax,yunit=\dimexpr\ht\IBox/\M\relax}
\begin{document}
\animateinline[palindrome,autoplay]{1}
\newcounter{i}\newcounter{j}
\multiframe{\numexpr\N*\M\relax}{}
{
\unless\ifnum\value{i}<\N\relax
\addtocounter{j}{1}%
\setcounter{i}{0}%
\fi
\begin{pspicture}[showgrid](\N,\M)
\begin{psclip}{\psframe[linestyle=none]
(!\thei\space \thej)
(!\thei\space 1 add \thej\space 1 add)}
\rput[bl](0,0){\usebox\IBox}
\end{psclip}
\end{pspicture}
\addtocounter{i}{1}
}
\endanimateinline
\end{document}
so I will accept his answer.
Other answers also get +1 of course!
NOTE: Compile it with
xelatex. Animation importing images does not work withlatex-dvips-ps2pdf.\newcountdoes not work as well, use\newcounterinstead.
