9

I would like to animate the following picture so that the length of the blue box becomes smaller and smaller. Using the overprint environment along with \transduration{0.2} makes the job. However, this requires to copy and paste the piece of code, each time reducing the x-coordinate of topRight_corner. I am sure there is a proper way to do that...

PS: I am using this to illustrate the limit as 'delta t' goes to 0.


Here is the TikZ picture enter image description here

and here is the piece of code I wrote for that

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

%------ tikZ ------%
\usepackage{tikz}
\usetikzlibrary{positioning, arrows}
%------------------%

\begin{document}

\begin{frame}[c]

\begin{center}
\begin{tikzpicture}
\node[coordinate] at (0, 0) (bottomeLeft_corner) {};
\node[coordinate] at (2.50, 1.25) (topRight_corner) {};
\path[fill=blue!20] (bottomeLeft_corner) rectangle (topRight_corner);
\node[above left=0.625cm and 2cm of bottomeLeft_corner, coordinate] (start1) {};
\node[above left=0.625cm and 0cm of bottomeLeft_corner, coordinate] (end1) {};
\draw[semithick] (start1) -- (end1);
\node[above right=-0.625cm and 0cm of topRight_corner, coordinate] (start2) {};
\node[above right=0.625cm and 4.5cm of bottomeLeft_corner, coordinate] (end2) {};
\draw[->, >=stealth', semithick] (start2) -- (end2);
\draw[semithick, black!40] (end1) -- (start2);
\node[below=0cm of end2, xshift=0.25cm] {time}; 
\node[yshift=-0.25cm] at (bottomeLeft_corner) {$t$};
\end{tikzpicture}
\end{center}

\end{frame}

\end{document}
Marco
  • 4,435

3 Answers3

11

Here is the TikZ solution, as in the OP, using the animate package:

enter image description here

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

%------ tikZ ------%
\usepackage{tikz}
\usetikzlibrary{positioning, arrows}
%------------------%

\usepackage{animate}

\begin{document}

\begin{frame}[c]

\begin{center}
\pgfmathtruncatemacro\N{10}
\begin{animateinline}[controls,loop]{5} % 5 fps, same as 0.2 s transduration
  \multiframe{\N}{i=1+1}{
    \begin{tikzpicture}
      \pgfmathsetmacro\x{2.5*(\N-\i+1)/\N}
      \node[coordinate] at (0, 0) (bottomeLeft_corner) {};
      \node[coordinate] at (\x, 1.25) (topRight_corner) {};
      \path[fill=blue!20] (bottomeLeft_corner) rectangle (topRight_corner);
      \node[above left=0.625cm and 2cm of bottomeLeft_corner, coordinate] (start1) {};
      \node[above left=0.625cm and 0cm of bottomeLeft_corner, coordinate] (end1) {};
      \draw[semithick] (start1) -- (end1);
      \node[above right=-0.625cm and 0cm of topRight_corner, coordinate] (start2) {};
      \node[above right=0.625cm and 4.5cm of bottomeLeft_corner, coordinate] (end2) {};
      \draw[->, >=stealth', semithick] (start2) -- (end2);
      \draw[semithick, black!40] (end1) -- (start2);
      \node[below=0cm of end2, xshift=0.25cm] {time}; 
      \node[yshift=-0.25cm] at (bottomeLeft_corner) {$t$};
    \end{tikzpicture}
  }
\end{animateinline}
\end{center}

\end{frame}

\end{document}
AlexG
  • 54,894
10

To save more slides, I think that using animategraphics is much better. Compile the following with pdflatex -shell-escape input.tex.

% input.tex
\documentclass{beamer}
\usepackage{filecontents,animate,pgffor}

\begin{filecontents*}{limit.tex}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}

\begin{document}
\multido{\r=3.0+-0.1}{30}{%
\begin{pspicture}(-1,0)(6,2)
    \psline{->}(-1,1)(5,1)
    \pscircle*[linecolor=red](0,1){2pt}
    \psframe*[linecolor=cyan,opacity=0.5](0,0)(\r,2)
    \uput[-135](0,1){$t$}
    \uput[0](5,1){time}
\end{pspicture}}
\end{document}
\end{filecontents*}


\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf/ps}
    {\immediate\write18{\compiler\space limit.\ext}}

\begin{document}
\begin{frame}{Animation}
    \animategraphics[autoplay,loop,controls,scale=1]{5}{limit}{}{}
\end{frame}
\end{document}

The screenshot is as follows.

enter image description here

9

You can use \onslide<...> inside a for loop (\foreach) as follows:

enter image description here

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

%------ tikZ ------%
\usepackage{tikz}
\usetikzlibrary{positioning, arrows}
%------------------%

\begin{document}

\begin{frame}[c]

\begin{center}
\begin{tikzpicture}
\pgfmathtruncatemacro\N{10}
\foreach \k in {1,...,\N}%
{%
    \pgfmathsetmacro\x{2.5*(\N-\k+1)/\N}
    \onslide<\k>
    {
        \node[coordinate] at (0, 0) (bottomeLeft_corner) {};
        \node[coordinate] at (\x, 1.25) (topRight_corner) {};
        \path[fill=blue!20] (bottomeLeft_corner) rectangle (topRight_corner);
        \node[above left=0.625cm and 2cm of bottomeLeft_corner, coordinate] (start1) {};
        \node[above left=0.625cm and 0cm of bottomeLeft_corner, coordinate] (end1) {};
        \draw[semithick] (start1) -- (end1);
        \node[above right=-0.625cm and 0cm of topRight_corner, coordinate] (start2) {};
        \node[above right=0.625cm and 4.5cm of bottomeLeft_corner, coordinate] (end2) {};
        \draw[->, >=stealth', semithick] (start2) -- (end2);
        \draw[semithick, black!40] (end1) -- (start2);
        \node[below=0cm of end2, xshift=0.25cm] {time}; 
        \node[yshift=-0.25cm] at (bottomeLeft_corner) {$t$};
    }
}
\end{tikzpicture}
\end{center}

\end{frame}

\end{document}
jub0bs
  • 58,916
  • Great! I was just trying 'foreach' but I did not manage to embed it within 'onslide'. Many thanks! – Marco Sep 06 '13 at 13:43