Contents

Drawing Fractal Snowflakes Using Lindenmayer Systems (L-Systems) in LaTeX TikZ

This article explores Lindenmayer Systems (L-Systems) fractal theory and LaTeX TikZ coding techniques to model 6-fold hexagonal ice crystal snowflakes.


In nature, snowflakes form as water vapor freezes around atmospheric particles, crystallizing into hexagonal molecular structures. Consequently, nearly all ice snowflakes exhibit 6-fold radial symmetry (6060^\circ rotation).

In computer science and fractal geometry, one of the most elegant methods for modeling self-similar branching structures is the Lindenmayer System (L-System), introduced by theoretical biologist Aristid Lindenmayer in 1968.

This article reviews a LaTeX TikZ implementation by Jose Luis Diaz (JLDiaz). By defining L-System string rewrite rules for a single snowflake “arm” using the lindenmayersystems library and rotating it 6 times (\foreach \a in {0,60,...,300}), we can render a vast gallery of precise, intricate crystal snowflakes.


A formal L-System is defined as a quintuple G=(V,Σ,ω,P)G = (V, \Sigma, \omega, P):

  • VV (Variable Alphabet): Symbols replaced during string rewriting (e.g., F, G, H). In TikZ graphics, F commands the turtle/pen to move forward and draw a line segment of length step.
  • Σ\Sigma (Constant Alphabet): Turtle control symbols:
    • + : Turn left by angle.
    • - : Turn right by angle.
    • [ : Push current position and heading onto the state stack.
    • ] : Pop position and heading from the stack (used for branching).
  • ω\omega (Axiom / Initial State): The starting string prior to recursion (e.g., axiom=F).
  • PP (Production Rules): Rewrite rules replacing variables with new strings at each recursion level (order).

Here is the complete TikZ code by Jose Luis Diaz to compute multiple snowflake variations:

% Snowflakes with TikZ
% Author: Jose Luis Diaz (JLDiaz)
\documentclass{article}
\usepackage[textwidth=6cm]{geometry}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}%
\usetikzlibrary{lindenmayersystems}

% -------------------------------------------------------------
% L-System Rule Declarations for Snowflake Arms
% -------------------------------------------------------------
\pgfdeclarelindenmayersystem{A}{
  \rule{F -> FF[+F][-F]}
}

\pgfdeclarelindenmayersystem{B}{
  \rule{F -> ffF[++FF][--FF]}
}

\pgfdeclarelindenmayersystem{C}{
  \symbol{G}{\pgflsystemdrawforward}
  \rule{F -> F[+F][-F]FG[+F][-F]FG}
}

\pgfdeclarelindenmayersystem{D}{
  \symbol{G}{\pgflsystemdrawforward}
  \symbol{H}{\pgflsystemdrawforward}
  \rule{F -> H[+HG][-HG]G}
  \rule{G -> HF}
}

% Default Style Configuration
\tikzset{
  type/.style={
    l-system={#1, axiom=F, order=3, step=4pt, angle=60},
    blue, opacity=0.4, line width=.5mm, line cap=round
  },
}

% Macro to Draw a Complete Snowflake (6-Fold Radial Symmetry)
\newcommand\drawsnowflake[2][scale=0.2]{
  \tikz[#1] \foreach \a in {0,60,...,300} {
    \draw[rotate=\a,#2] l-system;
  };
}

\begin{document}
\begin{center}

  % System A Variations Across Line Widths
  \foreach \width in {.2,.4,...,.8} {
    \drawsnowflake[scale=0.3]{type=A, line width=\width mm}
  }

  % System A Variations with 90-Degree Branch Angle
  \foreach \width in {.2,.4,...,.8} {
    \drawsnowflake[scale=0.38]{type=A, l-system={angle=90}, line width=\width mm}
  }

  % System B Variations
  \foreach \width in {.2,.4,...,.8} {
    \drawsnowflake[scale=0.3]{type=B, line width=\width mm}
  }

  \foreach \width in {.2,.4,...,.8} {
    \drawsnowflake{type=B, l-system={angle=30}, line width=\width mm}
  }

  % Systems C & D with Custom Axioms
  \drawsnowflake[scale=0.24]{type=C, l-system={order=2}, line width=0.2mm}
  \drawsnowflake[scale=0.25]{type=C, l-system={order=2}, line width=0.4mm}
  \drawsnowflake[scale=0.25]{type=C, l-system={order=2,axiom=fF}, line width=0.2mm}
  \drawsnowflake[scale=0.32]{type=C, l-system={order=2,axiom=---fff+++F}, line width=0.2mm}

  \drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=GF}, line width=0.7mm}
  \drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=GfF}, line width=0.7mm}
  \drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=FG}, line width=0.7mm}
  \drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=FfG}, line width=0.7mm}

\end{center}
\end{document}

Compiling the code generates a diverse gallery of snowflake crystals:

Snowflakes TikZ
Snowflakes L-Systems TikZ Output


TikZ’s built-in \usetikzlibrary{lindenmayersystems} provides native string-rewriting capabilities without requiring custom recursive TeX routines.

Looking at System A:

\pgfdeclarelindenmayersystem{A}{
  \rule{F -> FF[+F][-F]}
}
  • At order=1, F becomes FF[+F][-F].
  • At order=2, each F in the expanded string is recursively rewritten again.
  • Square brackets [+F] and [-F] branch off to the left and right, then restore the turtle position back to the stem.

The complete snowflake is assembled inside \drawsnowflake:

\newcommand\drawsnowflake[2][scale=0.2]{
  \tikz[#1] \foreach \a in {0,60,...,300} {
    \draw[rotate=\a,#2] l-system;
  };
}

Loop \foreach \a in {0,60,...,300} duplicates and rotates 1 L-system branch across angles 0,60,120,180,240,0^\circ, 60^\circ, 120^\circ, 180^\circ, 240^\circ, and 300300^\circ.


Try these modifications to create new snowflake geometries:

  1. Varying Branch Angles (angle): Set angle=45 to generate 8-fold symmetric snowflakes with \foreach \a in {0,45,...,315}.
  2. Recursion Depth (order): Increase order=3 to order=4 or order=5 for denser, more intricate crystal filigree.
  3. Custom Color Gradients: Change blue, opacity=0.4 to cyan!80!black or add glow effects for an icy aesthetic.

Jose Luis Diaz’s TikZ code demonstrates how Lindenmayer Systems combined with radial rotational symmetry offer an efficient framework for algorithmic botanical and crystalline modeling in LaTeX.


  1. Jose Luis Diaz, Snowflakes with TikZ, TeXample.net
  2. Przemyslaw Prusinkiewicz & Aristid Lindenmayer, The Algorithmic Beauty of Plants, Springer-Verlag, 1990.
  3. Till Tantau, The TikZ and PGF Manual, v3.1.10, 2024.

Written by: Aan Triono
License: CC BY-SA 4.0

Related Content