2

I would like to animate the following path from A to 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}

Something similar to the code AlexG provided in Animating Protocols

\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}
2
  • Welcome to TeX.sx! Please add a complete minimal working example (MWE), including \documentclass and \usepackages, that illustrates your problem. Show us where you are getting stuck in applying AlexG's answer to the existing question, and you will stand a better chance of getting help. Oct 6, 2012 at 20:10
  • Sorry about that. Here's a mwe. \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} Oct 6, 2012 at 21:21

3 Answers 3

5

Next code uses Jake's answer to How to animate a path or how to draw starting fraction of a complex but linear path? adapted to your path form A to B. It draws the start segment of a path with an arrow at the end and moving along the animation.

As soon as I can understand how to convert the animation to an animated gif, I'll upload the image. I know it's explained here, but I've never tried it.

\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
  • Perfect. That's exactly what I wanted. Thank you so much. Oct 8, 2012 at 10:49
  • Here a little update which might help others. I redrew my line using absolute coordinates, the relative coords where confusing things up. my line redrawn is: \draw (8,3.4) -- (9.1,3.4) -- (9.1,1.1) -- (7.9,1.1);. Then I had to specify node (s) coords otherwise I get a zig-zag(wrong) animation. So the code from \begin{tikzpicture} (all else remains the same) is: \begin{tikz...}[] \node (s) at (8,3.4) {A}; \node (r) at (9.1,3.4) {}; \node (t) at (9.1,1.1) {}; \node (v) at (7.9,1.1) {B}; \draw[start segment=\rPos,->,black!70, line width=2.5] (s) -- (r.center) -- (t.center)--(v); \end{tikz...} Oct 9, 2012 at 21:29
2

You can also use uncover for this job (though the code is not tidy as when using 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}

enter image description here

1
  • Thanks for the suggestion. It's very much close to what I want to achieve. How can I make a loop - so it starts from the beginning and on one slide. I thought of using 'animate' because I need the path/shape to loop and on one slide only. Also, it will be nice if the arrow/shape progresses in length like in AlexG's code. How do I achieve this? Oct 6, 2012 at 23:58
2

The one-page animation which loops:

\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}
1
  • Thank you Alex. I had like the line/path to be a single line increasing in length. Ignasi's code below did the job. Thanks. Oct 8, 2012 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .