The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

NodeBox 1ArchiveFrom the old forum

How does Shoebot 1 decide to render a single image or run an animation ?

6 replies Last reply

  1. How does Nodebox 1 decide whether a bot is an animation or a still image.

    In our Shoebot, I think we toggle on whether there is a "draw" function, but I've seen other info that it might be calling speed() with a number > 0 that enables it.

    This should help me remove some of the less sane code in Shoebot :)

    Copy link
  2. In file console.py, in class NodeboxRunner method _check_animation() is self-explanatory.

    See also usages of this method.

    Copy link
  3. Ah, great - I was thinking that having speed with a default of None might be a way of implementing this.

    Reassuring to see I was thinking along similar lines.

    This is definitely enough to write some unit tests for Shoebot so our implementation is compatible.

    Copy link
  4. While you're here: the canvas vs context distinction always confused me, is it that the graphics "context" is the current state, of graphics, while canvas is the thing it paints on ?

    Copy link
  5. Hey, I only keep it alive ;-) and write some new stuff; occasionally.

    ...graphics "context" is the current state

    Yes. It's in nodebox/graphics/init.py and should be adaptable to Shoe with minimal changes

    ...while canvas is the thing it paints on...
    Yes. And it has connections to the Cocoa framework

    If you look in my fork here

    https://github.com/karstenw/nodebox-pyobjc/blob/7dbbb1d3d1263d9a08faf22e11910bd5f9b4a817/nodebox/graphics/cocoa.py#L15

    you'l see all the Cocoa functions that are used.

    Copy link
  6. Thanks.

    I'll probably implement the same logic, but with tests, the code is pretty different + I'm working to gradually remove the weirder code (that I added about 7 years ago!).

    BTW, for Shoebot I've started to add unit tests, including some assertions around image correctness, there stuff you can find useful

    https://github.com/shoebot/shoebot/tree/master/tests/unittests

    BTW, is _ctx when running a nodebox script, the same context ?

    For the longest time, I've been working on this + not really understanding the nodebox codebase :) (I may be main dev, but I didn't start this project).

    I feel like if I worker on it for long enough the codebase would end up looking like Nodeboxes exactly, but for now I'm happy to fix up the bugs and weirdness + maybe get it to the next release.

    Copy link
  7. _ctx is the connection to the canvas for ximported libs. It's the Context() that is created when a nodebox script is run.

    class NodeBoxRunner(object):

    def __init__(self):
        ...
        self.canvas = graphics.Canvas()
        self.context = graphics.Context(self.canvas, self.namespace)
    

    ...

    def _initNamespace(self, frame=1):
        self.canvas.clear()
        self.namespace.clear()
        # Add everything from the namespace
        for name in graphics.__all__:
            self.namespace[name] = getattr(graphics, name)
        for name in util.__all__:
            self.namespace[name] = getattr(util, name)
        # Add everything from the context object
        self.namespace["_ctx"] = self.context
    
    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply