Recursive Growth and the Parallel Rewrite
In 1968, Hungarian biologist Aristid Lindenmayer wanted a formal way to model how multicellular organisms grow at the cellular level, particularly algae whose development follows strict branching rules. He devised a grammar where every symbol in a string rewrites simultaneously in parallel, mimicking how cells divide in concert rather than one at a time. An axiom like "F" with the rule F → F[+F]F[-F][F] expands into a longer string each generation, and after a few iterations the result encodes a branching tree structure. The difference between this and a Chomsky grammar is that all replacements happen at once, which prevents sequential bias and captures the simultaneity of biological growth. By the 1980s, computer graphics researchers realized that these string expansions could drive turtle graphics interpreters to draw plants, fractals, and organic forms, moving L-systems from theoretical biology into generative art.
The implementation here uses seven presets that span the range from botanical models to pure geometry. The fractal tree and fern use small angles and depth-limited recursion to produce realistic branching, with the fern incorporating an extra non-terminal symbol X that controls structural recursion without drawing. The Koch snowflake and Sierpinski triangle are deterministic space-filling curves that tile perfectly at specific angle values. The dragon curve produces a path that folds in on itself with 90-degree turns, and the Hilbert curve traces a continuous path through two-dimensional space. Each preset has a maximum depth to prevent exponential blowup, because string length doubles or triples with each iteration depending on the rules. The renderer counts F commands in the expanded string and draws them progressively during the growth animation, which gives the visual effect of watching the structure unfold over time rather than appearing all at once.
for (const ch of s) {
n += rules[ch] || ch;
}
s = n;
Rendering uses turtle graphics with a stack to handle branching. When the interpreter hits an F, it draws a line segment in the current direction and advances the position. The plus and minus symbols rotate the heading by the current angle parameter, which you can adjust with keyboard arrows or the control panel. Brackets push and pop state from a stack, so an open bracket saves the current position and angle, the turtle explores a branch, and the close bracket restores the previous state to start a new branch from the same fork point. The color shifts as the structure grows, mapping each segment's position in the sequence to a hue range defined by the palette. Ice uses low saturation blues, autumn shifts through warm tones, and rainbow cycles the full spectrum. The jitter multiplier adds slight randomness to both segment length and angle, which breaks the rigidity of pure geometry and makes organic presets like the fern feel more natural.
What stands out is how compact the rules are compared to the complexity they generate. The bush preset has a single rule with four branching operations, and after four iterations it produces hundreds of line segments arranged in a recognizable shrub shape. The Hilbert curve uses two mutually recursive symbols that interleave at right angles, producing a fractal path that fills a square more densely with each depth increase. Clicking the canvas reseeds the random jitter and triggers regrowth, so you can explore variations on the same structure without changing the underlying grammar. The auto-scaling computes a bounding box by simulating the turtle path without drawing, then fits the result to the viewport with uniform scaling and centered offset. This keeps every preset visible regardless of window size or aspect ratio, and it lets you increase depth without worrying about the structure growing off-screen. The combination of deterministic rules and stochastic rendering parameters creates output that feels both structured and alive, which tracks with Lindenmayer's original goal of capturing biological development through formal computation.
Links. Visualization · Gallery Index · L-systems background · The Algorithmic Beauty of Plants
← Back to main page