[Tex/LaTex] Tikz Fractal – Sierpinski Hexagon

diagramsfractalslindenmayertikz-pgf

Yet another attempt at a Fractal construction. This time I am trying to draw the Sierpinski Hexagon:

enter image description here

I think this should be easy enough to do using l-system. My question is a slightly broader one than just how to draw this I suppose.

How do I define an l-system to use hexagons instead of squares or triangles?

Best Answer

I simply adapt Jake's Sierpinski triangle : How to create a Sierpinski triangle in LaTeX?

The output

enter image description here

The code

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{lindenmayersystems}

\begin{document}%
\def\hexagwidth{2cm}%
\pgfdeclarelindenmayersystem{Sierpinski hexagon}{
  \symbol{X}{\pgflsystemdrawforward}
    \symbol{Y}{\pgflsystemmoveforward\pgflsystemmoveforward\pgflsystemmoveforward}
    \rule{X -> X+X+X+X+X+X+Y}
    \rule{Y -> YYY}
}%
\foreach \level in {1,...,4}{%
\tikzset{
    l-system={step=\hexagwidth/3^\level, order=\level, angle=60}
}%
\begin{tikzpicture}
  \fill (0,0) l-system [l-system={Sierpinski hexagon, axiom=X}] ;
\end{tikzpicture}
}%
\end{document}