I'll never learn it ...
[PyX.git] / test / functional / test_deformer.py
blob34325c48b88ae3da2a0126bdbcddfdaf4a8bc31a
1 #!/usr/bin/env python
2 import sys; sys.path[:0] = ["../.."]
3 from pyx import *
4 from pyx.deformer import *
6 ##### helpers ##############################################################
8 def bboxrect(cmd):
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)]))
13 eval("%s(c2)" % test)
14 c.stroke(bboxrect(c2))
16 def drawpathwbbox(c, p):
17 c.stroke(p, [color.rgb.red])
18 np = p.normpath()
19 c.stroke(np, [color.rgb.green, style.linestyle.dashed])
20 c.stroke(bboxrect(p))
22 ##### tests ################################################################
24 def testcycloid(c):
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)
38 c.stroke(p)
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)
47 c.stroke(p)
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])
55 def testsmoothed(c):
56 p = path.path(path.moveto(0,0), path.lineto(3,0), path.lineto(5,7),
57 path.curveto(0,10, -2,8, 0,6),
58 path.lineto(0,4), path.lineto(-5,4), path.lineto(-5,2), path.lineto(-0.2,0.2),
59 path.closepath()
60 ) + path.circle(0,0,2)
62 c.stroke(p, [color.gray(0.8), style.linewidth.THICk])
63 c.stroke(p, [smoothed(radius=0.85, softness=1, obeycurv=1), style.linewidth.Thin])
64 c.stroke(p, [smoothed(radius=0.85, softness=1, obeycurv=0), color.rgb.red])
65 c.stroke(p, [smoothed(radius=0.20, softness=1, obeycurv=0), color.rgb.green])
66 c.stroke(p, [smoothed(radius=1.20, softness=1, obeycurv=0), color.rgb.blue])
68 c=canvas.canvas()
69 dotest(c, 0, 0, "testcycloid")
70 dotest(c, 15, 0, "testsmoothed")
71 c.writeEPSfile("test_deformer", paperformat="a4", rotated=0, fittosize=1)
72 c.writePDFfile("test_deformer")