TiKz - Draw a recursive plot with matches

I would like to produce the following draws and more. Can someone gives me some clues to achieve this easily ?

I have found the following post to draw one single match : Draw a match using TikZ

Forgive me to not give a MWE.

Conceptually similar to Vinzza's answer but with pics instead of macros and the possibility to draw a single tower with matches. A single match is obtained as pic=match.

\documentclass[svgnames,tikz,border=3mm]{standalone}
\tikzset{pics/match/.style={code={%
\fill [PeachPuff] (0,0) rectangle (0+4,0+0.2);
\fill [PeachPuff!60!Black] (0,0) -- ++(4,0)-- ++(0.1,-0.05) -- ++(-4,0) -- ++(-0.1,0.05);
\draw (0,0) -- ++(0,0.2) -- ++(4,0) -- ++(0,-0.2) -- ++(0.1,-0.05) -- ++(-4,0) -- ++(-0.1,0.05);
\shade[ball color=red] (0+4,0+0.1) ellipse (0.25cm and 0.22cm);
\draw (0+4,0+0.1) ellipse (0.25cm and 0.22cm);
}},pics/matches/.style={code={
\foreach \YY in {0,...,#1}
{\path foreach \XX in {0,...,\YY}
{ (-2.2-4.4*\XX,-2.2+4.8*#1-4.8*\YY)pic[rotate=90]{match} (-2.2-4.4*\XX,2.2+4.8*#1-4.8*\YY)pic{match}
(-2.2+4.4*\XX,-2.2+4.8*#1-4.8*\YY)pic[rotate=90]{match} (-2.2+4.4*\XX,2.2+4.8*#1-4.8*\YY)pic{match}}
(2.2+4.4*\YY,-2.2+4.8*#1-4.8*\YY)pic[rotate=90]{match};}
}}}

\begin{document}

\begin{tikzpicture}[scale=0.25,transform shape]
\path foreach \Z in {0,...,5}
{({9*\Z*(\Z+1)/2+2*\Z},0) pic{matches=\Z}
node[below=3cm,scale=6]{$\the\numexpr\Z+1$ stories}};
\end{tikzpicture}
\end{document}


• Niiiiiiiiiice!! I always forget I can use pics... And I'll try to remember the \the\numexpr\Z+1 which is probably way better than \pgfmathtruncatemacro! :D Oct 8, 2019 at 8:31
• Thanks for your code. Does pics is a TiKz mechanism to define "graphical" ? Oct 8, 2019 at 20:39
• @projetmbc Yes, it is a TikZy means of defining little pictures that you may want to repeat. They are explained in detail in section 18 Pics: Small Pictures on Paths of pgfmanual v 3.1.4.
– user194703
Oct 8, 2019 at 20:42
• Thanks. I will try to keep it my mind. Oct 8, 2019 at 20:46

You can do it with several \foreach, it may not be the prettiest way to do it, but I find it quite simple to do!

Note that I added a scope to shift/scale/rotate in the \allumette command (in the link you gave)!

\documentclass[border=5mm]{standalone}

\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\newcommand\allumette[3]{
\begin{scope}[line width=.2,shift={(#1,#2)},rotate=#3,scale=.2,shift={(.25,0)}]
\fill [PeachPuff] (0,0) rectangle (0+4,0+.2);
\fill [PeachPuff!60!Black] (0,0) -- ++(4,0)-- ++(0.1,-0.05) -- ++(-4,0) -- ++(-0.1,0.05);
\draw (0,0) -- ++(0,.2) -- ++(4,0) -- ++(0,-.2) -- ++(0.1,-0.05) -- ++(-4,0) -- ++(-0.1,0.05);
\shade[ball color=red] (0+4,0+0.1) ellipse (0.25cm and 0.22cm);
\draw (0+4,0+0.1) ellipse (0.25cm and 0.22cm);
\end{scope}
}

\begin{document}

\begin{tikzpicture}

%% Set the position of the next tower
\coordinate (dum) at (0,0);

\foreach \t in {0,...,5}{
\begin{scope}[shift={(dum)}]

%%%%%%%%%% Draw to tower of height \t+1 %%%%%
\foreach \z in {0,...,\t}{
\foreach \x in {-\z,...,\z}{
\allumette{\t+\x}{\t+1-\z}{0} % Horizontal
\allumette{\t+\x}{\t-\z}{90}  % Vertical
}
\allumette{\t+\z+1}{\t-\z}{90} % Last one on the line
}
%%%%%%%%%% Draw to tower of height \t+1 %%%%%

%% The text under the tower
\pgfmathtruncatemacro\foo{\t+1}
\node[anchor=north] at (\t+.5,-.5) {\bfseries\foo{} \'etages};

%% Set the position of the next tower
\coordinate (dum) at (2*\t+2,0);
\end{scope}
}

\end{tikzpicture}

\end{document}


which gives

• Thanks. I vote for the other code because you say yourself that is great. ;-) Oct 8, 2019 at 20:35
• @projetmbc This answer is certainly no "worse" than the other one. Some users prefer macros, others pics. There are some arguments in favor of pics like the ability to use the pic actions and other pgf keys more easily but in this application non of that gets used at this point.
– user194703
Oct 8, 2019 at 20:50
• To be honest, if I could I would vote for the both answers. I let you decide if you want that I vote for the other code. :-) Oct 8, 2019 at 21:30
• @projetmbc It's fine like that, don't worry! :) Oct 9, 2019 at 9:28