我想制作从 A 到 B 的以下路径的动画。
\begin{tikzpicture}
\draw [->, draw=black!70, line width=2.5] (8,4) -- +(1,0) node (v4) {} -- +(1,-2) -- +(0,-2);
\node at (7.5,4) {A};
\node at (7.5,2) {B};
\end{tikzpicture}
\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{animateinline}[autoplay,loop]{3}
\multiframe{10}{rPos=0.1+0.1}{
\begin{tikzpicture}[]
\node (s){A}; \node (r) at (1,0) {};
\node (t) at (1,-2) {};
\node (v) at (0,-2) {B};
\path (s) -- (r) -- (t)--(v) node[pos=\rPos,coordinate] (p) {};
\draw[->, draw=black!70, line width=2.5] (s) -- +(r)--+(t)--+(p);
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
答案1
接下来的代码使用杰克的回答到如何为路径制作动画或如何绘制复杂但线性路径的起始部分?适应您的从 A 到 B 的路径。它绘制start segment
一条以arrow
结尾的路径,并沿着动画移动。
一旦我理解了如何将动画转换为 gif 动画,我就会上传图片。我知道这里有解释,但我从未尝试过。
\documentclass{beamer}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{calc,decorations,arrows,positioning,matrix}
% A simple empty decoration, that is used to ignore the last bit of the path
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}
\pgfdeclaremetadecoration{start}{initial}{
\state{initial}[
width={0pt},
next state=middle
]
{\decoration{moveto}}
\state{middle}[
width={\pgfmetadecoratedpathlength*\pgfdecorationsegmentlength},
next state=final
]
{\decoration{curveto}}
\state{final}
{\decoration{ignore}}
}
\tikzset{%
start segment/.style={decoration={start,raise=2mm},decorate, segment length=#1},
}
\begin{document}
\begin{frame}
\begin{animateinline}[autoplay,loop]{3}
\multiframe{10}{rPos=0.15+0.1}{
\begin{tikzpicture}[]
\node (s){A}; \node (r) at (1,0) {};
\node (t) at (1,-2) {};
\node (v) at (0,-2) {B};
\draw[start segment=\rPos,->,black!70, line width=2.5] (s) -- (r.center) -- (t.center)--(v); \end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
答案2
您也可以使用uncover
来完成这项工作(尽管代码不像使用时那样整洁foreach
)
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node at (7.5,4) {A};
\uncover<2->{\draw [-, draw=black!70, line width=1] (8,4) -- +(1,0) coordinate (v4) {} ;}
\uncover<3->{\draw [-, draw=black!70, line width=1] (v4) -- +(0,-2) coordinate (v5) {} ;}
\uncover<4->{\draw [->, draw=black!70, line width=1] (v5) -- +(-1,0) ;}
\uncover<5->{ \node at (7.5,2) {B};}
\end{tikzpicture}
\end{frame}
\end{document}
答案3
循环播放的单页动画:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage{fancyvrb}
\begin{VerbatimOut}{timeline.txt}
::0x0 % A
::1x0 % --
::2x0 % |
::3x0 % <--
::4 % B
\end{VerbatimOut}
\begin{document}
\begin{frame}
\begin{animateinline}[
timeline=timeline.txt,
begin={
\begin{tikzpicture}
\useasboundingbox (7.3,1.8) rectangle (9.1,4.2);
},
end={\end{tikzpicture}},
loop,autoplay
]{1}
\node at (7.5,4) {A};
\newframe
\draw [-, draw=black!70, line width=1] (8,4) -- +(1,0) coordinate (v4) {};
\newframe
\draw [-, draw=black!70, line width=1] (v4) -- +(0,-2) coordinate (v5) {};
\newframe
\draw [->, draw=black!70, line width=1] (v5) -- +(-1,0);
\newframe
\node at (7.5,2) {B};
\end{animateinline}
\end{frame}
\end{document}