Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw some self similar fractals and highlight the first iteration. I was able to do so for the Sierpinski Triangle, although my code is somewhat ugly. (A minimal working example is included at the end of this post.)

But how to achieve similar results for the Sierpinski Carpet, Box Fractal, Cantor Dust, Koch curve and others? The googleable l-systems do help me, as they often only look similar to the fractal in high orders. For example: Can I use this Koch Curve l-system for my purpose?

As promised, finally the code:

\pgfdeclarelindenmayersystem{Sierpinski triangle}{
    \rule{X -> X-Y+X+Y-X}
    \rule{Y -> YY}

  \fill[black] (0,0) -- ++(0:\trianglewidth) -- ++(120:\trianglewidth) -- cycle;
  \path l-system
  [l-system={Sierpinski triangle, axiom=X, step=\trianglewidth/(2^\level), order=\level, angle=-120},fill=blue!25];
  \path l-system
  [l-system={Sierpinski triangle, axiom=X, step=\trianglewidth/(2^1), order=1, angle=-120},fill=white];

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.