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.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI 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 pic
s 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}
\the\numexpr\Z+1
which is probably way better than \pgfmathtruncatemacro
! :D
pics
is a TiKz mechanism to define "graphical" ?
Oct 8, 2019 at 20:39
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}
pic actions
and other pgf keys more easily but in this application non of that gets used at this point.