PlantGL is an open-source graphic toolkit for the creation, simulation and analysis of 3D virtual plants.
In this tutorial, we will :
We need some packages to make this tutorial work.
import k3d
from openalea.plantgl.all import *
from oawidgets.plantgl import PlantGL
Let's build a Sphere object from PlantGL.
s=Sphere(radius=2)
Now, we display it with the oawidgets.PlantGL function.
PlantGL(s)
UGxvdChhbnRpYWxpYXM9MywgYXhlcz1bJ3gnLCAneScsICd6J10sIGJhY2tncm91bmRfY29sb3I9MTY3NzcyMTUsIGNhbWVyYT1bNC41LCA0LjUsIDQuNSwgMC4wLCAwLjAsIDAuMCwgMS4wLCDigKY=
Let's have a scene object in which we add a Sphere and a Box objects.
scene = Scene()
scene.add(Sphere())
b = Box()
tbox = Translated((1,0,0), b)
scene.add(tbox)
Now we visualize the scene.
PlantGL(scene)
UGxvdChhbnRpYWxpYXM9MywgYXhlcz1bJ3gnLCAneScsICd6J10sIGJhY2tncm91bmRfY29sb3I9MTY3NzcyMTUsIGNhbWVyYT1bNC41LCA0LjUsIDQuNSwgMC4wLCAwLjAsIDAuMCwgMS4wLCDigKY=
Let's import cool stuff !
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from random import randint
Let's define some functions.
def color():
return Material(ambient=Color3(randint(0,255), randint(0,255), randint(0,255)))
def buildSphere(n, rows=2):
"""Build n Spheres at different positions"""
s = Sphere()
scene = Scene()
for i in range(n):
si = Translated((2*(i%rows),2*(i//rows),0), s)
scene.add(Shape(si, color()))
return PlantGL(scene, group_by_color=True)
interact(buildSphere, n=widgets.IntSlider(min=1, max=100, step=1, value=10))
aW50ZXJhY3RpdmUoY2hpbGRyZW49KEludFNsaWRlcih2YWx1ZT0xMCwgZGVzY3JpcHRpb249dSduJywgbWluPTEpLCBJbnRTbGlkZXIodmFsdWU9MiwgZGVzY3JpcHRpb249dSdyb3dzJywgbWHigKY=
<function __main__.buildSphere>