Package for generating and rendering Lsystems
Project description
Lsystem generator python lib
Current version: 1.0
This package enable to generate Lsystem representation by providing:
- Axioms (e.g. : "F")
- Rules of generation (e.g. F -> F+F--F+F)
- Generation (e.g. 2 for the second generation)
- Rules of display (using the turtle analogy)
Installation
pip install lsystem-generator==1.0
Usage
from lsystem.lsys_generator import Lsystem
if __name__=="__main__":
lsys = Lsystem("F",("F", "F-Y-F"), ("Y", "Y+F+Y"))
lsys.generate(2)
image = lsys.render(("+",80), ("-",-80))
image.show()
lsys.generate(5)
image = lsys.render(("+",60), ("-",-60))
image.show()
note fore the user: after declaring a Lsystem, multiple generation generate()
can be created and different representation can be obtained render()
help(Lsystem)
gives a detailed documentation on how to create Lsystems, generate and render image representations
Performance limits
The programm is performing at generate lsystem in the first 10-15 generation, depending on the lenght of the rule for generation and the number of axioms and rules. At generation n+1 the lenght of the generated sequence will be:
l_1 = number of axioms in sequence_n * lenght of the rule for generation for each axiom + characters that are not axioms in the sequence_n
= sum(number of axiom i in sequence_n * lenght of the rule i for this axiom) + (lenght of the sequence - sum(number of axiom i in sequence_n))
= sum((l / l_rule_i * occ_a_i) * l_rule_i) + (l - sum(l / l_rule_i * occ_a_i) )
with:
l
: lenght of the sequence at generation nl+1
: lenght of the sequence at generation nl_rule_i
: lenght of the rule i for generationocc_a_i
: number of occurences of the axiom i in the rule i for generationi
: index of the pair (axiom, rule) defined in the Lsystem
The RAM available will depend on the system and the python installation you are running the lib with, the maximum string length that can be generated and thus the number of generation that can be produced will vary. If higher generation needs to be produced, a different implementation would be required.
Development
After downloading the sources run pip install -e .
We recommand using a virtulanv to install pip dependencies
Running unit test (in development mode)
To run the tests execute from the root folder:
pytest --testdox
if you encounter import difficulites, make sure the root directory, lsystem and tests dir are in the $PYTHONPATH. Run source .env
to add them
License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for lsystem_generator-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e996e16f233e52b6efa416cb3d40763bbc23278f6152c62185cb3b5b6a913e7 |
|
MD5 | d81961b121e293de1b83e4e48b194aa1 |
|
BLAKE2b-256 | 39e686dc15986e19992060cf885602a60ab4afb80eaae60c6ee430d2641698e1 |