tag:support.nodebox.net,2012-11-01:/discussions/nodebox-1/91-how-does-shoebot-1-decide-to-render-a-single-image-or-run-an-animationNodeBox: Discussion 2021-01-30T09:26:02Ztag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T12:37:52Z2020-05-03T12:37:52ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>In file console.py, in class NodeboxRunner method _check_animation() is self-explanatory.</p>
<p>See also usages of this method.</p></div>karstenwotag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T17:27:33Z2020-05-03T17:27:34ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>Ah, great - I was thinking that having speed with a default of None might be a way of implementing this.</p>
<p>Reassuring to see I was thinking along similar lines.</p>
<p>This is definitely enough to write some unit tests for Shoebot so our implementation is compatible.</p></div>Stutag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T17:32:24Z2020-05-03T17:32:26ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>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 ?</p></div>Stutag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T18:31:17Z2020-05-03T18:31:17ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>Hey, I only keep it alive ;-) and write some new stuff; occasionally.</p>
<p>...graphics "context" is the current state</p>
<p>Yes. It's in nodebox/graphics/<strong>init</strong>.py and should be adaptable to Shoe with minimal changes</p>
<p>...while canvas is the thing it paints on... Yes. And it has connections to the Cocoa framework</p>
<p>If you look in my fork here</p>
<p><a href="https://github.com/karstenw/nodebox-pyobjc/blob/7dbbb1d3d1263d9a08faf22e11910bd5f9b4a817/nodebox/graphics/cocoa.py#L15">https://github.com/karstenw/nodebox-pyobjc/blob/7dbbb1d3d1263d9a08f...</a></p>
<p>you'l see all the Cocoa functions that are used.</p></div>karstenwotag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T20:31:05Z2020-05-03T20:31:07ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>Thanks.</p>
<p>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!).</p>
<p>BTW, for Shoebot I've started to add unit tests, including some assertions around image correctness, there stuff you can find useful</p>
<p><a href="https://github.com/shoebot/shoebot/tree/master/tests/unittests">https://github.com/shoebot/shoebot/tree/master/tests/unittests</a></p>
<p>BTW, is _ctx when running a nodebox script, the same context ?</p>
<p>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).</p>
<p>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.</p></div>Stutag:support.nodebox.net,2012-11-01:Comment/482993692020-05-03T21:30:14Z2020-05-03T21:30:14ZHow does Shoebot 1 decide to render a single image or run an animation ?<div><p>_ctx is the connection to the canvas for ximported libs. It's the Context() that is created when a nodebox script is run.</p>
<p>class NodeBoxRunner(object):</p>
<pre>
<code>def __init__(self):
...
self.canvas = graphics.Canvas()
self.context = graphics.Context(self.canvas, self.namespace)</code>
</pre>
<p>...</p>
<pre>
<code>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</code>
</pre></div>karstenwo