The information on this page might change rapidly. You can check the recent changes to see if any updates have occurred.
This page will show you:
- How to build your own node from scratch by using a generator node.
- How to edit and reload code.
- How to add parameters and use them in your script.
Contents |
Hairy filter

[[file download: Media:furrylise.ndbx Media:furrylise.png]]
Following example creates a node that can recieve a list of points to generate hairs on them growing away from a specified point.
To achieve this we will start from the filter template node, part of the core nodes. It has an input (shape) and returns an output.
First we will create all necessary variables:
- a strokecolor and a strokewidth
- a point (to go away from) consisting of an x and y position, lets call it midx and midy
Go to the parameters pane and press "metadata" in the upper left corner to open the metadata pane. The metadate pane allows users to create new parameters within a node.
In the lower left corner is a little interface that allows to create, delete or reorder new parameters which looks like this:
Create 4 new parameters called:
- midx with type set to float
- midy with type set to float
- stroke, with type set to color
- strokewidth with type set to float
When done it should look like this:
You can rename the filter node by double clicking its name and give it a new one.
The example uses 3 nodes:
- a shape node (textpath1)
- a scatter node (scatter1) to create points within the shape
- a furryliser node which is the one we're working on.
Go to the source pane of the new node and type following code:
from nodebox.graphics import Path,Geometry
from random import uniform
def cook(self):
if self.shape is None: return None
p1c = self.shape.clone()
g = Geometry()
for i, point in enumerate(p1c.points):
p1 = Path()
x = point.x
y = point.y
xx = (x-self.midx)/2
yy = (y-self.midy)/2
p1.strokeColor = self.stroke
p1.strokeWidth = self.strokewidth
p1.line(x,y,x+uniform(0,xx),y+uniform(0,yy))
g.add(p1)
return g
When changing the code make sure to press the "reload" button to save the changes and executing it in the viewer pane. If you at some point forget to reload the node will be set to its previous saved form.
What happens is that every point from the given input is used to draw a line from it to another point based on the midx and midy input from the parameters pane.
The screenshots of the network shows the new node with an icon. For more information on saving to a library go to the next section
Same principle .. Other input

[[file download: Media:pix_image.ndbx
Is it a hairy monkey or george W ?
The input comes from a node calculating points within a picture. It has two parameters:
- foto with as type string
- segment with as type float
It also uses some java input.
the source code of this node looks like:
from javax.imageio import ImageIO
from java.io import File
from nodebox.graphics import Path,Color
def cook(self):
g = Path()
g.fill = None
f = File(self.foto)
bi = ImageIO.read(f)
raster = bi.raster
w = raster.width
h = raster.height
seg = self.segment
for i in xrange(0,w,seg):
for j in xrange(0,h,seg):
c = bi.raster.getPixel(i,j,[0.0,0.0,0.0])
if c[0]<120:
g.addPoint(i-w/2,j-h/2)
return g.asGeometry()
Webby filter

[[file download: Media:webalise.ndbx Media:webalise.png]]
Following example uses 3 nodes:
- a textpath node
- a resample node to resample the amount of points
- a node called webaliser which draws spider like web in the shape.
To achieve it we will take the incoming points and calculate the distance between them and a random (over choice) point from the same list. If the distance is less than a certain value (in this example a parameter part of the node called maxdistance (parameter type float), a line will be drawn between them.
In the parameter pane create 2 parameters: one float called maxdistance and a color called stroke.
The source code looks like this:
from nodebox.graphics import Path,Geometry
from nodebox.util.Geometry import distance
from random import uniform,choice
def cook(self):
if self.shape is None: return None
p1c = self.shape.clone()
g = Geometry()
for i, point in enumerate(p1c.points):
checkpoint = choice(p1c.points)
p1 = Path()
d =distance(point.x,point.y,checkpoint.x,checkpoint.y)
if d<self.maxdistance:
p1.line(point.x,point.y,checkpoint.x,checkpoint.y)
p1.strokeColor = self.stroke
g.add(p1)
return g
Spikey filter

[[file download: Media:spikelise.ndbx Media:spikelise.png]]
Download and store in users/Library/NodeBox/Scripts/ in a new folder. The example shown as above has following as network.
Try changing the angle for inside and outside spikes, change curvature to create leafs, triangles etc.
Peter de Jong attractor

[[file download: Media:Peterring.ndbx]]
In abstraction, a path given as template input could be anything; a grid, points in a path, a textpath.. Below is an example on a path that stores the points given by the equation within the Peter de Jong fractal.
the network consists of 3 nodes.
- an ellipse node with dimensions 2px - connected to the shape port on the placenode
- a node that generates a path based on Peter de Jong extractor with 5000 points - connected on the template port of the placenode.
- a place node that will place an instance of the ellipsenode on each point of the fractal
The easiest way to start with this is to open a generator template node which already has an output to work with. The node itself takes only 1 parameter called segment but a,b,c,d could also be stored in parameters or even a menu to create different kind of fractals
Here is the code of the peterringnode:
from nodebox.graphics import Path
from math import sin,cos
def cook(self):
p = Path()
p.fill = None
a,b,c,d = 1.4,1.56,1.4,-6.56
x0,y0 = 0.0,0.0
scale = 30.0
for i in xrange(self.number):
x1 = d*sin(a*x0)-sin(b*y0)
y1 = c*cos(a*x0)+cos(b*y0)
p.addPoint(x1*scale, y1*scale)
x0,y0 = x1,y1
return p.asGeometry()







