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

pathname.draw() VS drawpath(pathname)

Posted by Giorgio O. on Oct 29, 2007

Hello,

what's the difference - under the hood - between

pathname.draw()
and
drawpath(pathname)
?

In one sketch that I'm writing, using pathname.draw() gives me only the fill without stroke while drawpath(pathname) gives me the stroked path. Shouldn't they behave the same?

thanks!
G.


 
Posted by Tom De Smedt on Oct 30, 2007

Hi Giorgio,

They should behave the same. Can you provide an example where they don't?



Posted by Giorgio O. on Oct 31, 2007

Hello Tom,

sure! here's the example from the draft of some graphic work,
take a look at the final effect as it should be:
www.todo.to.it/clients/nodebox/lines_joydivision_ok.jpg
this was drawn with "drawpath(pathname)".

This one instead was drawn with "pathname.draw()"
www.todo.to.it/clients/nodebox/lines_joydivision_bizarre.jpg
(it would be nice to post images also in comments :-)

here's the code:

size(400,400)
background(0.5) # this is set to grey only to debug, it should be black
nofill()
nostroke()
 
core = ximport("coreimage")
 
canvas = core.canvas(150,150)
imm = canvas.layer("yourgrayscaleimage.png")
imm_w, imm_h = imm.size()
imm_w = int(imm_w)
imm_h = int(imm_h)
imm_p = imm.pixels()
step_x = 3
step_y = 10
linedepth = 70
 
def ovo(x,y,d):
    r = d/2.0
    oval(x-r,y-r,d,d)
    
strokewidth(0.6)
stroke(1)
fill(0)
 
colormode(RGB,255)
 
pathlist = []
 
for y in range(0, imm_h, step_y):
    multipath = BezierPath()
    multipath.moveto(0, y + linedepth)
 
    for x in range(0, imm_w, step_x):
        r, g, b = imm_p.get_pixel(x, y)
        c = color(r, g ,b)
        b = c.brightness
        multipath.lineto( x, y + b*linedepth)
        
    pathlist.append(multipath)
 
for i in range(len(pathlist)):
    pathlist[i].draw() # THE WEIRD ONE
    #drawpath(pathlist[i]) # THE OK ONE
load whatever grayscale blurred image you have

(and yes, it is inspired at Peter Saville's cover art for Joy Division ;-)



Posted by Tom De Smedt on Oct 31, 2007

Ah yes, I see. You should always use drawpath().
path.draw() is for internal use only - it draws the path without taking into account the current state.

If you must use path.draw(), then first intherit the state:

p.inheritFromContext()
p.draw()
Thanks for sharing your Savillizer by the way, looks great! Perhaps we should add it to the gallery.



Posted by Tom De Smedt on Oct 31, 2007

Naturally, you could also do the grayscaling and blurring in the script itself:

imm.desaturate()
imm.filter_blur(5)
For this to work you would also have to discern between RGB and RGBA pixels:
p = imm_p.get_pixel(x, y)
if len(p) == 4:
    r, g, b, a = p
else:
    r, g, b = p



Posted by Giorgio O. on Nov 01, 2007

Awesome! thanks for the useful tips.
If you like the idea of adding it to the gallery I'll be more than glad to prepare a document with proper images and a detailed description.



Posted by Lucas Nijs on Nov 01, 2007

Please go ahead, we will be more than happy to add it, and thanks for sharing.