Animateinline 与 foreach 和缩放缩小图像

Animateinline 与 foreach 和缩放缩小图像

我一直在尝试使用\animateinline 命令创建动画。当执行 while 循环中的最后一部分代码时,动画会缩小。我认为这与我的绘图中的移位和缩放选项有关。请帮我解决这个问题。

\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}

在此处输入图片描述

在此处输入图片描述

答案1

发生这种情况的原因,正如您所怀疑的那样,是边界框发生了变化。因此,您不必完全不绘制对象,只需通过拨动适当的不透明度来打开和关闭它们即可。(另请注意,\animatelinline已经创建了一个可进行动画处理的参数,您可以ifthen在此处将其删除,而使用\ifnum语句。)

\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}

相关内容