Tikz Fractal - Sierpinski Hexagon
I simply adapt Jake's Sierpinski triangle : How to create a Sierpinski triangle in LaTeX?
The output
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}
Just for fun, I've reproduced this fractal figure with MetaPost, thanks to a recursive macro.
vardef Sierpinski(expr A, B, n) =
save P; pair P[]; P0 = A; P1 = B;
for i = 1 upto 5:
P[i+1] = P[i-1] rotatedaround (P[i], 120);
endfor;
if n = 0: fill P0 for i = 1 upto 5: -- P[i] endfor -- cycle;
else:
for i = 0 step 2 until 4:
Sierpinski(P[i], 1/3[P[i],P[i+1]], n-1);
Sierpinski(2/3[P[i],P[i+1]], P[i+1], n-1);
endfor; fi
enddef;
beginfig(1);
for n = 0 upto 4:
draw image(Sierpinski(origin, (2cm, 0), n)) shifted (n*4.5cm, 0);
endfor;
endfig;
end.