Soon we can celebrate the New Year. How can we use TikZ for drawing fireworks? For example like this, photographed by Kurume-Shimin, found on Wikipedia:

Fireworks Aug 5, 2011 in Kurume, Fukuoka, Japan

Click on Image search for getting further impressions. On the Wikipedia page you can see further effects, just click the image. I would like to post a nice drawing on our blog for celebrating New Year, and as addition to the TikZ example gallery on this occasion.

link|improve this question

feedback

3 Answers

up vote 52 down vote accepted

Here is my take:

Update: More "bling bling", more compilation time... (and trying @Stefan's brilliant idea)

Update 2 Thanks to Stefan, I have seen that the previous version was only working in the QtikZ environment but nowhere(I guess) else. For some reason beyond me, the fadings are still not displayed correctly in Adobe Reader but at least it works (almost) properly in SumatraPDF on Windows. Sorry for the inconvenience and Happy New Year everyone!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing}
\pgfdeclareradialshading{someshade}{\pgfpointorigin}{color(0mm)=(pgftransparent!40);color(4mm)=(pgftransparent!50);color(8mm)=(pgftransparent!70);color(2cm)=(pgftransparent!100)}
\pgfdeclareradialshading{somenodeshade}{\pgfpointorigin}{color(0mm)=(pgftransparent!0);color(2mm)=(pgftransparent!0);color(5mm)=(pgftransparent!99);color(20mm)=(pgftransparent!100)}
\pgfdeclareradialshading{invertshade}{\pgfpointorigin}{color(0mm)=(pgftransparent!100);color(10mm)=(pgftransparent!95);color(16mm)=(pgftransparent!60);color(2cm)=(pgftransparent!0)}

\pgfdeclarefading{fadeit}{\pgfuseshading{someshade}}
\pgfdeclarefading{fadein}{\pgfuseshading{invertshade}}

\begin{document}
\begin{tikzpicture}[projectile/.style={decorate,decoration={random steps,segment length=2pt,amplitude=0.5pt}}]
\fill[black] (-4,-3) rectangle (6,4);

\begin{scope}[xshift=0cm,yshift=-0.4cm,transparency group]
\pgfsetfading{fadein}{\pgftransformshift{\pgfpointorigin}}
    \foreach \x in {0,10,..., 360}{\draw[blue!80!white,projectile,line width=1.1pt] (0,0) to [in=90] (10*rand+\x:rand*1mm+2cm);};
\end{scope}

\begin{scope}[xshift=2cm,yshift=1cm]
   \foreach \x in {0,12,..., 360}{\draw [yellow!5,thick,projectile] (0.7,0) to  (3*rand+\x :1mm*rand+2.2cm)  node%
[circle,inner sep=1mm,shade,shading=somenodeshade,opacity=1,outer sep=0] {};}
{\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{2.5cm}{1cm}}}};\fill[white] (-3,-3) rectangle (3,3);
\end{scope}

\begin{scope}[xshift=3cm,yshift=-1cm]
\foreach \x in {0,10,..., 360}{\def\r1{rand}\draw [yellow]  ($(0,0)!abs{\r1}!(\x :5mm)$) to [in=90] ($(0,0)!abs{\r1}+0.2!(\x :8mm)$);}
{\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{3cm}{-1cm}}}};\fill[yellow,opacity=0.6] (-3,-3) rectangle (3,3);
\end{scope}

\begin{scope}[xshift=-1cm,yshift=1.5cm]
   \foreach \x in {0,12,..., 360}{\def\r2{rand}\draw [red,line width=0.5pt]  ($(0,0)!abs{\r2}!(\x :3mm)$) -- ($(0,0)!abs{\r2}+0.1!(\x :7mm)$);}
{\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{-1cm}{1.5cm}}}};\fill[red,opacity=0.6] (-3,-3) rectangle (3,3);
\end{scope}
\end{tikzpicture}
\end{document}

and the updated code gives (see the history for the previous code)

enter image description here

link|improve this answer
5  
Fading is a very good idea here ! – Altermundus Dec 28 '11 at 18:39
1  
Same is your coloring scheme. I loved it! – percusse Dec 28 '11 at 18:42
Incredible, the first one is beautiful and the second one is very realistic! Is fading of projectile paths possible, instead of for example the homogeneous blue? – Stefan Kottwitz Dec 29 '11 at 0:31
@StefanKottwitz Let me try. – percusse Dec 29 '11 at 9:09
1  
I think this is the best one. – Marc van Dongen Dec 29 '11 at 13:14
show 3 more comments
feedback

