Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

linsys

Lindenmayer systems in python.

Usage

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
...

Visualize

A turtle eats the generated string and its trace can be used to visualize it. See example.

Fractal Tree

About

Lindenmayer systems in python

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages