# Draw an animated image with Tikz

After several unsuccessful tries to reproduce the following post in order to draw this image in gif format:

I come in desperation, to wonder if it's possible to do the same picture with Tikz environment.

After taking into consideration the answer from marmot, I still can't make the conversion.

Can a benevolent person please do anything that might assist me?

• The answer is certainly yes, but do you have the source code for any of the frames? – marmot Jun 10 '18 at 20:25
• Precisely, I do not know exactly for writing a part of Tikz for a drawing close to this image. – Furdzik Jun 10 '18 at 21:07
• Well, what have you got? You should be able to do some of it at least. – cfr Jun 10 '18 at 21:31
• The conversion process in the first answer to the linked question works fine. I can't get the animation to run, but I can never get them to run, so that doesn't mean anything. – cfr Jun 10 '18 at 21:43
• As it's not possible to include gif animations in beamer presentations unless you convert them to something else, why not to ask how to draw like something which could be included in beamer? Even more, you've forgotten to mention beamer in your question and it's an important point to be considered. – Ignasi Jun 11 '18 at 8:53

To produce

compile

\documentclass[tikz, border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta,decorations.markings}

\begin{document}
\foreach \X in {0,0.05,...,1}
{\begin{tikzpicture}
%
\path[use as bounding box](-0.2,-2) rectangle (4.2,3.1);
\draw[line width=4mm,line cap=round,green!80!black!70!blue] (0,2) -- (0,3);
\draw[line width=4mm,green!20!black,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,2.2) -- (0,2.8);
%
\draw[line width=4mm,line cap=round,green!20!black,Butt Cap-] (0,0) --
(0,1.6);
\draw[line width=4mm,green!80!black!70!blue,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,0) -- (0,1.4);
%
\draw[line width=4mm,line cap=round,red,Butt Cap-] (1,1.1) --
(1,1.6);
\draw[line width=4mm,orange] (1,1.1) -- (1,1.3);
%
\draw[line width=1.5mm,orange!50!yellow,rounded corners=5mm,-Triangle,
postaction={decorate,decoration={markings, mark=at position \X with {%
\coordinate (first);
}}},shorten >=10mm]
(0,0) -- (0,-1.5) -- (4,-1.5) --  (4,1.8);
%
\draw[line width=1.5mm,orange!50!yellow,rounded corners=5mm,-Triangle,
postaction={decorate,decoration={markings, mark=at position \X with {%
\coordinate (second);
}}},shorten >=5mm]
(1,1) -- (1,0) --  (3.14,0);
%
\begin{scope}[xshift=3cm]
\draw[line width=4mm,line cap=round,green!20!black,Butt Cap-] (0,0) --
(0,1.6);
\draw[line width=4mm,green!80!black!70!blue,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,0) -- (0,1.4);
%
\draw[line width=4mm,line cap=round,red,Butt Cap-] (1,1.1) --
(1,1.6);
\draw[line width=4mm,orange] (1,1.1) -- (1,1.3);
\end{scope}
%
\begin{scope}[shift={(first)}]
\draw[line width=4mm,line cap=round,cyan,-Butt Cap] (0,-0.6) --
(0,0);
\draw[line width=4mm,orange] (0,-0.15) -- (0,0);
\draw[line width=4mm,green!20!black] (0,-0.25) -- (0,-0.15);
\end{scope}
%
\begin{scope}[shift={(second)}]
\draw[line width=4mm,red,line cap=round,red,Butt Cap-] (0,0.1) -- (0,-1);
\draw[line width=4mm,red!50!black,
dash pattern=on 3pt off 7pt on 8pt off 5pt on 3pt] (0,0) -- (0,-0.9);
\end{scope}
\end{tikzpicture}
}
\end{document}


and then convert with

convert -density 300 -delay 24 -loop 0 -alpha remove multipage.pdf animated.gif


\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.markings}
\newcount\myangle

\begin{document}
\transduration{2}
\animate<2-22>
\begin{frame}[t,fragile]{Protein}
\animatevalue<2-22>{\myangle}{0}{20}
\begin{tikzpicture}
\pgfmathsetmacro{\X}{\myangle/21}
%
\path[use as bounding box](-0.2,-2) rectangle (4.2,3.1);
\draw[line width=4mm,line cap=round,green!80!black!70!blue] (0,2) -- (0,3);
\draw[line width=4mm,green!20!black,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,2.2) -- (0,2.8);
%
\draw[line width=4mm,line cap=round,green!20!black,Butt Cap-] (0,0) --
(0,1.6);
\draw[line width=4mm,green!80!black!70!blue,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,0) -- (0,1.4);
%
\draw[line width=4mm,line cap=round,red,Butt Cap-] (1,1.1) --
(1,1.6);
\draw[line width=4mm,orange] (1,1.1) -- (1,1.3);
%
\draw[line width=1.5mm,orange!50!yellow,rounded corners=5mm,-Triangle,
postaction={decorate,decoration={markings, mark=at position \X with {%
\coordinate (first);
}}},shorten >=10mm]
(0,0) -- (0,-1.5) -- (4,-1.5) --  (4,1.8);
%
\draw[line width=1.5mm,orange!50!yellow,rounded corners=5mm,-Triangle,
postaction={decorate,decoration={markings, mark=at position \X with {%
\coordinate (second);
}}},shorten >=5mm]
(1,1) -- (1,0) --  (3.14,0);
%
\begin{scope}[xshift=3cm]
\draw[line width=4mm,line cap=round,green!20!black,Butt Cap-] (0,0) --
(0,1.6);
\draw[line width=4mm,green!80!black!70!blue,
dash pattern=on 8pt off 7pt on 3pt off 8pt] (0,0) -- (0,1.4);
%
\draw[line width=4mm,line cap=round,red,Butt Cap-] (1,1.1) --
(1,1.6);
\draw[line width=4mm,orange] (1,1.1) -- (1,1.3);
\end{scope}
%
\begin{scope}[shift={(first)}]
\draw[line width=4mm,line cap=round,cyan,-Butt Cap] (0,-0.6) --
(0,0);
\draw[line width=4mm,orange] (0,-0.15) -- (0,0);
\draw[line width=4mm,green!20!black] (0,-0.25) -- (0,-0.15);
\end{scope}
%
\begin{scope}[shift={(second)}]
\draw[line width=4mm,red,line cap=round,red,Butt Cap-] (0,0.1) -- (0,-1);
\draw[line width=4mm,red!50!black,
dash pattern=on 3pt off 7pt on 8pt off 5pt on 3pt] (0,0) -- (0,-0.9);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

• Many thanks in advance for taking the time to solve my problem. However, I forgot to specify that the drawing, in this case, is in a Beamer file. You can look it in my post. – Furdzik Jun 11 '18 at 5:58
• @Furdzik You have to say \usepackage{tikz} above \usetikzlibrary{arrows.meta,decorations.markings}. In standalone, tikz gets loaded because it was added to the options in \documentclass[tikz, border=3.14mm]{standalone}. Notice also that in beamer you can animate \X with the corresponding animate syntax. – marmot Jun 11 '18 at 11:51
• Unfortunately, I didn't have the animation despite the modifications made by you. Please take a look at the post above where I put an image of the error message. – Furdzik Jun 11 '18 at 12:51
• @Furdzik You have to load tikz but also needed libraries \usetikzlibrary{arrows.meta, decorations.markings} as in marmot's code. – Ignasi Jun 11 '18 at 13:35
• I can't do the conversion. Please take a look at the image embedded in the initial message. – Furdzik Jun 11 '18 at 15:12