![使用向前移动的线来制作永动机动画(TikZ/beamer)](https://linux22.com/image/275825/%E4%BD%BF%E7%94%A8%E5%90%91%E5%89%8D%E7%A7%BB%E5%8A%A8%E7%9A%84%E7%BA%BF%E6%9D%A5%E5%88%B6%E4%BD%9C%E6%B0%B8%E5%8A%A8%E6%9C%BA%E5%8A%A8%E7%94%BB%EF%BC%88TikZ%2Fbeamer%EF%BC%89.png)
我正在尝试创建一个动画,以视觉形式呈现时间中永恒向前的运动。我想要创建的是:
- 箭头开始向右侧移动X轴。
- 以下X轴,显示时间刻度值,比如从 1 到 10。
- 箭的长度从 1 增加到 10。
- 当其长度达到 10 时X坐标,标签(X轴)不断递增,但箭头长度不需要改变(因此保持 10 个单位)。
我是 TikZ/ 的新手beamer
,我尝试了各种方法,但无法接近预期目标。我目前拥有的是这样的:
\documentclass{beamer}
\usepackage{color}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{animate}
\usetheme{Warsaw}
\usecolortheme{whale}
\begin{frame}{Progress in Time}
\begin{animateinline}[
begin={ % header of each frame
\begin{tikzpicture}
[line width=1pt]
\path[clip] (0,-3) rectangle (11,6);
},
end={\end{tikzpicture}},autoplay]{3}
\multiframe{10}{iCount=1+1}{
\node (s) at (1,0.5) [] [label=below:$\iCount$] {};
\node (r) at (8,0.5) [] {};
\pgfmathsetmacro{\sup}{\iCount + 1}
\pgfmathsetmacro{\incr}{\iCount/10}
\node at (3,0.5) [] [label=below:$\sup$] {};
\path (s) -- (r) node[pos=\incr,coordinate] (p) {};
\draw[->] (s) -- (p);
} % end of multiframe
\end{animateinline}
\end{frame}
答案1
代码 (animate
)
\documentclass{beamer}
\usepackage{tikz,animate}
\usetheme{Warsaw} \usecolortheme{whale}
\begin{document}
\begin{frame}{Progress in Time}
\begin{animateinline}[
begin={%
\tikzpicture[line width=1pt]
\node[below] at (10,0) {\phantom{00}};
\coordinate (start) at (0,0) ++ (up:.25cm);
},
end=\endtikzpicture,
autoplay,
palindrome
] {1}
\multiframe{20}{iCount=1+1}{
\draw[->] (start) -- ({ifthenelse(\iCount<10,\iCount,10)},0)
coordinate (target)
node[below] {\iCount};
\foreach \cnt[evaluate={\Pos={\cnt/\iCount}}] in {0,...,\the\numexpr\iCount-1\relax}{
\path (start) -- (target) node[below, pos=\Pos] (@) {\cnt};
\draw (@.north) + (up:2pt) -- + (down:2pt);
}
}
\end{animateinline}
\end{frame}
\end{document}
代码 (convert
)
\documentclass{beamer}
\usepackage{tikz}
\usetheme{Warsaw} \usecolortheme{whale}
\begin{document}
\foreach \iCount in {1,...,20,19,18,...,2}{%
\begin{frame}{Progress in Time}
\tikzpicture[line width=1pt]
\node[below] at (10,0) {\phantom{00}};
\coordinate (start) at (0,0) ++ (up:.25cm);
\draw[->] (start) -- ({ifthenelse(\iCount<10,\iCount,10)},0)
coordinate (target)
node[below] {\iCount};
\foreach \cnt[evaluate={\Pos={\cnt/\iCount}}] in {0,...,\the\numexpr\iCount-1\relax}{
\path (start) -- (target) node[below, pos=\Pos] (@) {\cnt};
\draw (@.north) + (up:2pt) -- + (down:2pt);
}
\endtikzpicture
\end{frame}
}
\end{document}