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
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to run lpy without the GUI?\n",
"\n",
"The script will showcase different stages:\n",
" - Load a lpy simulation program.\n",
" - Iterate several times (defined by derivation length)\n",
" - Generate the 3D representation\n",
"\n",
"\n",
"## Installation\n",
"To install it, please create a conda environment (Python 2 is manatory)::\n",
"\n",
" conda create -n lpy -c openalea openalea.lpy\n",
"\n",
"To run the script in a shell, launch ipython with qt\n",
"\n",
"%gui qt\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"%gui qt\n",
"\n",
"# Import lpy library\n",
"from openalea.lpy import *\n",
"from openalea.plantgl.all import Viewer\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('Lstring: ', AxialTree(F(1)[+(30)A(2)][-(30)A(2)]F(0.2);(3)@o(0.2)))\n",
"('Lstring: ', AxialTree(F(1)[+(30)F(1)[+(30)A(3)][-(30)A(3)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(3)][-(30)A(3)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)))\n",
"('Lstring: ', AxialTree(F(1)[+(30)F(1)[+(30)F(1)[+(30)A(4)][-(30)A(4)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(4)][-(30)A(4)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(4)][-(30)A(4)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(4)][-(30)A(4)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)))\n",
"('Lstring: ', AxialTree(F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(5)][-(30)A(5)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)))\n",
"('Lstring: ', AxialTree(F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(6)][-(30)A(6)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)))\n",
"('Lstring: ', AxialTree(F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)][-(30)F(1)[+(30)A(7)][-(30)A(7)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)]F(0.2);(3)@o(0.2)))\n"
]
}
],
"source": [
"# Create the simulation object from a given file\n",
"lsys = Lsystem(\"example.lpy\")\n",
"\n",
"n = lsys.derivationLength\n",
"tree = lsys.axiom\n",
"for i in range(n):\n",
" # Apply rewritting rules on the tree -> One step of simulation\n",
" tree = lsys.iterate(tree, 1)\n",
" print('Lstring: ', tree)\n",
"\n",
" # COmpute the scene interpretation\n",
" # That is apply geometric rules to retrieve the 3D plant\n",
" scene = lsys.sceneInterpretation(tree)\n",
"\n",
" # Display or save in a given format the scene\n",
" Viewer.display(scene)\n",
" # if it goes too fast, you can sleep or ask user to give an input\n",
" #raw_input('next?')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "IPython (Python 2)",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"""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