pyx
pyx copied to clipboard
[Question] How to create paths with a dynamic number of elements?
The docs very skilfully show how to add a path that is known at "compile time", but since the input to path.path
it's not immediately obvious how to create a path from say, a list of points.
I would like to suggest adding an example like that, or editing the current example, to show how one might deal with user generated points, or with points read from a file.
If I understand you correctly, you are looking for something along the lines of the following code example:
from math import cos, sin, pi
from pyx import *
N = 9
r = 1
p = path.path(path.moveto(r, 0))
for i in range(N):
phi = (i+1)/N*2*pi
p.append(path.lineto(r*cos(phi), r*sin(phi)))
c = canvas.canvas()
c.stroke(p)
c.writePDFfile()
This shows how to append path elements to an existing path as needed.