View here.
A visualization of plant-like forms generated by Lindenmayer systems using the p5 library.
An L-System consists of a seed string and a set of production rules which expand a symbol into a longer string of symbols. By repeatedly applying the production rules, we can generate a longer and longer string, whose recursive nature leads to self-similarity and fractal-like forms when we interpret the result of this process as a sequence of instructions for a graphical "turtle."
Example (from Wikipedia):
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=0: A start (axiom)
/ \
n=1: A B the initial single A turns into AB by rule (A → AB)
/| \
n=2: A B A A turns AB again, B turns into A
/| | |\
n=3: A B A A B etc
/| | |\ |\ \
n=4: A B A A B A B A