1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Current (x,y) from graphics state?

Posted by Red on Apr 28, 2008

Is there a way to get the current (x,y) position from the graphics state? This could be way useful if you send out a wandering bot that works on translate/rotate and want to append it's location to a path for later drawing.

For an over simplified example:

points = []
translate(300,300)
for i in range(10):
   rx = random(20)
   ry = random(20)
   rotate(x, y)
   translate(rx, ry)
   points.append((currentGlobalx, currentGlobaly))
 
drawpath(points)


 
Posted by Tom De Smedt on May 11, 2008

One way would be to store the rotations and translations on each step, and then later repeat the sequence of rotate() and translate(). However, this is not useful if you want to draw a path of connected lines. Then you'll absolute from and to coordinates.

You'll then need to calculate the absolute coordinates yourself. This is not too hard with a combination of commands in the Math tutorial. The described distance() and coordinates() commands may be of use to you.