Lindenmayer systems in python.
Specify an L-system by its production rules
>>> algae = Lsys({'A': 'AB'})
Alphabet consisting of both variables and constants is inferred from the rules.
>>> algae.variables() == {'A'}
True
>>> algae.constants() == {'B'}
True
>>> algae.alphabet() == {'A', 'B'}
True
Apply the (for now) single rule
>>> algae('A')
'AB'
Add another production rule
>>> algae['B'] = 'A'
>>> algae.variables() == {'A', 'B'}
True
Apply the production rules to some string
>>> algae('AB')
'ABA'
Or iterate over the applications of rules
for i, state in enumerate(algae.iter('A')):
print(i, state)
yielding
0 A
1 AB
2 ABA
3 ABAAB
4 ABAABABA
5 ABAABABAABAAB
6 ABAABABAABAABABAABABA
7 ABAABABAABAABABAABABAABAABABAABAAB
...
A turtle eats the generated string and its trace can be used to visualize it. See example.