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

draw partial path

Posted by Ralph on Apr 23, 2008

Does anyone know if it there is a straightforward way to draw only a selected portion of a path? That is, I have a path, p, and I would like to draw the subsegment from parameter t1 to parameter t2 (say, for example from t = .3 to .7).

Thanks in advance.



Posted by anonymous on Apr 23, 2008

I threw this together in a few seconds. Hope it helps.

oldpath = textpath("h", 0, 20)
newpath = BezierPath()
begin = 0.1
end = 0.9
resolution = 0.01
for i in range(int(begin*100), int(end*100), int(resolution*100)):
    pt = oldpath.point(float(i)/100.0)
    try: newpath.lineto(pt.x, pt.y)
    except: newpath.moveto(pt.x, pt.y)
 
drawpath(oldpath)
translate(20, 0)
drawpath(newpath)

 

Posted by Ralph on Apr 25, 2008

Thanks for that. It's an effective solution, but I was hoping there might be something less "choppy", whereby one would create a new subpath using bezier math, rather than a linear "approximation".

But your solution does work fine.



Posted by lievn on Apr 28, 2008

an alternative..

fontsize(100)
size(300,200)
pad = textpath("test",40,100)
points = []
param1 = 20;param2 = 75
 
for i in range(len(pad)):
    point = pad[i]
    ''' you need a starting point
    otherwise error: NSGenericException - No current point for curve/line
    might turn up
    '''
    if i == 0:
        points.append(point)
    ''' add points between parameters to 
    the points list
    '''
    if i > param1 and i < param2:
        points.append(point)
 
nofill()
stroke(0)
drawpath(points)