L-System

Posted on: August 2nd, 2016 by Peter Balazs No Comments

This week we’ll move on to the L-system which was named after Aristid Lindenmayer, who was a Hungarian theoretical biologist and botanist. He worked with yeast, fungi, algae and he used L-systems to describe the development of such simple, multicellular organisms.

Structure

The system is based on an alphabet of symbols that are used to create strings, a collection of rules that expand the symbols into larger strings, an axiom string which is the starting point of the construction, and a mechanism that translates the string into geometric structures.

His original modelling of the growth of algae looked like the following:
alphabet: A B
axiom: A
rules: (A becomes AB), (B becomes A)
‘n’ is the number of iterations.

The above produces these strings:
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 task at hand

For this little experiment – just as last week – we’re going to use P5.js which is really good JavaScript framework for (not exclusively) animation / drawing.
Our L-system looks like this:

alphabet: X F
constants: + − [ ]
axiom: X
rules: (X → F−[[X]+X]+F[+FX]−X), (F → FF)
angle: 25°
n: 6

How are we going to make a plant out of this? We’ll use turtle graphics. The turtle moves according to commands relative to his own position. By the way, he also carries a pen, and draws a line as he moves.

This is how we’re going to translate the rules / strings into turtle graphics:
F: draw forward
−: turn left 25°
+: turn right 25°
X: won’t do anything, it only helps the evolution of the strings
[: save the current values for position and angle
]: restore previously saved position and angle

And here is our plant constructed with the help of the L-system:

source: Wikipedia

Back to the lab