Interaction old
NodeBox is designed to output PDF documents, when you want to do all sorts of moving and interactive things you're probably better off with a tool like Processing.
However, if you do want to experiment with interactivity in NodeBox, there's a library that might be of help to you.
The Interaction library
The Interaction library (4KB) has two commands that you can use in an animation:
- mousedown(path=None): returns True when the mouse button is pressed on the canvas, or optionally, on the given path.
- mouse(): returns a tuple containing the mouse's coordinates.
Getting the mouse coordinates is easy enough - put the interaction libary in the same folder as your project, import it, and call the mouse command():
interaction = ximport("interaction")
x, y = interaction.mouse()
print x, y
Checking if the mouse is pressed is equally easy:
p = textpath("hit me!", 100, 100)
drawpath(p)
if interaction.mousedown(p): print "pressed on path"
A fun example is included in the download: the electric.py script. Simply run it, draw some stuff on the canvas, and watch it evolve!
