How can I use the old nodebox libraries (like L-System) in Nodebox for OpenGL?

kenzenichinyokiai's Avatar


01 Nov, 2013 07:39 PM

I tried ximport, but it doesn't work in NB OpenGL, right? I also tried to copy the LSystem class into my code and then build an L-System object using the example code provided but it didn't work. ('tree = lsystem.create()' and 'tree =LSystem.create()')

Sorry if the question is too 'newbish', I'm not an experienced programmer and hadn't tried doing anything in Python before.


  1. 1 Posted by kenzenichinyoki... on 05 Nov, 2013 06:45 PM

    kenzenichinyokiai's Avatar


    Here's my last code:

    # Import the library
    from import *
    #from lsystem import *
        # This is the statement you normally use.
        lsystem = ximport("lsystem")
        # 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__")

    # 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)
    def draw(canvas):
        time = min(FRAME*0.1, done)
        tree.draw(250, 250, 5, time, ease=8)

    And here are the errors listed in the console:

    Traceback (most recent call last):
      File "E:\workspace\Test2\src\", line 42, in <module>
      File "E:\workspace\Test2\src\nodebox\graphics\", line 3918, in run
      File "E:\Python2732\lib\site-packages\pyglet\app\", line 264, in run
      File "E:\Python2732\lib\site-packages\pyglet\app\", line 63, in run
        self._timer_func(0, 0, timer, 0)
      File "E:\Python2732\lib\site-packages\pyglet\app\", line 84, in _timer_func
        sleep_time = self.idle()
      File "E:\Python2732\lib\site-packages\pyglet\app\", line 187, in idle
        dt = clock.tick(True)
      File "E:\Python2732\lib\site-packages\pyglet\", line 700, in tick
        return _default.tick(poll)
      File "E:\Python2732\lib\site-packages\pyglet\", line 303, in tick
        item.func(ts - item.last_ts, *item.args, **item.kwargs)
      File "E:\workspace\Test2\src\nodebox\graphics\", line 3847, in _draw
      File "E:\workspace\Test2\src\", line 40, in draw
        tree.draw(250, 250, 5, time, ease=8)
      File "E:\workspace\Test2\src\lsystem\", line 182, in draw
        self._grow(generation, self.root, angle, self.d, time, draw=True)
      File "E:\workspace\Test2\src\lsystem\", line 131, in _grow
      File "E:\workspace\Test2\src\lsystem\", line 145, in _grow
        self.segment(length, generation, None, id=self._segments)
      File "E:\workspace\Test2\src\", 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.

  2. Support Staff 2 Posted by tomdesmedt on 04 Dec, 2013 12:17 AM

    tomdesmedt's Avatar

    Old libraries from NodeBox 1 that "draw stuff" can't be used in NOGL, since the drawing operations are very specific to NB1. Nevertheless, NOGL ported a lot of code from the libraries (e.g., boids, colors, ...) but unfortunately not L-systems.

    You could look at the source code of the L-systems library, and replace the drawing commands (they start with "_ctx") with NOGL commands. Here is a simple L-system in Javascript which should not be hard to convert to Python code:

    NOGL does not have support for PDF, since it draws pixels for speed and not vectors. So chances are pretty slim it will ever support PDF. There is always a trade-off: either it is fast (=graphics card accelerated, pixels) or either it is slower but scalable (vector curves, PDF).


Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

31 Jan, 2023 11:29 PM
28 Jan, 2023 10:39 AM
26 Jan, 2023 01:30 AM
26 Jan, 2023 01:24 AM
26 Jan, 2023 12:48 AM


20 Jan, 2023 02:32 PM
13 Jan, 2023 09:54 PM
11 Jan, 2023 10:32 AM
09 Jan, 2023 11:45 AM
28 Dec, 2022 11:19 PM
27 Dec, 2022 06:57 AM