4

I am new to Beamer/Tikz animation, I have been searching intensively and I have not found any answers to my specific case.

Description: enter image description here I have a graph of a process similar to a flowchart with several paths that can be obtained. I would like to draw a ball or a dot that moves along the different options, to describe the possible path that can be taken. The most similar thread that I have found is ttps://tex.stackexchange.com/questions/475463/animate-an-airplane-in-beamer but in my case, the graph is fixed I only want to move an element through the graph.

I am attaching a sample flow chart but mine is less complicated. I will appreciate your help!

The following code is what I have at the moment. Instead of a line, I would like to draw a dot that moves around through different paths.

    \documentclass{beamer}
\usepackage{tikz}

\pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground}

\begin{document}

\begin{frame}

\begin{figure}
    \begin{center}
        \begin{tikzpicture}
     \node[anchor=south west,inner sep=0] (image) at (0,0) 
      {\includegraphics[width=0.9\textwidth]{figures/Flow_3.png}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
      %draw path
        \begin{pgfonlayer}{foreground}
           \path<2->[draw,line width=2pt,-,red] (0.16,0.24) edge node {} (0.59,0.24);
        \end{pgfonlayer}
       \end{scope} 
       \end{tikzpicture}
           \end{center}  
 \label{fig:1}           
\end{figure}    

\end{frame}
\end{document} 

EDIT***

Thanks to the @AlexG contribution I was able to write the following code. The problem now is that I need to include different paths "resetting" the frame each time. How can I do it?

\documentclass{beamer}
    \usepackage{tikz}
     \userpackage{animate}
   \tikzset{dot/.pic={\fill[red] (0,0) circle [radius=2pt];}}

    \begin{document}

    \begin{frame}


\begin{figure} \begin{center} %Animation \begin{animateinline}[controls={play,stop}]{12}% \multiframe{11}{rPos=0+0.1}{% \begin{tikzpicture} \node [anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{figures/Flow_3.png}}; \path (1.67,1.24) -| (2.3,1.24) pic [pos=\rPos] {dot};

%To draw the grid for coordinates \begin{scope}[x={(image.south east)},y={(image.north west)}] %GRID \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1); \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; } \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; } \end{scope} \end{tikzpicture}% }%
\newframe* % pause here, click to continue \multiframe{11}{rPos=0+0.1}{% \begin{tikzpicture} \node [anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[width=0.9\textwidth]{figures/Flow_3.png}}; \path (2.3, 1.24) |- (6.59,1.24) pic [pos=\rPos] {dot}; \begin{scope}[x={(image.south east)},y={(image.north west)}] \end{scope}
\end{tikzpicture}% }%

\end{animateinline}
\end{center}

\end{figure}

I will appreciate your help!

  • 1
    Hello ! A basic solution would be to draw the complete diagram (without the moving part), create a path that the dot should follow and then update the dot position along the path with a \foreach loop. Could you post a working example so that we can see where you start from ? – BambOo Oct 30 '20 at 18:06
  • Hello, thanks for your answer. I will research that function about creating a path. As I said in my post I am new to beamer animation and I do not have a starting point at the moment. – Ana Batista Nov 02 '20 at 05:07
  • From your code, I understand that the flowchart was not made with TikZ. Would it be possible to share this image ? Otherwise, you could reuse the use bounding box relative coordinates style proposed by Max here https://tex.stackexchange.com/a/445311/141947 – BambOo Nov 02 '20 at 12:10
  • @BambOo thanks for your answer. The graph was not done employing Tikz, I can not share the image because it is part of an ongoing project, but it is a flowchart similar to the one I posted. I will check the link you suggested. – Ana Batista Nov 03 '20 at 07:00

1 Answers1

5

For the sake of beauty, the flow chart itself should be drawn with TikZ as well. This comes with the bonus that all node coordinates are readily available for positioning a dot on the connecting lines.

What follows is an animate(-package)-based solution. The flow chart with its static objects is saved in a box first and then re-used in the animation. (Using package xsavebox for size-effective storage.) Click for viewing it in action.

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{shapes} \usepackage{animate} \usepackage{xsavebox}

\tikzset{dot/.pic={\fill[red] (0,0) circle [radius=2pt];}}

\begin{document}

% save flow chart \begin{xlrbox}{Flow} \begin{tikzpicture}[every node/.style=draw, -latex] \useasboundingbox (-0.6,-1.5) rectangle (3,1.5); \path (0,1) node [rounded rectangle] (start) {Start} (2,0) node [trapezium, trapezium left angle=60, trapezium right angle=-60] (hello) {Hello!} (0,-1) node [rounded rectangle] (end) {End}; \draw (start) -| (hello); \draw (hello) |- (end); \end{tikzpicture} \end{xlrbox}% % % dot moving along node connections \begin{animateinline}[controls={play,stop}]{12}% \multiframe{11}{rPos=0+0.1}{% \begin{tikzpicture} \node [anchor=south west, inner sep=0pt] at (-0.6,-1.5) {\theFlow}; \path (start) -| (hello) pic [pos=\rPos] {dot}; \end{tikzpicture}% }%
\newframe* % pause here, click to continue \multiframe{11}{rPos=0+0.1}{% \begin{tikzpicture} \node [anchor=south west, inner sep=0pt] at (-0.6,-1.5) {\theFlow}; \path (hello) |- (end) pic [pos=\rPos] {dot}; \end{tikzpicture}% }%
\end{animateinline}