Update 4 : it's better with more rays and I add a decoration (Stephan's idea) but the result is aleatory. I change some arguments. With some shading in the center (idea from percusse and bloodworks):

\documentclass{minimal} 
\usepackage[dvipsnames,svgnames]{xcolor} 
\usepackage{tikz}
 \usetikzlibrary{calc} 

 \usetikzlibrary{decorations,decorations.pathmorphing} 

\begin{document}

\begin{tikzpicture}[decoration={bent,aspect=.3}]
  \draw[fill=black] (-8,-3) rectangle (8,5); 
  \foreach \colA/\colB/\sx/\sy in {red/yellow/-4/2,blue/green/-2/1,
                                   yellow/red/0/2,green/blue/4/2,yellow/white/3/1.5} 
{% 
   \draw[shading=radial, inner color=white, outer color=black, opacity=.5]  (\sx,\sy) circle (1cm);   
  \pgfmathparse{rnd}   
  \let\ri\pgfmathresult  
  \begin{scope}[xshift=\sx]
      \foreach \i in {0,...,150}{%  
         \pgfmathparse{rnd}
         \global\let\x\pgfmathresult 
         \pgfmathparse{rnd}  
         \global\let\y\pgfmathresult 
         \pgfmathparse{rnd} 
         \let\c\pgfmathresult 
         \pgfmathsetmacro{\col}{50*\c+50} 
           \draw[decorate,\colA!\col!\colB] %
           ($(360*\x:2*\ri*\y+1) +(\sx,\sy)$) to    ($(360*\x:1*\y) + (\sx,\sy)$);} 
  \end{scope}
} 
\end{tikzpicture} 
\end{document} 

enter image description here

link|improve this answer
Very nice already! Perhaps adding a path morphing decoration would be nice, such as by \begin{tikzpicture}[decoration={bent,aspect=.3}] and \draw[decorate,\colA!\col!\colB] however modified for bending in one direction (wind effect). – Stefan Kottwitz Dec 28 '11 at 18:11
Yes there are some possible modifications. – Altermundus Dec 28 '11 at 18:25
2  
Very nice! Maybe using \colA for the inner color option would make it even nicer! – percusse Dec 28 '11 at 20:17
I try but the result was not fine – Altermundus Dec 28 '11 at 20:20
feedback

Not quite as smart as the two above but well thats what i have. I (almost) used no commands starting with pgf.

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing} 

\begin{document}

\begin{tikzpicture}
 \draw[fill=black] (-5,-15) rectangle (25,15);
 \foreach \mya in {1,10,20}{
  \pgfmathrandominteger{\myb}{1}{10}
  \draw[shading=radial, inner color=white, outer color=black, opacity=.5](\mya , \myb) circle (5cm);
  \foreach \x in {-3.1,-2,-1.1,0.1,1.2,2.3,3.1}{%
  \foreach \y in {-3.2,-2.1,-1.2,0,1.1,2,3.2}{%
  \draw[red, thick, decorate, decoration={random steps,segment length=3pt,amplitude=1pt}, rotate around={10:(\mya , \myb)}, opacity=0.7](\mya , \myb)--(\mya+\x, \myb+\y)node[red, yshift=-.1mm]{*};%
  \draw[blue,decorate, decoration={random steps,segment length=3pt,amplitude=1pt}, rotate around={20:(\mya , \myb)}](\mya , \myb)--(\mya+\x, \myb+\y)node[red, yshift=-.1mm]{*};%
  \draw[red!50!yellow, decorate, decoration={random steps,segment length=3pt,amplitude=1pt}, rotate around={50:(\mya , \myb)}](\mya , \myb)--(\mya+\x,  \myb+\y);
 }
 }
 \draw[decorate, decoration=snake, red, thick] (0 , -13)--(\mya , \myb);
}


\end{tikzpicture}
\end{document}

enter image description here

It takes a while to compile!

link|improve this answer
8  
I can't look at it without the virtual "Piiuuuuuuw" sound in my head :) – percusse Dec 28 '11 at 22:03
feedback

Your Answer

 
or
required, but never shown

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