tag:support.nodebox.net,2012-11-01:/discussions/nodebox-1/53-calling-nodebox-functions-from-a-library-moduleNodeBox: Discussion 2015-03-09T09:27:10Ztag:support.nodebox.net,2012-11-01:Comment/362254402015-03-09T09:27:09Z2015-03-09T09:27:09ZCalling Nodebox functions from a library Module<div><p>You're right: the NodeBox 3 graphics API is different from the
NodeBox 1 API. That's because the new API uses Path objects instead
of directly drawing which is what NodeBox 1 did. We do this because
we can take these generated Path objects and modify them using
different nodes, for example the "wiggle" node.</p>
<p>So whereas in NodeBox 1 you would write:</p>
<pre>
<code>rect(10, 20, 30, 40)</code>
</pre>
<p>In NodeBox 3, you would construct a Path and add a rectangle to
it:</p>
<pre>
<code>from nodebox.graphics import Path
def my_rect(x, y, w, h):
p = Path()
p.rect(x, y, w, h)
return p</code>
</pre>
<p>We call these nodes <strong>generators</strong>: they only take
in primitive values (numbers) and generate shapes. Nodes that take
in shapes and modify them are called <strong>filters</strong>. They
might look like this:</p>
<pre>
<code>def my_colorize(shape, fill):
if shape is None: return None
new_shape = shape.clone()
new_shape.fill = fill
return new_shape</code>
</pre>
<p>Note that these nodes are required to <em>clone</em> the input
shape, instead of modifying the input shape directly.</p>
<p>The documentation for the graphics API is unfortunately still
missing. You can look at the <a href=
"https://github.com/nodebox/nodebox/blob/master/src/main/java/nodebox/graphics/Path.java">
source code for the Path class</a> to see how it works
internally.</p>
<p>I hope this helps. Feel free to ask any additional
questions.</p></div>Frederik De Bleser