A Lindenmayer system implementation written in C++ using opengl
The recursive nature of the L-system rules leads to self-similarity and thereby, fractal-like forms are easy to describe with an L-system. Plant models and natural-looking organic forms are easy to define, as by increasing the recursion level the form slowly 'grows' and becomes more complex. Lindenmayer systems are also popular in the generation of artificial life. The rules of the L-system grammar are applied iteratively starting from the initial state. As many rules as possible are applied simultaneously, per iteration. The fact that each iteration employs as many rules as possible differentiates an L-system from a formal language generated by a formal grammar, which applies only one rule per iteration. If the production rules were to be applied only one at a time, one would quite simply generate a language, rather than an L-system. Thus, L-systems are strict subsets of languages.
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
We followed two different approaches for constructing L-system based graphics.
Similar to the above example, each vaariable is recursively grown in each generation as per the given rule.
variables : A
constants : B
axiom : A
rules : (A → A[BA]A), (B → B)
which produces:
n = 0 : A
n = 1 : A[BA]A
n = 2 : A[BA][BA[BA]]A[BA]A
n = 3 : A[BA][BA[BA]][BA[BA][BA[BA]]]A[BA]A[BA[BA]A]A[BA]A
Only the variables inside a subbranch are grown further. Variables in the main branch are not grown
variables : A
constants : B
axiom : A
rules : (A → A[BA]A), (B → B)
which produces:
n = 0 : A
n = 1 : A[BA]A
n = 2 : A[BA[BA]]A
n = 3 : A[BA[BA][BA[BA]]]A