Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to create paths with a dynamic number of elements? #38

Open
Makogan opened this issue Sep 19, 2022 · 1 comment
Open

Comments

@Makogan
Copy link

Makogan commented Sep 19, 2022

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.

@joerg-lehmann
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants