Hi!
Here's my last code:
Import the library
from nodebox.graphics import *
#from lsystem import *
try:
# This is the statement you normally use.
lsystem = ximport("lsystem")
except:
# But since these examples are "inside" the library
# we may need to try something different when
# the library is not located in /Application Support
lsystem = ximport("init")
reload(lsystem)
Create a simple treelike pattern.
tree = lsystem.create()
tree.rules = {
"1" : "[-FF-FF1][+FF+FF1]"
}
Each F command depletes a little bit of time.
Calculate the total time we need to grow 6 generations.
done = tree.duration(5)
Our custom segment is a pinkish oval.
When we divide the current time at the segment by done,
we get a number between 0.0 and 1.0 we can use for coloring.
def segment(length, generations, time, id):
t = min(1.0, time/done)
fill(1-t*0.75, 0, 0.5, 0.6)
oval(-length/2, -length, length, length)
tree.segment = segment
Animate the growth of the tree using the FRAME count.
size(500, 250)
speed(20)
def draw(canvas):
time = min(FRAME*0.1, done)
tree.draw(250, 250, 5, time, ease=8)
canvas.run(draw)
And here are the errors listed in the console:
Traceback (most recent call last):
File "E:\workspace\Test2\src\test2.py", line 42, in <module>
canvas.run(draw)
File "E:\workspace\Test2\src\nodebox\graphics\context.py", line 3918, in run
pyglet.app.run()
File "E:\Python2732\lib\site-packages\pyglet\app_init_.py", line 264, in run
EventLoop().run()
File "E:\Python2732\lib\site-packages\pyglet\app\win32.py", line 63, in run
self._timer_func(0, 0, timer, 0)
File "E:\Python2732\lib\site-packages\pyglet\app\win32.py", line 84, in timer_func
sleep_time = self.idle()
File "E:\Python2732\lib\site-packages\pyglet\app_init.py", line 187, in idle
dt = clock.tick(True)
File "E:\Python2732\lib\site-packages\pyglet\clock.py", line 700, in tick
return _default.tick(poll)
File "E:\Python2732\lib\site-packages\pyglet\clock.py", line 303, in tick
item.func(ts - item.last_ts, *item.args, **item.kwargs)
File "E:\workspace\Test2\src\nodebox\graphics\context.py", line 3847, in draw
self.draw()
File "E:\workspace\Test2\src\test2.py", line 40, in draw
tree.draw(250, 250, 5, time, ease=8)
File "E:\workspace\Test2\src\lsystem_init.py", line 182, in draw
self.grow(generation, self.root, angle, self.d, time, draw=True)
File "E:\workspace\Test2\src\lsystem_init.py", line 131, in grow
draw
File "E:\workspace\Test2\src\lsystem_init.py", line 145, in _grow
self.segment(length, generation, None, id=self._segments)
File "E:\workspace\Test2\src\test2.py", line 28, in segment
t = min(1.0, time/done)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
What am I doing wrong? It is important for me to create LSystems, and why not, use the other clibraries you built for Nodebox 1 in Nodebox OpenGL.
By the, way, and also very important for me: can you export to PDF using Nodebox for OpenGL? I don't have a Mac so for me this is the option to use 'just code'.
I love your tools.