Rewriting (L-systems)
The text is rewritten several times, then each letter becomes a stroke or a turn.
The rule
An L-system starts from a string of letters, called the axiom, and a rule that says what to replace each letter with. The rule is applied to all the letters at once, then again on the result. Each round is a generation.
F → F-F++F-F
Then a turtle reads the string. F means: move forward, drawing a line. + turns left by a fixed angle, - turns right by the same angle. The square brackets [ and ] put the position aside, then bring it back: that is what makes branches. The other letters, like X, draw nothing, they only serve the rewriting.
Here the axiom is F++F++F, a triangle, and the angle is 60°. At each generation, every line is replaced by four smaller lines. The text grows very fast, but the drawing keeps the same look.
Your turn
Pick a rule, then raise the generations one by one. The string appears next to the drawing: when it gets too long, only its beginning is shown, with its real length just below. The turtle walks along it, and the drawing is reframed at each generation to fit the frame.
The dragon and the plant have their own limit of generations, so that the page stays smooth.
Rewritten string
F++F++F
7 characters
F → F-F++F-F
The drawing above is a teaching sketch, not the artwork: it shows the rule, it does not replay the colours, the size of the dots or the grain of the print.
What changes from one algorithm to the next
Almost everything is in the data: the axiom, the rule and the angle. The engine that reads the string is the same for almost all of them.
- Dragon Curve
- Heighway's dragon: a strip of paper folded in half again and again, then unfolded at right angles. The artwork does not write a rewriting rule: it builds the sequence of turns, left or right, directly, by paper folding. The sketch above goes through a rule, which is simpler to show.
- Terdragon
- The ternary dragon, drawn in a single stroke. The rule is F → F+F-F, with 120° turns.
- Lévy C Curve
- Lévy's C curve. Each line is replaced by two lines at a right angle: F → +F--F+, with 45° turns.
- Koch Snowflake
- The Koch snowflake: a triangle (F++F++F) whose every side bristles according to F → F-F++F-F, with 60° turns. The curve is closed.
- Quadratic Koch Curve
- The right-angle variant: F → F+F-F-F+F, with 90° turns. Each line becomes a battlement. Unlike the snowflake, the curve is open.
- Sierpiński Arrowhead Curve
- Sierpiński's arrowhead: a single stroke that ends up drawing the Sierpiński triangle. Two letters, F and G, both draw: F → G-F-G and G → F+G+F, with 60° turns.
- Sierpiński (L-System)
- The Sierpiński triangle, obtained another way: the axiom is F-G-G, the rules are F → F-G+F+G-F and G → GG, with 120° turns.
- Gosper Snowflake
- The Gosper snowflake, or flowsnake: a hexagonal curve that fills space. Two letters draw, F → F-G--G+F++FF+G- and G → +F-GG--G-F++F+G, with 60° turns.
- Hilbert Curve
- The Hilbert curve, which fills the square. The letters X and Y do not draw, they only serve the rewriting: X → +YF-XFX-FY+ and Y → -XF+YFY+FX-, with 90° turns.
- Peano Curve
- The Peano curve, another curve that fills the square. The string is multiplied by nine at each generation, against four for Hilbert: so it cannot go as high. 90° turns, rules written with X and Y.
- Moore Curve
- The Moore curve, the closed version of Hilbert: the axiom LFL+F+LFL puts four pieces of Hilbert together in a loop. The letters L and R do not draw, 90° turns.
- Fractal Plant
- Lindenmayer's plant, the only one in the family with branches: the square brackets [ and ] put the position aside. X → F+[[X]-X]-F[-FX]+X and F → FF, with 25° turns. It is also the only one whose angle can be slightly drawn at random at each turn.
What chance decides
For each artwork, the program draws these settings at random, between bounds set in advance.
- Number of rewrites Dragon Curve from 11 to 16
- Turning angle (°) Dragon Curve from 88 to 92
- Angle (°) Koch Snowflake from 58 to 62
The algorithms in this family
- Dragon Curve
- Terdragon
- Lévy C Curve
- Koch Snowflake
- Quadratic Koch Curve
- Sierpiński Arrowhead Curve
- Sierpiński (L-System)
- Gosper Snowflake
- Hilbert Curve
- Peano Curve
- Moore Curve
- Fractal Plant