1

This question already has an answer here:

I am trying to draw a fractal in tikz that is not a 'common' one - so I'm a little stuck.

It is essentially the Sierpinski Casket but with a square instead of a triangle. Start with the (solid) unit square, remove the centre 9-th, and repeat with the remaining 8 squares. So you end up with 8^k squares of size 1/9^k.

I'd like it to look something like:enter image description here

Preferably the 'last' image will be of stage 5 or 6 but, if possible, a nice definable end stage would be great (like other fractals in LaTeX).

marked as duplicate by cfr tikz-pgf Jun 11 '17 at 4:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6

Use the lindenmayersystems of TikZ.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\begin{tikzpicture}[l-system={step=1pt, order=5, angle=90}]
  \pgfdeclarelindenmayersystem{Sierpinski carpet}{
    \rule{F -> F+F-F-FF-F-F-fF}
    \rule{f -> fff}
  }
  \draw l-system [l-system={Sierpinski carpet, axiom=F}];
\end{tikzpicture}
\end{document}

enter image description here

  • Wow, every day I find out a new gorgeous feature of tikz! – CarLaTeX Jun 11 '17 at 5:29

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