\end{document}

If, however, an external graphic with a flow chart is to be used, the connection line's start and end coordinates must be manually determined and then inserted by means of TikZ's \coordinate command. Putting a grid with help lines on top of the node with the embedded graphic might help in this process.

Here we make use of the callouts package to put coordinates and to annotate the external flow chart with the animated red dot. Helper lines are temporarily inserted with \helpgrid[gray]. The number of frames of each animation section should be adjusted with respect to the individual lengths of the connection lines in order to achieve a well-balanced speed of the moving dot. Again, click to see the animation in action.

%\documentclass[dvisvgm]{standalone} % dvilualatex example ; dvisvgm --exact --font-format=woff2 --zoom=-1 example 
\documentclass{standalone}

\usepackage{animate} \usepackage{callouts} \usepackage{xsavebox}

\tikzset{dot/.pic={\fill[red] (0,0) circle [radius=3pt];}}

\begin{document}

% save flow chart \begin{xlrbox}{Flow} \begin{annotate}{\includegraphics{N5Zfy}}{1.0} \helpgrid[gray] \coordinate (plan route east) at (-6.85,-2.05); \coordinate (route west) at (-6,-2.05); \coordinate (route north) at (-4.7,-1.3); \coordinate (don't know west) at (-2.75,3.9); \end{annotate} \end{xlrbox}% % % dot moving along node connections \begin{animateinline}[controls={play,stop}]{12}% \multiframe{6}{rPos=0+0.2}{% \begin{annotate}{\theFlow}{1.0} \path (plan route east) -- (route west) pic [pos=\rPos] {dot}; \end{annotate} }%
\newframe* % pause here, click to continue \multiframe{41}{rPos=0+0.025}{% \begin{annotate}{\theFlow}{1.0} \path (route north) |- (don't know west) pic [pos=\rPos] {dot}; \end{annotate} }%
\end{animateinline}

\end{document}

AlexG
  • 54,894
  • Very nice very very nice. :-) – Sebastiano Nov 02 '20 at 16:03
  • @AlexG that exactly what I am looking for. Unfortunately, my graph was not done using Tikz and I think it will be a lot of work to do it again. Is it possible to modify your code for the case with a fixed image and defining the coordinates? – Ana Batista Nov 03 '20 at 07:02
  • @Ana In this case, you you will have to determine the starting end ending coordinates of the connections manually and specify them using TikZ's \coordinate... command. A grid put on top of the node with the included image file might help in this process. – AlexG Nov 03 '20 at 08:27
  • @AlexG thanks, That exactly that I have done it. I have edited my answer to include the new code. The problem now is that I would like to reset the path several times and start from a new point, also including some stops. How can I do it? – Ana Batista Nov 03 '20 at 08:58
  • No gif animation? I'm disappoint. :P – Alenanno Nov 03 '20 at 09:07
  • @Alenanno hehehe, I do not know how to do it... – Ana Batista Nov 03 '20 at 09:08
  • @AnaBatista oh no worries, my message was for AlexG :P – Alenanno Nov 03 '20 at 09:13
  • @Alenanno GIF is '90s technology. – AlexG Nov 03 '20 at 10:20
  • @Ana You can add as many animation sections with inserted stops as you want. I edited an example with the given external flow chart image. – AlexG Nov 03 '20 at 10:35
  • @AlexG Thank you. But What about if I want to re-start a new path using the same dot. Let say, the graph has two different possible start point. – Ana Batista Nov 03 '20 at 10:44
  • @AnaBatista By adding another \multiframe...-loop? Or do you want two dots moving at the same time? – AlexG Nov 03 '20 at 10:50
  • @AlexG Thanks. I only want to show one dote moving. But in one slide it will show the path_1 and on the other slide the path_2. Maybe it can be done with the overlay option or just adding another loop to the same slide, making the dot to appear in the path_2. Am I correct? – Ana Batista Nov 03 '20 at 10:55
  • @Ana In the example, each \multiframe section moves the dot between two coordinates. So yes, add more such loops! Both examples already contain two such sections. Of course, all coordinates should be defined beforehand, in the code section underneath % save flow chart. – AlexG Nov 03 '20 at 11:00
  • @AlexG Perfect. I will play with it. Thank you very much for your contribution. I can not give you "a Like" because I am new to StackExchange, but I am sure the post will be helpful to others. Cheers! – Ana Batista Nov 03 '20 at 11:06