L-Systems & Procedural Plants: Grammar Theory to 3D Trees
In 1968 biologist Aristid Lindenmayer invented a string-rewriting formalism to model the growth of algae. That same mathematical framework β now called an L-system β underlies the procedurally generated trees in The Witcher 3, the fractal ferns of early computer art, and sophisticated plant-growth models used in botany research today.
1. String Rewriting: the Core Idea
An L-system (Lindenmayer system) is a formal grammar defined by three components:
- Alphabet V: a finite set of symbols (e.g., {F, +, β, [, ]})
- Axiom Ο: the initial string (e.g., "F")
- Production rules P: substitution rules applied simultaneously to every symbol in the current string
At each generation step, every symbol in the string is simultaneously replaced by its production. This parallel rewriting is what distinguishes L-systems from regular grammars (which rewrite one symbol at a time) and why they capture self-similar biological growth so naturally.
The Fibonacci sequence emerges naturally from a two-symbol L-system illustrating how simple rewriting rules produce rich mathematical structure. The branching counts in plant phyllotaxis (the spiral packing of seeds in a sunflower head, scales on a pine cone) follow the same sequence β L-systems provide a mechanistic explanation for why.
2. Turtle Graphics Interpretation
A string of symbols is just text until we assign it geometric meaning. Turtle graphics provides that mapping: imagine a turtle holding a pen, carrying a position and heading. Symbols command the turtle's movement:
The stack bracket symbols [ and ] are what
enable branching: push the turtle state before going down a branch,
then pop it to return to the branch point and continue. Every plant's
fork is a [β¦] sub-string.
3. Classic DOL-System Examples
A DOL-system (Deterministic, context-free, 0-predecessor) is the simplest class: each symbol has exactly one rewrite rule and no context is checked. Most fractal plant illustrations use DOL-systems.
Koch Snowflake
Dragon Curve
Bush / Tree Form
Barnsley Fern (via IFS β analogous spirit)
The Barnsley fern is generated by an Iterated Function System rather than a strict L-system, but captures the same idea of self-similar replacement. An L-system equivalent uses 4 rules to produce frond, leaflet, and petiole structures at different scales.
4. Stochastic L-Systems for Natural Variation
Deterministic L-systems produce geometrically perfect, too-regular structures β trees that look stamped from a mould. Real plants have variation: slightly different branch angles, unequal branch lengths, asymmetric crowns. Stochastic L-systems assign probabilities to competing rules for the same symbol:
The results look remarkably biological. Each call to generate with a different random seed produces a unique tree, yet all instances share the same overall size, branching density, and character β exactly as conspecific trees in a forest resemble each other without being identical.
For reproducible procedural content in games, the random seed is stored per-object. Given the same seed and grammar, the same tree is always regenerated without storing the full geometry β saving significant memory for large forests.
5. Context-Sensitive L-Systems
In a context-sensitive L-system (IL-system or 2L-system), a symbol's rewriting may depend on its neighbours in the string. This models inter-cell signalling β information propagating through a biological structure:
Context-sensitive rules let the grammar model:
- Hormone flow along a stem (signal propagates from apex downward)
- Nutrient uptake (resource depletion modelled as a value passing through the string)
- Dorsiventral leaf differentiation (upper vs lower surface cells react differently based on position)
These biologically motivated models bridge pure mathematics and plant physiology, and were central to Lindenmayer's original research goals.
6. Parametric L-Systems
In parametric L-systems, each symbol carries numeric parameters, and production rules are conditional on those parameters. This enables continuous plant growth models where branch lengths and angles change with age:
This models apical dominance β the tip of a plant branch growing vigorously while lateral branches weaken. A secondary production could reduce the parameter of subordinate branches, naturally producing the conical crown shape of fir trees.
Prusinkiewicz and Lindenmayer's 1990 book The Algorithmic Beauty of Plants (freely available online) catalogs dozens of parametric L-systems matching measured botanical data. It remains the definitive reference for the field.
7. 3D Plant Generation
Extending from 2D turtle to 3D requires tracking a full 3D orientation frame. The turtle carries three orthogonal vectors: H (heading), L (left), and U (up). Rotation commands apply rotation matrices to this frame:
Tropism β the bending of growth toward or away from a stimulus β is modelled by a small rotation correction applied at every branch segment. A heavy branch sags under gravity (negative geotropism: e Γ gravity_vector); a leaf petiole twists toward the sun (phototropism).
Geometry Output and Instancing
For real-time rendering, the turtle's segments are not drawn as individual line primitives but grouped into meshes:
-
Branch cylinders: Each
Fcommand produces a cylinder. Radius tapers with depth:r(depth) = r_trunk Γ (2/3)^depth(pipe model β cross-sectional area is conserved across branches). -
Leaf billboards: Terminal
Lsymbols emit camera-facing quad billboards with leaf texture. LOD reduces leaf count at distance. - Instanced rendering: Large forests use GPU instancing β render one tree mesh N times with different transform matrices, reducing draw calls from N to 1.
- Level of Detail (LOD): Near trees use full L-system geometry (5β6 generations). Far trees switch to impostors (pre-rendered sprites viewed from 8 angles).
8. Applications in Games & Visualisation
L-systems are a staple of procedural content generation (PCG) in games and visualisation software:
- SpeedTree (Interactive Data Visualization): The industry-standard middleware used in Ghost of Tsushima, The Last of Us Part II, and many others. Uses parametric L-system-style rules combined with artist-controlled hand-tuning and wind simulation.
- Houdini (SideFX): Its "L-System" node is a first-class geometry operator. Artists and TDs specify grammar rules in the node parameters and get real-time 3D geometry updates. Used for forest scenes in film VFX.
- Blender (add-on "Sapling"): Generates branch skeletons from parametric rules, then applies skin/subdivision modifiers for smooth geometry.
- Botany research: The Virtual Laboratory (vlab) at the University of Calgary creates quantitative plant models that match measured growth data β used to study crop architecture and canopy light interception.
- Architecture: Procedural faΓ§ade generation, branching corridor layouts, and organic structural forms use grammar-based generation analogous to L-systems.
The deeper lesson of L-systems is that complex, apparently designed structure can arise from very simple local rules applied iteratively. This resonates far beyond botany: similar pattern-forming mechanisms appear in animal coat patterns (reaction-diffusion), urban street networks, river tributaries, and lung bronchial trees β all exhibiting statistical self-similarity well described by variants of the same rewriting framework.