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

concentric circles

Posted by spooky kid on Apr 15, 2008

Hi, I'm new in nodebox, and I'm trying to draw concentric circles but I don't know how to center objects in the screen (align center). Can anybody help me?

Thanks!


 
Posted by Mark M on Apr 15, 2008

SK,

Circle in nodebox are defined from their top-left corner so you need to go through an extra step of moving them up and to the left by the amount of the radius to have them centered where you want.

Here's a short example:

stroke(.2)
nofill()
 
#set up some constants you change to fit your needs
center_x, center_y = (200, 200)
gap_between_circles = 14
 
for diameter in range(1,20):
    diameter *= gap_between_circles
    radius = diameter/2.0
    oval(center_x-radius, center_y-radius, diameter, diameter)



Posted by andrea on Apr 16, 2008

if you define:

def centeredOval(x, y, radius, other = None):
    if other == None:
        other = radius
    return oval(x-radius*0.5, y-other*0.5, radius, other)
you can use
# centered in 10, 10 with radius 20
# other is None, so it's a circle
centeredOval(10, 10, 20)
Best
-a-



Posted by Spooky Kid on Apr 24, 2008

Thanks for your help!