I don't understand what you are trying to do with this code:
pts = [] for pt in path.points(12): oval(pt.x-2, pt.y-2, 4, 4) pts.append(pt) drawpath(pts)If you have the path already, why don't you just draw that:
drawpath(path)instead of putting the points into a list and drawing those?
Anyways, the error you're getting is because path.points() doesn't give you a MOVETO-type PathElement, which you need at the beginning of a path to indicate where it starts from.
Try:
pts = [] for pt in path: oval(pt.x-2, pt.y-2, 4, 4) pts.append(pt) print pts pts = [] for pt in path.points(12): oval(pt.x-2, pt.y-2, 4, 4) pts.append(pt) print ptsand you will see what the lists look like after the loop.
a
hi
thanks for fast replay and sorry for my bad english
my mailnly problem is that i have a path defined with 3 curveTo, so with 3 pathelement point. and i want to ahe an equal path with 12 pathelemnts that produce the same curve.
is it possible?
i'm using one more pathelements list (pts) because i'm getting different variation of the original one randomizing (well not properly random) the x and y of each pathelement object. with only 3 points i'm getting kind the same (well, one for each randomizing procedure) pattern. i think that with more definition points i can achive more various pattern.. is it right?
i tried to cody the first pathelemtn (the MOVE_TO one) for the first ot others like this:
pts1.insert(0, pts[0] )now no error but the resuting path is a bit distorted (more points more distorted).. how can i do?
mayebe segmentlengths() is the answer? i didn't find documentation of that.. where is a complete reference of path class? like javadoc for standard java api (also processing.org has this lack of documentation) and how can i get a python shell to do all my test without each time write and apple+r?
last question: bezier nodebox api implements spline and not simple quadratic bezier isn'it?
Okay, I understand what you're trying to do. I don't think there's a simple answer. Well, the only possible simple answer that I see is to use findpath() on your list of points, but that will still require some manipulation of the PathElements.
NodeBox's paths are just wrappers for Apple's Cocoa NSBezierPath class. I think they use cubic interpolation, but I'm not really clear on the difference and I couldn't find the answer in a quick search. Here are nodebox reference documents that may interest you: BezierPath class PathElement class. Here are some relevant Apple docs: CocoaDrawing Guide, section on Paths NSBezierPath Class reference.
Now, as far as getting more points on a path you already have, this is problematic. I believe that when you try to get more points out of a path using the path.points() method, you're really just getting points -- the PathElements that result don't have control points that result in an accurate reconstruction of the path. This is why the path seems distorted. I believe that it does this because figuring out those control points would be way too much work. I could be off base, though, so I recommend that if you really want to figure it out, take a look at the code: bezier.py
As far as running nodebox from the command line, I don't believe it's possible, because there's no drawing context for it to use.
Hope that's more help than trouble! Good luck!
Actually, I just tried this:
pts = [pt for pt in path.points(12)] path_2 = findpath(pts) drawpath(path_2)and it gives a pretty good approximation of the original path; maybe that will do the trick for you!
Huh. I just found this page about running NB from the command line. Did not realize that it was possible!
[drawpath] some point missing?
Posted by alberto on Jan 12, 2010sorry i don't know if this is the right point to post code question
[code]
print "dud"
pts = []
for pt in path:
oval(pt.x-2, pt.y-2, 4, 4)
pts.append(pt)
drawpath(pts)
print "dudee"
pts = []
for pt in path.points(12):
oval(pt.x-2, pt.y-2, 4, 4)
pts.append(pt)
drawpath(pts)
[/code]
this:
dud
dudee
Traceback (most recent call last):
File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
File "/Users/alberto/Documents/NodeBox/bezier_test.py", line 91, in
File "nodebox/graphics/__init__.pyo", line 309, in drawpath
File "nodebox/graphics/__init__.pyo", line 124, in BezierPath
File "nodebox/graphics/__init__.pyo", line 121, in _makeInstance
File "nodebox/graphics/cocoa.pyo", line 217, in __init__
File "nodebox/graphics/cocoa.pyo", line 306, in extend
File "nodebox/graphics/cocoa.pyo", line 317, in append
File "nodebox/graphics/cocoa.pyo", line 246, in curveto
error: NSGenericException - No current point for curve