Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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. –  Henry DeYoung Oct 6 '12 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} –  Daves Broadley Oct 6 '12 at 21:21

3 Answers 3

up vote 2 down vote accepted

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}
share|improve this answer
    
Perfect. That's exactly what I wanted. Thank you so much. –  Daves Broadley Oct 8 '12 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...} –  Daves Broadley Oct 9 '12 at 21:29

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}
share|improve this answer
    
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. –  Daves Broadley Oct 8 '12 at 10:51

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

share|improve this answer
    
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? –  Daves Broadley Oct 6 '12 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.