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

Multiple instances of a path

Posted by Sisra on Nov 28, 2007

I'm using NodeBox 1.0rc7 with the Cornu library. How can I get Path 1 and Path 2 to be the same? The code is:

cornu = ximport("cornu")
 
size(400, 400)
colormode(CMYK, range=100)
 
def curva():
    crpoints = []
    for i in range(4):
        x = random(0.25, 0.75)
        y = random(0.25, 0.75)
        coordenadas = (x, y)
        crpoints.append(coordenadas)
    p = cornu.path(crpoints, tweaks=1)
    drawpath(p)
 
nofill()
strokewidth(0.5)
stroke(100, 0, 0, 0)
 
# Path 1
curva()
 
# Path 2. It must be the same as path 1 but scaled (or rotated, translated, etc.)
scale(.5)
curva()
Also I tried using the bezier library and path.copy, but it seems don't work with v. 1.0rc7.

Any help?
Thanks in advance.


 
Posted by anonymous on Nov 29, 2007

Hm… Ah hah! If I am correct, you must create the path, transform, and then draw it. Here is a revised version:

cornu = ximport("cornu")
 
size(400, 400)
colormode(CMYK, range=100)
 
def curva():
    crpoints = []
    for i in range(4):
        x = random(0.25, 0.75)
        y = random(0.25, 0.75)
        coordenadas = (x, y)
        crpoints.append(coordenadas)
    return cornu.path(crpoints, tweaks=1)
 
nofill()
strokewidth(0.5)
stroke(100, 0, 0, 0)
 
# Path 1
drawpath(curva())
 
# Path 2. It must be the same as path 1 but scaled (or rotated, translated, etc.)
p = curva()
scale(.5)
drawpath(p)
That might work better.



Posted by Tom De Smedt on Nov 29, 2007

Since you are using random() commands inside your curva() command, two calls to curva() will never yield the same path.

You need to create one path from curva(), and then create copies of that path. The path.copy() command doesn't work with NodeBox 1.0rc7, but there's another way: drawpath() also accepts a list of points.

p1 = curva()
drawpath(p1)
 
try:
    # NodeBox 1.9
    p2 = p1.copy()  
except:
    # NodeBox 1.0rc7
    p2 = [pt for pt in p1] 
scale(0.5)
drawpath(p2)