2

I have done animation in edges in the following graph. I also want to highlight vertices by animation. I want to do both animation one after another. First vertices animation then edges animation. Please guide me for the same.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{animate}
\usepackage{graphicx}
\usepackage{kpfonts}
\usepackage{tkz-graph}
\begin{document}
\begin{center}
\begin{animateinline}[autoplay,loop]{40}
\multiframe{200}{n=0+0.005}{
\begin{tikzpicture}
\draw (7,0)[line width=1pt]--(11,0);
\draw (7,0)[line width=1pt]--(7,4);
\draw (7,4)[line width=1pt]--(11,4);
\draw (11,0)[line width=1pt]--(11,4);
\draw (7,0)[white,line width=1pt]--(8,1);
\draw (7,4)[white,line width=1pt]--(8,3);
\draw (11,0)[white,line width=1pt]--(10,1);
\draw (11,4)[white,line width=1pt]--(10,3);
\draw (8,1)[line width=1pt]--(8,3);
\draw (8,1)[line width=1pt]--(10,1);
\draw (10,1)[line width=1pt]--(10,3);
\draw (8,3)[line width=1pt]--(10,3);
\draw (7,0)[blue,line width=1pt]--(8,3);
\draw (7,0)[blue,line width=1pt]--(10,1);
\draw (7,4)[blue,line width=1pt]--(8,1);
\draw (7,4)[blue,line width=1pt]--(10,3);
\draw (11,4)[blue,line width=1pt]--(8,3);
\draw (11,4)[blue,line width=1pt]--(10,1);
\draw (11,0)[blue,line width=1pt]--(10,3);
\draw (11,0)[blue,line width=1pt]--(8,1);
\draw(7,4) [fill=black] circle (3pt);
\draw(11,4) [fill=black] circle (3pt);
\draw(7,0) [fill=black] circle (3pt);
\draw(11,0) [fill=black] circle (3pt) ;
\draw(8,1) [fill=black] circle (3pt);
\draw(8,3) [fill=black] circle (3pt);
\draw(10,1) [fill=black] circle (3pt);
\draw(10,3) [fill=black] circle (3pt);
 \begin{scope}[fill opacity=4]
    \filldraw[fill=blue,draw=red,line width=1pt] (7,0)--(7+\n,0+\n);
    \filldraw[fill=blue,draw=red,line width=1pt] (7,4)--(7+\n, 4-\n);
    \filldraw[fill=blue,draw=red,line width=1pt] (11,0)--(11-\n, 0+\n);
    \filldraw[fill=blue,draw=red,line width=1pt] (11,4)--(11-\n, 4-\n);
\end{scope}


 \draw(7,0)node[left=2pt]{\Large $v_2'$};
 \draw(7,4)node[left=2pt]{\Large $v_1'$};
 \draw(11,0)node[right=2pt]{\Large $v_3'$};
 \draw(11,4)node[right=2pt]{\Large $v_4'$};
 \draw(8,1)node[left=2pt]{ $v_2$};
 \draw(8,3)node[left=2pt]{ $v_1$};
 \draw(10,1)node[right=2pt]{ $v_3$};
 \draw(10,3)node[right=2pt]{ $v_4$};
 \draw(9,0)node[below=7mm]{$D_2^*(C_4)$};
  \end{tikzpicture}}
  \end{animateinline}
  \end{center}
  \end{document}
  • That looks nice! What kind of vertex animation do you have in mind? – user121799 Mar 13 '18 at 3:54
3

Here is a proposal. First the vertices grow and then the edges (as in your code).

\documentclass[a6paper]{article}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\begin{animateinline}[autoplay,loop]{40}
\multiframe{200}{n=-0.5+0.005}{
\begin{tikzpicture}
\draw (7,0)[line width=1pt]--(11,0);
\draw (7,0)[line width=1pt]--(7,4);
\draw (7,4)[line width=1pt]--(11,4);
\draw (11,0)[line width=1pt]--(11,4);
\draw (7,0)[white,line width=1pt]--(8,1);
\draw (7,4)[white,line width=1pt]--(8,3);
\draw (11,0)[white,line width=1pt]--(10,1);
\draw (11,4)[white,line width=1pt]--(10,3);
\draw (8,1)[line width=1pt]--(8,3);
\draw (8,1)[line width=1pt]--(10,1);
\draw (10,1)[line width=1pt]--(10,3);
\draw (8,3)[line width=1pt]--(10,3);
\draw (7,0)[blue,line width=1pt]--(8,3);
\draw (7,0)[blue,line width=1pt]--(10,1);
\draw (7,4)[blue,line width=1pt]--(8,1);
\draw (7,4)[blue,line width=1pt]--(10,3);
\draw (11,4)[blue,line width=1pt]--(8,3);
\draw (11,4)[blue,line width=1pt]--(10,1);
\draw (11,0)[blue,line width=1pt]--(10,3);
\draw (11,0)[blue,line width=1pt]--(8,1);
\pgfmathsetmacro{\k}{ifthenelse(\n<0,6*(0.5+\n),3)} % animates as long as \n is negative
\draw(7,4) [fill=black] circle ({\k*1pt});
\draw(11,4) [fill=black] circle ({\k*1pt});
\draw(7,0) [fill=black] circle ({\k*1pt});
\draw(11,0) [fill=black] circle ({\k*1pt}) ;
\draw(8,1) [fill=black] circle ({\k*1pt});
\draw(8,3) [fill=black] circle ({\k*1pt});
\draw(10,1) [fill=black] circle ({\k*1pt});
\draw(10,3) [fill=black] circle ({\k*1pt});
\pgfmathsetmacro{\m}{2*max(\n,0)} % <-animation will only start when \n is positive
\begin{scope}[fill opacity=4]
    \filldraw[fill=blue,draw=red,line width=1pt] (7,0)--(7+\m,0+\m);
    \filldraw[fill=blue,draw=red,line width=1pt] (7,4)--(7+\m, 4-\m);
    \filldraw[fill=blue,draw=red,line width=1pt] (11,0)--(11-\m, 0+\m);
    \filldraw[fill=blue,draw=red,line width=1pt] (11,4)--(11-\m, 4-\m);
\end{scope}
 \draw(7,0)node[left=2pt]{\Large $v_2'$};
 \draw(7,4)node[left=2pt]{\Large $v_1'$};
 \draw(11,0)node[right=2pt]{\Large $v_3'$};
 \draw(11,4)node[right=2pt]{\Large $v_4'$};
 \draw(8,1)node[left=2pt]{ $v_2$};
 \draw(8,3)node[left=2pt]{ $v_1$};
 \draw(10,1)node[right=2pt]{ $v_3$};
 \draw(10,3)node[right=2pt]{ $v_4$};
 \draw(9,0)node[below=7mm]{$D_2^*(C_4)$};
\end{tikzpicture}}
\end{animateinline}
\end{document}
  • Can I do the animation one after another? First Vertices then the edges? – kalpeshmpopat Mar 13 '18 at 6:10
  • Yes, see the ↗other answer. – AlexG Mar 13 '18 at 9:50
2

Multiple \multiframe, separated by \newframe[*], can be placed in an animateinline environment. This allows you to divide the animation into several parts. Using the starred \newframe* instead of \newframe inserts a pause between two parts (as requested in the ↗comment). The animation continues upon click.

Besides rational numbers (prefix n), the second argument of \multiframe can also define dimensions (prefix d) as loop variables. This was used to simplify the code a bit. Also, the computations involving ifthenelse(...) could be removed.

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{tikz}
\usepackage{animate}

\newcommand\staticParts{%
  \draw (7,0)[line width=1pt]--(11,0);
  \draw (7,0)[line width=1pt]--(7,4);
  \draw (7,4)[line width=1pt]--(11,4);
  \draw (11,0)[line width=1pt]--(11,4);
  \draw (7,0)[white,line width=1pt]--(8,1);
  \draw (7,4)[white,line width=1pt]--(8,3);
  \draw (11,0)[white,line width=1pt]--(10,1);
  \draw (11,4)[white,line width=1pt]--(10,3);
  \draw (8,1)[line width=1pt]--(8,3);
  \draw (8,1)[line width=1pt]--(10,1);
  \draw (10,1)[line width=1pt]--(10,3);
  \draw (8,3)[line width=1pt]--(10,3);
  \draw (7,0)[blue,line width=1pt]--(8,3);
  \draw (7,0)[blue,line width=1pt]--(10,1);
  \draw (7,4)[blue,line width=1pt]--(8,1);
  \draw (7,4)[blue,line width=1pt]--(10,3);
  \draw (11,4)[blue,line width=1pt]--(8,3);
  \draw (11,4)[blue,line width=1pt]--(10,1);
  \draw (11,0)[blue,line width=1pt]--(10,3);
  \draw (11,0)[blue,line width=1pt]--(8,1);
  \draw(7,0)node[left=2pt]{\Large $v_2'$};
  \draw(7,4)node[left=2pt]{\Large $v_1'$};
  \draw(11,0)node[right=2pt]{\Large $v_3'$};
  \draw(11,4)node[right=2pt]{\Large $v_4'$};
  \draw(8,1)node[left=2pt]{ $v_2$};
  \draw(8,3)node[left=2pt]{ $v_1$};
  \draw(10,1)node[right=2pt]{ $v_3$};
  \draw(10,3)node[right=2pt]{ $v_4$};
  \draw(9,0)node[below=7mm]{$D_2^*(C_4)$};
}

\newcommand\vertices[1]{%
  \draw(7,4) [fill=black] circle (#1);
  \draw(11,4) [fill=black] circle (#1);
  \draw(7,0) [fill=black] circle (#1);
  \draw(11,0) [fill=black] circle (#1);
  \draw(8,1) [fill=black] circle (#1);
  \draw(8,3) [fill=black] circle (#1);
  \draw(10,1) [fill=black] circle (#1);
  \draw(10,3) [fill=black] circle (#1);
}

\newcommand\edges[1]{%
  \draw[draw=red,line width=1pt] (7,0)--(7+#1,0+#1);
  \draw[draw=red,line width=1pt] (7,4)--(7+#1, 4-#1);
  \draw[draw=red,line width=1pt] (11,0)--(11-#1, 0+#1);
  \draw[draw=red,line width=1pt] (11,4)--(11-#1, 4-#1);
}

\begin{document}
\begin{animateinline}[autoplay]{40}
\multiframe{101}{d=0pt+0.03pt}{ %d=0pt,0.03pt,...,3pt
  \begin{tikzpicture}
  \staticParts
  \vertices{\d}
  \end{tikzpicture}
}
\newframe*    %insert pause, click to continue
\multiframe{101}{n=0.0+0.01}{    %n=0,0.01,...,1.0
  \begin{tikzpicture}
  \staticParts
  \edges{\n}
  \vertices{3pt}
  \end{tikzpicture}
}
\end{animateinline}
\end{document}
  • The OP asked already another question here. One possible scenario would be to copy or move your answer there. – user121799 Mar 13 '18 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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