Skip to content

Instantly share code, notes, and snippets.

@pradal
Created March 4, 2018 12:53
Show Gist options
  • Save pradal/78dbc7181f1c269b62b19b8a52edb59a to your computer and use it in GitHub Desktop.
Save pradal/78dbc7181f1c269b62b19b8a52edb59a to your computer and use it in GitHub Desktop.
Running L-Py without GUI
Axiom: A(1)
production:
derivation length: 6
A(n) :
produce F(1)[+(30.)A(n+1)] [-(30.)A(n+1)]F(0.2);(3)@o(0.2)
endlsystem
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""A script that run lpy without the GUI.
The script will showcase different stages:
- Load a lpy simulation program.
- Iterate several times (defined by derivation length)
- Generate the 3D representation
To install it, please create a conda environment (Python 2 is manatory)::
conda create -n lpy -c openalea openalea.lpy
To run the script, launch ipython with qt
ipython
%gui qt
"""
# Import lpy library
from openalea.lpy import *
from openalea.plantgl.all import Viewer
# Create the simulation object from a given file
lsys = Lsystem("example.lpy")
n = lsys.derivationLength
tree = lsys.axiom
for i in range(n):
# Apply rewritting rules on the tree -> One step of simulation
tree = lsys.iterate(tree, 1)
print(tree)
# COmpute the scene interpretation
# That is apply geometric rules to retrieve the 3D plant
scene = lsys.sceneInterpretation(tree)
# Display or save in a given format the scene
Viewer.display(scene)
# if it goes too fast, you can sleep or ask user to give an input
#raw_input('next?')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment