demonstrate deformers...
[PyX/mjg.git] / examples / path / springs.py
blob991a14598af1db99efc19e746ce52960298f95ae
1 # contributed by Gert-Ludwig Ingold
3 from pyx import *
5 n = 3 # number of masses
6 r = 3.0 # system radius
7 rcyc = 0.3 # radius of cycloid
8 nl = 13 # number of loops
9 rc = 0.5 # radius of masses
10 eps = 0.03 # extra spacing for surrounding circles
12 c = canvas.canvas()
13 springcircle = path.circle(0, 0, r)
14 masspositions = [i*springcircle.arclen()/n
15 for i in range(n)]
16 for springsegment in springcircle.split(masspositions):
17 c.stroke(springsegment,
18 [deformer.cycloid(rcyc, nl),
19 deformer.smoothed(radius=0.1)])
20 for x, y in springcircle.at(masspositions):
21 c.fill(path.circle(x, y, rc))
23 # draw border around springs.
24 # In order to demonstrate another deformer, we construct
25 # the border by expanding/constricting the original circle
26 c.stroke(springcircle, [deformer.parallel(rc+eps)])
27 c.stroke(springcircle, [deformer.parallel(-rc-eps)])
29 c.writeEPSfile("springs")
30 c.writePDFfile("springs")