3

Here is a question about how to display fireworks and I like the answer of cmhughes very much. It generates 20 frames and then use them to generate a gif file. But I would like the 20 frames to be displayed in only one frame. I know I should use the animate package, but I am new to the package and I do not know how to associate it with the tikz package. Here is the code, but it does not work. Anyone can help? Thanks in advance and happy new year.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.shapes}
\usepackage{animate}
\usepackage{ifthen}

\begin{document}
\begin{frame}
\begin{animateinline}[poster=first, controls]{8}%
    \multiframe{21}{radius=1+1}{%
    \begin{tikzpicture}
    % background rectangle
    \filldraw[black] (-3,-3) rectangle (5,3);
    % skyline
    \filldraw[black!80!blue](-3,-3)--(-3,-2)--(-2.5,-2)--(-2.5,-1)--(-2.25,-1)--(-2.25,-2)--(-2,-2) --(-2,-1)--(-1.75,-0.75)--(-1.5,-1) --(-1.5,-2)--(-1.1,-2)--(-1.1,0)--(-0.5,0)--(-0.5,-2) --(0,-2)--(0,-1.5)--(1,-1.5)--(1.25,-0.5)--(1.5,-1.5)--(1.5,-2) --(2,-2)--(2,0)--(2.5,0)--(2.5,-2) --(3,-2)--(3,-1)--(4,-1)--(4,-2)--(5,-2)--(5,-3)--cycle;
    % moon- what a hack!
    \filldraw[white] (4,2.5) arc (90:-90:20pt);
    \filldraw[black] (3.8,2.5) arc (90:-90:20pt);
    % fireworks
    \pgfmathparse{100-(\radius-1)*10};
    % red firework
    \ifnum\radius<11
    \draw[decorate,decoration={crosses},red!\pgfmathresult!black] (0,0) circle (\radius ex);
    \fi
    % orange firework
    \pgfmathparse{100-(\radius-6)*10};
    \ifnum\radius>5
    \ifnum\radius<16
    \draw[decorate,decoration={crosses},orange!\pgfmathresult!black] (1,1) circle ( \radius ex-5ex);
    \fi
    \fi
    % yellow firework
    \pgfmathparse{100-(\radius-11)*10};
    \ifnum\radius>10
    \draw[decorate,decoration={crosses},yellow!\pgfmathresult!black] (2.5,1) circle (\radius ex-10ex);
    \fi
    \end{tikzpicture}
    }
\end{animateinline}
\end{frame} 
\end{document}

Edit: The above code is obtained by copying the code of cmhughes (Here) into the code in the example (Here), but it does not work when compiling.

Wieshawn
  • 273

2 Answers2

4

cmhughes code uses standalone class to produce a multipage pdf file, you can include inside a beamer frame with command \animategraphics instead of multiframe.

Supose that fireworks is the pdf file produced by cmhughes code, then following code:

\documentclass{beamer}
\usepackage{animate}
\begin{document}
\begin{frame}
\animategraphics{1}{fireworks}{}{}
\end{frame}
\end{document}

will generate a pdf file with the whole animation inside one frame. I've to open it with Adobe Reader to watch it, I don't know what others pdf readers can reproduce it.

Ignasi
  • 136,588
2

Just for completeness, the all-in-one-file version using \multiframe.

The original code of the question does not compile, because the TeX primitive \ifnum compares integers but \multiframe{21}{radius=1+1}{...} defines \radius as a real number.

Just replace radius with iRadius to ensure that the parameter is defined as an integer:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.shapes}
\usepackage{animate}
\usepackage{ifthen}

\begin{document}
\begin{frame}
\begin{animateinline}[poster=first, controls, loop]{8}%
    \multiframe{21}{iRadius=1+1}{%
    \begin{tikzpicture}
    % background rectangle
    \filldraw[black] (-3,-3) rectangle (5,3);
    % skyline
    \filldraw[black!80!blue](-3,-3)--(-3,-2)--(-2.5,-2)--(-2.5,-1)--(-2.25,-1)--(-2.25,-2)--(-2,-2) --(-2,-1)--(-1.75,-0.75)--(-1.5,-1) --(-1.5,-2)--(-1.1,-2)--(-1.1,0)--(-0.5,0)--(-0.5,-2) --(0,-2)--(0,-1.5)--(1,-1.5)--(1.25,-0.5)--(1.5,-1.5)--(1.5,-2) --(2,-2)--(2,0)--(2.5,0)--(2.5,-2) --(3,-2)--(3,-1)--(4,-1)--(4,-2)--(5,-2)--(5,-3)--cycle;
    % moon- what a hack!
    \filldraw[white] (4,2.5) arc (90:-90:20pt);
    \filldraw[black] (3.8,2.5) arc (90:-90:20pt);
    % fireworks
    \pgfmathparse{100-(\iRadius-1)*10};
    % red firework
    \ifnum\iRadius<11
    \draw[decorate,decoration={crosses},red!\pgfmathresult!black] (0,0) circle (\iRadius ex);
    \fi
    % orange firework
    \pgfmathparse{100-(\iRadius-6)*10};
    \ifnum\iRadius>5
    \ifnum\iRadius<16
    \draw[decorate,decoration={crosses},orange!\pgfmathresult!black] (1,1) circle ( \iRadius ex-5ex);
    \fi
    \fi
    % yellow firework
    \pgfmathparse{100-(\iRadius-11)*10};
    \ifnum\iRadius>10
    \draw[decorate,decoration={crosses},yellow!\pgfmathresult!black] (2.5,1) circle (\iRadius ex-10ex);
    \fi
    \end{tikzpicture}
    }
\end{animateinline}
\end{frame}
\end{document}
AlexG
  • 54,894