2 import sys
; sys
.path
[:0] = ["../.."]
4 from pyx
.deformer
import *
6 ##### helpers ##############################################################
9 return cmd
.bbox().enlarged(5*unit
.t_mm
).rect()
11 def dotest(c
, x
, y
, test
):
12 c2
= c
.insert(canvas
.canvas([trafo
.translate(x
, y
)]))
14 c
.stroke(bboxrect(c2
))
16 def drawpathwbbox(c
, p
):
17 c
.stroke(p
, [color
.rgb
.red
])
19 c
.stroke(np
, [color
.rgb
.green
, style
.linestyle
.dashed
])
22 ##### tests ################################################################
26 # dependence on turnangle
27 p
= path
.line(0, 0, 3, 0)
28 c
.stroke(p
, [style
.linewidth
.THIN
])
29 cyc
= cycloid(halfloops
=3, skipfirst
=0.5, skiplast
=0.5, curvesperhloop
=2)
30 c
.stroke(p
, [cyc(turnangle
=00)])
31 c
.stroke(p
, [cyc(turnangle
=22), color
.rgb
.red
])
32 c
.stroke(p
, [cyc(turnangle
=45), color
.rgb
.green
])
33 c
.stroke(p
, [cyc(turnangle
=67), color
.rgb
.blue
])
34 c
.stroke(p
, [cyc(turnangle
=90), color
.cmyk
.Cyan
])
36 # dependence on curvesperloop
37 p
= path
.curve(5, 0, 8, 0, 6, 4, 9, 4)
39 cyc
= cycloid(halfloops
=16, skipfirst
=0, skiplast
=0, curvesperhloop
=1)
40 c
.stroke(p
, [cyc(curvesperhloop
=2)])
41 c
.stroke(p
, [cyc(curvesperhloop
=3), color
.rgb
.red
])
42 c
.stroke(p
, [cyc(curvesperhloop
=4), color
.rgb
.green
])
43 c
.stroke(p
, [cyc(curvesperhloop
=10), color
.rgb
.blue
])
45 # extremely curved path
46 p
= path
.curve(0,2, 0.5,5, 1,6, 2,2)
48 cyc
= cycloid(radius
=0.7, halfloops
=7, skipfirst
=0, skiplast
=0, curvesperhloop
=1)
49 c
.stroke(p
, [cyc(curvesperhloop
=2)])
50 c
.stroke(p
, [cyc(curvesperhloop
=3), color
.rgb
.red
])
51 c
.stroke(p
, [cyc(curvesperhloop
=4), color
.rgb
.green
])
52 c
.stroke(p
, [cyc(curvesperhloop
=50), color
.rgb
.blue
])
60 path
.curveto(0,10, -2,8, 0,6),
62 # horrible overshooting with obeycurv=1
63 #path.lineto(-4,4), path.curveto(-7,5, -4,2, -5,2),
64 path
.lineto(-4,3), path
.curveto(-7,5, -4,2, -5,2),
65 #path.arct(-6,4, -5,1, 1.5),
66 #path.arc(-5, 3, 0.5, 0, 180),
68 path
.lineto(-0.2,0.2),
70 ) + path
.circle(0,0,2)
72 c
.stroke(p
, [color
.gray(0.8), style
.linewidth
.THICk
])
73 c
.stroke(p
.normpath(), [color
.gray(0.8), style
.linewidth
.THICk
])
74 c
.stroke(p
, [smoothed(radius
=0.85, softness
=1, obeycurv
=1), style
.linewidth
.Thin
])
75 c
.stroke(p
, [smoothed(radius
=0.85, softness
=1, obeycurv
=0), color
.rgb
.red
])
76 c
.stroke(p
, [smoothed(radius
=0.20, softness
=1, obeycurv
=0), color
.rgb
.green
])
77 c
.stroke(p
, [smoothed(radius
=1.20, softness
=1, obeycurv
=0), color
.rgb
.blue
])
81 path
.curveto(1,10, 4,12, 2,11),
82 path
.curveto(4,8, 4,12, 0,11)
84 c
.stroke(p
, [color
.gray(0.8), style
.linewidth
.THICk
])
85 c
.stroke(p
.normpath(), [color
.gray(0.8), style
.linewidth
.THICk
])
86 c
.stroke(p
, [smoothed(radius
=0.85, softness
=1, obeycurv
=1), style
.linewidth
.Thin
])
87 c
.stroke(p
, [smoothed(radius
=0.85, softness
=1, obeycurv
=0), color
.rgb
.red
])
88 c
.stroke(p
, [smoothed(radius
=0.20, softness
=1, obeycurv
=0), color
.rgb
.green
])
89 c
.stroke(p
, [smoothed(radius
=1.20, softness
=1, obeycurv
=0), color
.rgb
.blue
])
92 dotest(c
, 0, 0, "testcycloid")
93 dotest(c
, 17, 0, "testsmoothed")
94 c
.writeEPSfile("test_deformer", paperformat
=document
.paperformat
.A4
, rotated
=0, fittosize
=1)
95 c
.writePDFfile("test_deformer")