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

Stu's Avatar

Stu

03 May, 2020 11:35 AM

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 :)

  1. 1 Posted by karstenwo on 03 May, 2020 12:37 PM

    karstenwo's Avatar

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

    See also usages of this method.

  2. 2 Posted by Stu on 03 May, 2020 05:27 PM

    Stu's Avatar

    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.

  3. 3 Posted by Stu on 03 May, 2020 05:32 PM

    Stu's Avatar

    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 ?

  4. 4 Posted by karstenwo on 03 May, 2020 06:31 PM

    karstenwo's Avatar

    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.

  5. 5 Posted by Stu on 03 May, 2020 08:31 PM

    Stu's Avatar

    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.

  6. 6 Posted by karstenwo on 03 May, 2020 09:30 PM

    karstenwo's Avatar

    _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

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

Generic

? 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

18 Nov, 2024 11:24 PM
18 Nov, 2024 09:01 PM
07 Nov, 2024 10:53 AM
02 Nov, 2024 11:22 AM
01 Nov, 2024 12:41 AM

 

01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM
30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM
26 Sep, 2024 06:41 AM