1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# Original Python:
# from pyx import *
# from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve
# p1, p2, p3, p4, p5 = (0, 0), (2, 1.33), (1.3, 3), (0.33, 2.33), (1, 1.67)
# openpath = metapost.path.path([
# beginknot(*p1), tensioncurve(), smoothknot(*p2), tensioncurve(),
# smoothknot(*p3), tensioncurve(), smoothknot(*p4), tensioncurve(),
# endknot(*p5)])
# closedpath = metapost.path.path([
# smoothknot(*p1), tensioncurve(), smoothknot(*p2), tensioncurve(),
# smoothknot(*p3), tensioncurve(), smoothknot(*p4), tensioncurve(),
# smoothknot(*p5), tensioncurve()])
# c = canvas.canvas()
# for p in [p1, p2, p3, p4, p5]:
# c.fill(path.circle(p[0], p[1], 0.05), [color.rgb.red])
# c.fill(path.circle(p[0], p[1], 0.05), [color.rgb.red, trafo.translate(2, 0)])
# c.stroke(openpath)
# c.stroke(closedpath, [trafo.translate(2, 0)])
# c.writeEPSfile("metapost")
# c.writePDFfile("metapost")
# c.writeSVGfile("metapost")
using PyX
beginknot = metapost_path.beginknot
endknot = metapost_path.endknot
smoothknot = metapost_path.smoothknot
tensioncurve = metapost_path.smoothknot
p1, p2, p3, p4, p5 = (0, 0), (2, 1.33), (1.3, 3), (0.33, 2.33), (1, 1.67)
openpath = metapost_path.path([
beginknot(p1...), tensioncurve(), smoothknot(p2...), tensioncurve(),
smoothknot(p3...), tensioncurve(), smoothknot(p4...), tensioncurve(),
endknot(p5...)])
closedpath = metapost_path.path([
smoothknot(p1...), tensioncurve(), smoothknot(p2...), tensioncurve(),
smoothknot(p3...), tensioncurve(), smoothknot(p4...), tensioncurve(),
smoothknot(p5...), tensioncurve()])
c = canvas.canvas()
for p in [p1, p2, p3, p4, p5]:
fill(c, path.circle(p[0], p[1], 0.05), [color_rgb.red])
fill(c, path.circle(p[0], p[1], 0.05), [color_rgb.red, trafo.translate(2, 0)])
stroke(c, openpath)
stroke(c, closedpath, [trafo.translate(2, 0)])
writeEPSfile(c, "metapost")
writePDFfile(c, "metapost")
|