Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created January 6, 2013 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/4466810 to your computer and use it in GitHub Desktop.
Save zr-tex8r/4466810 to your computer and use it in GitHub Desktop.
LaTeX: fireworks animation embedded in PDF
%% to be compiled with pdflatex
\documentclass[a4paper]{article}
%% setting tight page manually ('standalone' avoided)
\usepackage[papersize={8cm,6cm},
margin=0mm,noheadfoot]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.shapes}
\usepackage{animate}
\begin{document}
\begin{animateinline}[autoplay,loop]{5}% 5 fps
%% use multiframe with a parameter
\multiframe{20}{iFC=1+1}{% \iFC goes 1 to 20
\begin{tikzpicture}
\useasboundingbox (-3,-3) rectangle (5,3);
\pgfmathtruncatemacro{\radius}{\iFC}% copy value
% 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{document}
%% to be compiled with pdflatex
\documentclass[a4paper]{article}
\usepackage[papersize={8cm,6cm},
margin=0mm,noheadfoot]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.shapes}
\usepackage{animate}
\begin{document}
\begin{animateinline}[autoplay,loop]{5}%
\multiframe{20}{iFC=1+1}{%
\begin{tikzpicture}
\useasboundingbox (-3,-3) rectangle (5,3);
\pgfmathtruncatemacro{\radius}{\iFC}%
% background rectangle
\filldraw[black] (-3,-3) rectangle (5,3);
\pgfmathparse{100-(\radius)};
\foreach \x in {-2,-.5,2.3,4}{
\pgfmathrandominteger{\y}{0}{2.9}
\node[xshift=5*rnd,blue!\pgfmathresult!white,scale={.8*rnd}]at (\x,\y){$\star$};
}
\ifnum\radius<4
\pgfmathparse{100-(\radius)*4};
\draw[blue!\pgfmathresult!black,decorate, decoration={random steps,segment length=3pt,amplitude=.5pt},ultra thin] (0.5 , -2.9)--(0,0);
\fi
\ifnum\radius<11
\pgfmathparse{100-(\radius-1)*10};
\fill[shading=radial, inner color=white!\pgfmathresult!black, outer color=black, opacity=.8](0,0) circle (\radius mm -2mm);
\foreach \angle in {0,10,...,360}
{
\draw[red!\pgfmathresult!black,,decorate, decoration={random steps,segment length=1pt,amplitude=.3pt}] (0,0) -- (\angle:\radius mm)node[white!\pgfmathresult!blue, yshift=-.1mm,scale=.35*rnd]{*};
}
\fi
%%%
\ifnum\radius>5
\ifnum\radius<10
\pgfmathparse{100-(\radius)*4};
\draw[xshift=1cm,yshift=1cm,red!\pgfmathresult!black,decorate, decoration={random steps,segment length=3pt,amplitude=.5pt},ultra thin] (1 , -3.9)--(0,0);
\fi\fi
\ifnum\radius>5
\pgfmathparse{100-(\radius-6)*7};
\fill[xshift=1cm,yshift=1cm,shading=radial, inner color=white!\pgfmathresult!black, outer color=black, opacity=.8](0,0) circle (\radius mm -9mm);
\foreach \angle in {0,20,...,360}
{
\draw[xshift=1cm,yshift=1cm,orange!\pgfmathresult!black,decorate, decoration={random steps,segment length=1pt,amplitude=.3pt}] (0,0) -- (\angle:\radius mm -4mm)node[white!\pgfmathresult!blue, yshift=-.1mm,scale=.5*rnd]{*};
}
\foreach \angle in {10,30,...,350}{
\draw[xshift=1cm,yshift=1cm,red!\pgfmathresult!black,decorate, decoration={random steps,segment length=1pt,amplitude=.5pt}] (0,0) -- (\angle:\radius mm -5mm)node[red!\pgfmathresult!black, yshift=-.1mm,scale=.5*rnd]{*};
}
\foreach \angle in {15,35,...,355}{
\draw[xshift=1cm,yshift=1cm,yellow!\pgfmathresult!black,decorate, decoration={random steps,segment length=1pt,amplitude=.5pt},opacity=.5] (0,0) -- (\angle:\radius mm -6mm)node[white!\pgfmathresult!black, yshift=-.1mm,scale=.5*rnd,opacity=1]{*};
}
\foreach \angle in {5,25,...,355}{
\draw[xshift=1cm,yshift=1cm,green!\pgfmathresult!black,decorate, decoration={random steps,segment length=1pt,amplitude=.5pt},opacity=.5] (0,0) -- (\angle:\radius mm -3mm)node[orange!\pgfmathresult!black, yshift=-.1mm,scale=.5*rnd,opacity=1]{*};
}
\fi
% yellow firework
\ifnum\radius>10
\ifnum\radius<14
\pgfmathparse{100-(\radius)*4};
\draw[xshift=3cm,yshift=1.5cm,blue!\pgfmathresult!black,decorate, decoration={random steps,segment length=3pt,amplitude=.5pt},ultra thin] (1 , -4.5)--(0,0);
\fi\fi
\ifnum\radius>10
\pgfmathparse{100-(\radius-1)*5};
\fill[xshift=3cm,yshift=1.5cm,shading=radial, inner color=green!\pgfmathresult!black, outer color=black, opacity=.8](0,0) circle (\radius mm -10mm);
\foreach \angle in {0,10,...,360}
{
\draw[xshift=3cm,yshift=1.5cm,yellow!\pgfmathresult!black,decorate, decoration={random steps,segment length=2pt,amplitude=.5pt},opacity=.5] (0,0) -- (\angle:\radius mm -8mm)node[orange!\pgfmathresult!black, yshift=-.1mm,scale=.8*rnd,opacity=1]{*};
}
\fi
% blue green firework
\ifnum\radius>10
\ifnum\radius<14
\pgfmathparse{100-(\radius)*4};
\draw[xshift=-1.5cm,yshift=1.5cm,green!\pgfmathresult!black,decorate, decoration={random steps,segment length=3pt,amplitude=.5pt},ultra thin] (-1, -4.5)--(0,0);
\fi\fi
\ifnum\radius>10
\pgfmathparse{100-(\radius-1)*5};
\fill[xshift=-1.5cm,yshift=1.5cm,shading=radial, inner color=yellow!\pgfmathresult!black, outer color=black, opacity=.8](0,0) circle (\radius mm -10mm);
\foreach \angle in {10,20,...,360}
{
\draw[xshift=-1.5cm,yshift=1.5cm,green!\pgfmathresult!black,decorate, decoration={random steps,segment length=2pt,amplitude=.5pt},opacity=.5] (0,0) -- (\angle:\radius mm -8mm)node[red!\pgfmathresult!black, yshift=-.1mm,scale=.8*rnd,opacity=1]{*};
}
\fi
\end{tikzpicture}%
}%
\end{animateinline}
\end{document}
@zr-tex8r
Copy link
Author

zr-tex8r commented Jan 6, 2013

There works are derived from the works posted on TeX.SE:
http://tex.stackexchange.com/questions/39485/how-can-we-display-fireworks
The original works simply generate a multi-page PDF document and then convert it to an animated GIF image (by use of ImageMagick). I modified them so that animation will be embedded in PDF, by the aid of 'animate' pacakge.
The resulted PDF files can be obtained from:
-- firework-cmhughes.pdf: https://docs.google.com/open?id=0B4TklbcTMngmaFZwU0x6NmZ6NDA
-- firework-kumar.pdf: https://docs.google.com/open?id=0B4TklbcTMngmVS1sMmw4UE5tV0k
Note that animation will probably work only when viewed with Adobe product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment