3

I want to produce animation which indicate cycle of length 5 in Petersen graph.I tried the following code but it indicate only single edges.I want to produce animation with all edges.

 \documentclass{article}
 \usepackage{animate}
 \usepackage{tikz}
 \usepackage{tkz-graph}
 \usetikzlibrary{arrows}
 \usetikzlibrary{lindenmayersystems}
 \usepackage[paperheight=11cm,paperwidth=11cm,bottom=0cm,top=0.21cm,left=0cm,right=0cm]{geometry}



\begin{document}


\begin{animateinline}[controls,autoplay,loop]{2}
\multiframe{12}{n=18+72}{
\begin{tikzpicture}
\foreach \x in {18,90,...,306}
{
\draw(\x:5cm) circle (5pt)[fill=black];
\draw(\x:3cm) circle (5pt)[fill=black];
\draw(\x:5cm) [line width=3pt]-- (\x+72:5cm);
\draw(\x:3cm) [line width=3pt] -- (\x+144:3cm);
\draw(\x:5cm) [line width=3pt] -- (\x:3cm);
}
\draw(\n:5cm)[line width=7pt,color=blue]--(\n+72:5cm);  \end{tikzpicture}    
}
\end{animateinline}

\end{document}
  • Would you please explain in more detail what you want to achieve? – AlexG Jul 23 '15 at 08:48
  • I want to produce animation which indicate cycle of length 4.I tried the above code but the it shaded to single edges.I want an animation which shade all edges of cycle. – kalpeshmpopat Jul 23 '15 at 09:11
  • I am not familiar with Petersen graphs nor with what a cycle means here. That is why I am asking. Up to now, I can see the outer edges being coloured blue one by one, one at a time. Do you want them to be successively coloured blue until all of them are blue, and if so, in which order? What about the nodes? – AlexG Jul 23 '15 at 09:26
  • A cycle of four length means sequence of four edges whose starting and ending node is same.In above code outer edges being colored one by one.But i want colored them continuously.Say suppose in first frame it should color one edge(say edge-1) and in next frame it should color two edges(say edge-1 and edge-2) like wise....And animation can be start from any of the node. – kalpeshmpopat Jul 23 '15 at 09:42

2 Answers2

2

This colours the outer edges continuously:

\documentclass[border=10pt]{standalone}
%\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
%\usepackage{tkz-graph}
%\usetikzlibrary{arrows}
%\usetikzlibrary{lindenmayersystems}
%\usepackage[paperheight=11cm,paperwidth=11cm,bottom=0cm,top=0.21cm,left=0cm,right=0cm]{geometry}

\begin{document}

\begin{animateinline}[controls,autoplay,loop]{2}
\multiframe{6}{i=0+1,n=-54+72}{
  \begin{tikzpicture}
  \foreach \x in {18,90,...,306}
  {
    \draw(\x:5cm) circle (5pt)[fill=black];
    \draw(\x:3cm) circle (5pt)[fill=black];
    \draw(\x:5cm) [line width=3pt]-- (\x+72:5cm);
    \draw(\x:3cm) [line width=3pt] -- (\x+144:3cm);
    \draw(\x:5cm) [line width=3pt] -- (\x:3cm);
  }
  \ifnum\i>0
    \ifnum\i=1
      \xdef\cycle{\n}
    \else
      \xdef\cycle{\cycle,\n}
    \fi
    \foreach \x in \cycle
    {
      \draw(\x:5cm)[line width=7pt,color=blue]--(\x+72:5cm);
    }
  \fi
  \end{tikzpicture}    
}
\end{animateinline}

\end{document}
AlexG
  • 54,894
2

Is something like this what you want?

\documentclass{beamer}

\usepackage{tikz}

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }


\begin{document}
\begin{frame}[fragile]
\frametitle{Animation}

\begin{tikzpicture}[%
    mydot/.style={circle, fill=#1, inner sep=0pt, outer sep=0pt, minimum width=10pt},
    line width=3pt]

\foreach \x [evaluate=\x as \i using int(\x)] in {18,90,...,306}
{
 \node[mydot=blue, visible on=<1->] (out-\i) at (\x:4cm) {};
 \node[mydot=red, visible on=<2->] (in-\i) at (\x:2cm) {};
}

\foreach \i [evaluate=\i as \k using {int(mod(\i+72,360))},
                evaluate=\i as \j using {int(mod(\i+144,360))}]
                in {18,90,...,306}{
   \draw[visible on=<4->] (out-\i) -- (in-\i);
    \draw[visible on=<3->] (out-\i)--(out-\k);
   \draw[visible on=<5->] (in-\i)--(in-\j);
}
\end{tikzpicture}
\end{frame}    
\end{document}  

enter image description here

Ignasi
  • 136,588