# Animateinline with foreach and scaling shrinks image

I have been trying to create an animation using the \animateinline command. The animation is shrinking when the last part of the code in the while loop is executing. I think this is related to the shift and scale options in my drawings. Please help me with this.

\documentclass[pdf]{beamer}
\mode<presentation>{\usetheme{Warsaw}}
\usepackage{animate}
\usepackage{amsmath}
\usepackage{tikz}
\title[]{My Presentation}
\author[Raghuram Dharmavarapu]{Raghu}
\date{}
\usepackage{ifthen}
\begin{document}
\newcounter{m}
\setcounter{m}{0}

\begin{frame}[fragile]{Animated Integral}

\begin{animateinline}[loop, poster = first, controls]{4}
\whiledo{\them < 14}{
\begin{tikzpicture}[scale = 0.8]

%%%%%%The solid blue block%%%%%%%%%%%
\filldraw[blue!40!black] (0,0) -- (7,0) -- (7.35,1) --(-0.35,1)--cycle;
\filldraw[blue!40!white] (-0.35,1) --(0.25,1.6) -- (6.75,1.6) -- (7.35,1) --cycle;
\foreach \x/\sh in {0/0,8/0.005,16/0.01,24/0.015,32/0.02,40/0.025,48/0.03}
{
\filldraw[gray!30!white,scale = 0.08+\sh, shift = {(7+\x,16-\x/10)}] (0,0) -- (3,0) -- (2.9,1) -- (4.5,1) --(4.2,2.25)--(2.7,2.25)--(2.6,3)--(0.4,3)--(0.3,2.25)--(-1.2,2.25)--(-1.5,1)--(0.1,1)--cycle;
\filldraw[gray!90!white,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (-1.5,1)--(-1.4,-1.5)--(0.05,-1.5)--(0,0)--(0.1,1)--cycle;
\filldraw[gray!90!black,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (0,0) -- (0.1,-2) -- (2.9,-2) -- (3,0)-- cycle;
\filldraw[gray!90!white,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (4.5,1) --(4.4,-1.5) --(2.95,-1.5) --(3,0) -- (2.9,1) --cycle;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%Draws the red horizontal lines %%%%%%%%%
\ifthenelse{\them < 12}{
\foreach \mv in {0,...,\them}{
\pgfmathsetmacro\k{mod(\mv,4)*24}
\draw [very thick,white!\k!red] (0,-2+\mv/4) -- (7,-2+\mv/4);
}
}
{
\foreach \mv in {0,...,12}{
\pgfmathsetmacro\k{mod(\mv,4)*24}
\draw [very thick,white!\k!red] (0,-2+\mv/4) -- (7,-2+\mv/4);
}

\foreach \x/\s/\y in {0/0.25/0,0.55/0.5/0.5,1.15/0.75/1,1.9/1/1.5,2.7/1.25/2,3.6/1.5/2.5,4.6/1.75/3}{
\draw[densely dashed,shift = {(0+\x,-1.75-\y)},scale = 1+\s] (0.3,2) .. controls (0.4,2.3) and (0.7,2.3) .. (0.8,2);
}

\foreach \x/\s/\y in {0/0.3/0,0.55/0.6/0.5,1.15/0.9/1,1.9/1.2/1.5,2.7/1.5/2,3.6/1.8/2.5
,4.6/2.1/3}{
\draw[densely dashed,shift = {(0+\x,-0.5-\y)},scale = 1+\s] (0.3,2) .. controls (0.4,2.3) and (0.7,2.3) .. (0.8,2);
}
}

\end{tikzpicture}
%
\stepcounter{m}
\ifthenelse{\them < 14}{
\newframe
}{
\end{animateinline}\relax % BREAK
}
} % END \whiledo...

\end{frame}

\end{document}


• Yes It does animate. May be you need to compile again. And press the play button.I could have uploaded the gif but I dont know how to create one from the pdf. – RD1153 Feb 15 at 3:50
• Hi Sorry, I needed to remove the comment line between the \ifthenelse blocks. – RD1153 Feb 15 at 4:29

The reason why that happens is, as you suspect, that the bounding box changes. So, instead of not drawing the objects at all, you may just switch them on and off by dialing the appropriate opacities. (Note also that \animatelinline already creates a parameter that gets animates, and you can remove ifthen here in favor of \ifnum statements.)

\documentclass[pdf]{beamer}
\mode<presentation>{\usetheme{Warsaw}}
\usepackage{animate}
\usepackage{amsmath}
\usepackage{tikz}
\title[]{My Presentation}
\author[Raghuram Dharmavarapu]{Raghu}
\date{}
\begin{document}
\newcounter{m}
\setcounter{m}{0}

\begin{frame}[fragile]{Animated Integral}

\begin{animateinline}[loop, poster = first, controls]{4}
\multiframe{14}{i=1+1}{%
\begin{tikzpicture}[scale = 0.8]

%%%%%%The solid blue block%%%%%%%%%%%
\filldraw[blue!40!black] (0,0) -- (7,0) -- (7.35,1) --(-0.35,1)--cycle;
\filldraw[blue!40!white] (-0.35,1) --(0.25,1.6) -- (6.75,1.6) -- (7.35,1) --cycle;
\foreach \x/\sh in {0/0,8/0.005,16/0.01,24/0.015,32/0.02,40/0.025,48/0.03}
{
\filldraw[gray!30!white,scale = 0.08+\sh, shift = {(7+\x,16-\x/10)}] (0,0) -- (3,0) -- (2.9,1) -- (4.5,1) --(4.2,2.25)--(2.7,2.25)--(2.6,3)--(0.4,3)--(0.3,2.25)--(-1.2,2.25)--(-1.5,1)--(0.1,1)--cycle;
\filldraw[gray!90!white,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (-1.5,1)--(-1.4,-1.5)--(0.05,-1.5)--(0,0)--(0.1,1)--cycle;
\filldraw[gray!90!black,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (0,0) -- (0.1,-2) -- (2.9,-2) -- (3,0)-- cycle;
\filldraw[gray!90!white,scale = 0.08+\sh, shift = {(7+\x,16.5-\x/10)}] (4.5,1) --(4.4,-1.5) --(2.95,-1.5) --(3,0) -- (2.9,1) --cycle;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%Draws the red horizontal lines %%%%%%%%%
\ifnum\i<13
\tikzset{opa 1/.style={opacity=1},opa 2/.style={opacity=0},opa 3/.style={opacity=0}}
\else
\ifnum\i=13
\tikzset{opa 1/.style={opacity=0},opa 2/.style={opacity=1},opa 3/.style={opacity=0}}
\else
\tikzset{opa 1/.style={opacity=0},opa 2/.style={opacity=1},opa 3/.style={opacity=1}}
\fi
\fi

\foreach \mv in {0,...,\i}{
\pgfmathsetmacro\k{mod(\mv,4)*24}
\draw [very thick,white!\k!red,opa 1] (0,-2+\mv/4) -- (7,-2+\mv/4);
}
\foreach \mv in {0,...,12}{
\pgfmathsetmacro\k {mod(\mv,4)*24}
\draw [very thick,white!\k!red,opa 2] (0,-2+\mv/4) -- (7,-2+\mv/4);
}

\foreach \x/\s/\y in {0/0.25/0,0.55/0.5/0.5,1.15/0.75/1,1.9/1/1.5,2.7/1.25/2,3.6/1.5/2.5,4.6/1.75/3}{
\draw[densely dashed,shift = {(0+\x,-1.75-\y)},scale = 1+\s,opa 2] (0.3,2) .. controls (0.4,2.3) and (0.7,2.3) .. (0.8,2);
}

\foreach \x/\s/\y in {0/0.3/0,0.55/0.6/0.5,1.15/0.9/1,1.9/1.2/1.5,2.7/1.5/2,3.6/1.8/2.5
,4.6/2.1/3}{
\draw[densely dashed,shift = {(0+\x,-0.5-\y)},scale = 1+\s,opa 3] (0.3,2) .. controls (0.4,2.3) and (0.7,2.3) .. (0.8,2);
}

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

• Can you tell me how do I display the last two semi circle sections one after other which is in 13th frame only the bottom semi circle block and in 14th both of them. – RD1153 Feb 15 at 6:54
• @user3227125 You're welcome and added something. I hope that I interpret your comment together (an will now go to sleep). – user121799 Feb 15 at 7:00