使用向前移动的线来制作永动机动画(TikZ/beamer)

使用向前移动的线来制作永动机动画(TikZ/beamer)

我正在尝试创建一个动画,以视觉形式呈现时间中永恒向前的运动。我想要创建的是:

  1. 箭头开始向右侧移动X轴。
  2. 以下X轴,显示时间刻度值,比如从 1 到 10。
  3. 箭的长度从 1 增加到 10。
  4. 当其长度达到 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}

输出

在此处输入图片描述

相关内容