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

Line path CapStyle + JoinStyle

Posted by Giorgio O. on Oct 27, 2007

A small piece of code that allows to set the line caps and join styles. It's based on the linedash example found it the tutorial PyObjC.

from AppKit import NSBezierPath
size(400, 400)
background(0.5,0.5,0.53)
 
x0,y0 = 30,100
x1,y1 = 130,100
x2,y2 = 200,140
x3,y3 = 200,50
x4,y4 = 300,50
 
'''
   MiterLine JoinStyle = 0
   RoundLine JoinStyle = 1
   BevelLine JoinStyle = 2
   
   ButtLine CapStyle   = 0
   RoundLine CapStyle  = 1
   SquareLine CapStyle = 2
   
'''
 
def capstyle(path, style): 
    path._nsBezierPath.setLineCapStyle_(style)
    return path
    
def joinstyle(path, style): 
    path._nsBezierPath.setLineJoinStyle_(style)
    return path
 
strokewidth(15)
stroke(1)
nofill()
 
l = BezierPath()
l.moveto(x0, y0)
l.lineto(x1, y1)
l.lineto(x2, y2)
l.lineto(x3, y3)
l.lineto(x4, y4)
capstyle(l, 1)
joinstyle(l, 2)
drawpath(l)
 
g = BezierPath()
g.moveto(x0, y0+150)
g.lineto(x1, y1+150)
g.lineto(x2, y2+150)
g.lineto(x3, y3+150)
g.lineto(x4, y4+150)
capstyle(g, 3)
joinstyle(g, 1)
drawpath(g)


 
Posted by fdb on Nov 06, 2007

They sound interesting enough to include in the next release.

I added a ticket in Trac, so you can follow up on this issue:

http://dev.nodebox.net/ticket/113

Kind regards,

Frederik



Posted by Dimitre on Sep 06, 2011

Not sure if its Nodebox or PyObjC issue, it is not working anymore in OS X Lion, Nodebox 1.9.7rc1