0

I saw this topic:

Improve code for four stroke engine in TikZ

Questions:

  1. How to make 4 pistons (Intake, Compression, Combustion, Exhaust) under one same row, as 4 Stroke Engine and animate them together?

  2. I want to save the animation into gif, I am able to obtain the pdf with tons of pictures. But do not have idea to make it into gif. Online converter is not even working.

this is the one I want to convert into GIF:

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}

\tikzset{ relative to node/.style={ shift={(#1.center)}, x={(#1.east)}, y={(#1.north)}, }, kolben/.pic={ \node[fill=white,draw,minimum width=1.5cm,minimum height=1.3cm] (-a) at (0,0.2) {}; \begin{scope}[relative to node=-a] \draw (-1,0.2) -- ++(2,0); \draw (-1,0.3) -- ++(2,0); \draw (-1,0.4) -- ++(2,0); \end{scope} \draw (0,0) circle(0.07); }, valve/.pic={ \draw[fill=white] (-0.175,0) -- (-0.125,0.05) -- (-0.05,0.05) -- (-0.05,0.15) -- (-0.075,0.15) -- (-0.075,0.2) -- (0.075,0.2) -- (0.075,0.15) -- (0.05,0.15) -- (0.05,0.05) -- (0.125,0.05) -- (0.175,0) -- cycle; }, cylinder/.pic={ \draw (-0.75,1.55) -- (-0.8,1.55) -- (-0.8,5.05) -- (-0.5,5.05) -- (-0.55,5) -- (-0.75,5) -- cycle; \draw (-0.25,5.05) -- (-0.2,5) -- (0.2,5) -- (0.25,5.05) -- cycle; \draw[xscale=-1] (-0.75,1.55) -- (-0.8,1.55) -- (-0.8,5.05) -- (-0.5,5.05) -- (-0.55,5) -- (-0.75,5) -- cycle; }, crank/.pic={ \draw[fill=white,rounded corners=1mm] (90:0.75) arc (90:270:0.75) -- (0,-0.1) [rounded corners=0mm] -- (1,-0.1) arc (-90:90:0.1) [rounded corners=1mm] -- (0,0.1) -- cycle (1,0) circle (0.05); } }

\begin{document} \foreach \phase [ evaluate=\phase as \x using {int(mod(\phase + 90,360))}, evaluate=\phase as \case using {int(mod(\phase/180,4))}, evaluate=\x as \d using {40*sin(\x)+50}, ] in {0,5,...,719}{ \begin{tikzpicture} \useasboundingbox (-2,-2) rectangle (2,6);

        \coordinate (pivot) at (0,{3+sin(\x)});
        \coordinate (piston-top) at (0,{3+sin(\x)+1.3/2+0.2});

        \ifcase\case
        \colorlet{gascolor}{blue!10}
        \pgfmathsetmacro\valveone{1}
        \pgfmathsetmacro\valvetwo{0}
        \or
        \colorlet{gascolor}{blue!\d}
        \pgfmathsetmacro\valveone{0}
        \pgfmathsetmacro\valvetwo{0}
        \or
        \colorlet{gascolor}{red!\d}
        \pgfmathsetmacro\valveone{0}
        \pgfmathsetmacro\valvetwo{0}
        \or
        \colorlet{gascolor}{gray!10}
        \pgfmathsetmacro\valveone{0}
        \pgfmathsetmacro\valvetwo{1}
        \fi

        \draw[line width=14.9mm,gascolor] (piston-top) -- (0,5);

        \pic (cylinder) at (0,0) {cylinder};

        \pic (valve1) at (-0.375,{5-0.1*\valveone}) {valve};
        \pic (valve2) at (0.375,{5-0.1*\valvetwo}) {valve};


        \draw[double distance=2mm-\pgflinewidth,line cap=round] (\x:1) -- (pivot);  

        \pic[rotate=\x] (crank) at (0,0) {crank};
        \pic (kolben) at (pivot) {kolben};

        \node[anchor=base] at (1.25,3) {$ x $};
        \ifnum\x=0
        \fill[red] (1,3) circle (1.5pt);
        \else
        \ifnum\x=180
        \fill[red] (1,3) circle (1.5pt);
        \else
        \draw[->,red,ultra thick] (1,3) -- +(0,{sin(\x)});
        \fi
        \fi

        \node[anchor=base] at (1.75,3) {$ \dot{x} $};
        \ifnum\x=90
        \fill[blue] (1.5,3) circle (1.5pt);
        \else
        \ifnum\x=270
        \fill[blue] (1.5,3) circle (1.5pt);
        \else
        \draw[->,blue,ultra thick] (1.5,3) -- +(0,{cos(\x)});
        \fi
        \fi

        \ifnum\phase=360
        \begin{scope}
            \clip (-7.5mm,5cm-0.5\pgflinewidth) rectangle (7.5mm,3cm);
            \node[starburst,starburst point height=3mm,inner color=yellow,outer color=red,draw=orange] at (0,5) {};
        \end{scope}
        \fi

    \end{tikzpicture}
}

\end{document}

  • 2
    Fortunately, you seem to be using Linux. Thus, the command you are after to produce animated Gif from multipage PDF is convert -density 300 -delay 4 -loop 0 -alpha remove multipage.pdf animated.gif. This command line is used in various Q/A on this site. The delay option defines the frame rate of the Gif output. Its unit is 1/100 s and -delay 4 produces 25 frames per second. Option density defines the resolution (and affects the file size) of the output. – AlexG Jan 25 '23 at 08:12
  • Hi @AlexG, yes I am using Linux.Do I need ImageMagick installed to be able to type this in terminal? convert -density 300 -delay 4 -loop 0 -alpha remove multipage.pdf animated.gif because it is not working now. I got this when type convert after installing ImageMagick: error while loading shared libraries: libMagickCore-7.Q16HDRI.so.10: cannot open shared object file: No such file or directory – Freya the Goddess Jan 26 '23 at 13:00
  • 1
    Yes, convert is part of ImageMagick. But a shared library which is part of the ImageMagick package is missing. This should not happen; something is wrong with your computer. If you are on a Debian-based system, such as Ubuntu, try a thorough system update: apt-get update && apt-get dist-upgrade. – AlexG Jan 26 '23 at 13:07
  • It works now just need to prepend the LD_LIBRARY_PATH... Linux is amazing – Freya the Goddess Jan 26 '23 at 16:11
  • With distribution provided packages this should not be necessary. Maybe a system restart would have helped too – AlexG Jan 26 '23 at 16:17

0 Answers0