mistake in handling column numbers > 9 (thanks to Thomas Lueck for reporting that...
[PyX/mjg.git] / examples / tree.py
blob57609421a1081f7ef7fc36ab7efc6e82229a1bab
1 import math, sys
2 sys.path[:0] = [".."]
4 from pyx import *
6 def tree(depth):
7 result = [trafo.trafo()]
8 if depth > 0:
9 subtree = tree(depth - 1)
10 result.extend([t.rotate(65).scale(0.5).translate(0, 2.0/3.0) for t in subtree])
11 result.extend([t.rotate(-4).scale(0.7).translate(0, 1) for t in subtree])
12 result.extend([t.mirror(90).rotate(-65).scale(0.5).translate(0, 1) for t in subtree])
13 return result
15 w = 0.01
16 c = canvas.canvas()
17 #for t in tree(8):
18 # c.insert(canvas.canvas(t).stroke(path.line(0, 0, 0, 1)))
20 for t in tree(8):
21 c.fill(path.path(path.moveto(-w, 0),
22 path.lineto(-0.7*w, 1+w*math.sin(4*math.pi/180)),
23 path.lineto(0.7*w, 1-w*math.sin(4*math.pi/180)),
24 path.lineto(w, 0),
25 path.closepath()).transformed(t))
26 c.writetofile("tree", paperformat="a4", fittosize=1)