The other day I was looking at implementations to the Hilbert Curve, and came across this concise and elegant recursive solution. I also came across the L-system, or Lindenmayer system. Lindenmayer, a biologist and botanist, developed the L-system to model the growth processes of plant development.
Wikipedia’s explanation of L-systems is succinct and clear:
An L-system consists of an alphabet of symbols that can be used to make strings, a collection of production rules that expand each symbol into some larger string of symbols, an initial "axiom" string from which to begin construction, and a mechanism for translating the generated strings into geometric structures.
A simple way to understand the L-system is to use Lindenmayer’s original L-system for modeling algae growth.
variables : A B
constants : none
axiom : A
rules : (A → AB), (B → A)
which produces:
n = 0 : A
n = 1 : AB
n = 2 : ABA
n = 3 : ABAAB
n = 4 : ABAABABA
n = 5 : ABAABABAABAAB
n = 6 : ABAABABAABAABABAABABA
n = 7 : ABAABABAABAABABAABABAABAABABAABAAB
The L-system is both simple and incredibly flexible. The L-system is a parallel rewriting system that isn’t opinionated about what the symbols mean or do. But what if we gave these symbols meaning? For example, we can use the L-system in graphics by mapping individual symbols in the model to drawing commands.
Consider the Hilbert Curve:
variables : A B
constants : none
axiom : A
rules : (A → LBFRAFARFBR), (B → RAFLBFBLFAR)
which produces:
n = 0 : A
n = 1 : LBFRAFARFBL
n = 2 : LRAFLBFBLFARFRLBFRAFARFBLFLBFRAFARFBLRFRAFLBFBLFARL
n = 3 : LRLBFRAFARFBLFLRAFLBFBLFARFRAFLBFBLFARLFLBFRAFARFBLRFRLRAFLBFBLFARFRLBFRAFARFBLFLBFRAFARFBLRFRAFLBFBLFARLFLRAFLBFBLFARFRLBFRAFARFBLFLBFRAFARFBLRFRAFLBFBLFARLRFRLBFRAFARFBLFLRAFLBFBLFARFRAFLBFBLFARLFLBFRAFARFBLRL
Now what if we mapped some of the symbols in the Hilbert L-system to drawing functions?
F → move forward
L → turn left 90°
R → turn right 90°
For various iterations (n=1 through n=4), we end up with the following patterns:
We can use this same process to generate various plant structures! None of the fractal plants presented here are novel. In fact, the production rules for these plants are well documented in Lindenmayer’s classic Algorithmic Beauty of Plants. The collage above is more or less the same as in page 25 of the same book, except that I generated my plants with higher iterations, and randomized the color for each stroke between two shades of green. I generated these using a rudimentary TypeScript implementation of L-system that I wrote and Canvas.
I don’t know how these plants should be named, so I’m just using the entire description of each one’s axiom, production rules, turn angle and iterations.