~ubuntu-branches/ubuntu/trusty/pyx/trusty

« back to all changes in this revision

Viewing changes to examples/path/tree.py

  • Committer: Bazaar Package Importer
  • Author(s): Graham Wilson
  • Date: 2004-12-25 06:42:57 UTC
  • Revision ID: james.westby@ubuntu.com-20041225064257-31469ij5uysqq302
Tags: upstream-0.7.1
Import upstream version 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: ISO-8859-1 -*-
 
2
# fractal tree
 
3
# contributed by Gerhard Schmid and Andr� Wobst
 
4
 
 
5
from pyx import *
 
6
 
 
7
# base tree length
 
8
l = 5
 
9
 
 
10
# base transformations for the left, center, and right part of the tree
 
11
ltrafo = trafo.rotate(65).scaled(0.4).translated(0, l * 2.0 / 3.0)
 
12
ctrafo = trafo.rotate(-4).scaled(0.75).translated(0, l)
 
13
rtrafo = trafo.mirror(90).rotated(-65).scaled(0.35).translated(0, l)
 
14
 
 
15
def tree(depth):
 
16
    "return transformations for a recursive tree of given depth"
 
17
    r = [trafo.rotate(5)]
 
18
    if depth > 0:
 
19
        subtree = tree(depth - 1)
 
20
        r.extend([t*ltrafo for t in subtree])
 
21
        r.extend([t*ctrafo for t in subtree])
 
22
        r.extend([t*rtrafo for t in subtree])
 
23
    return r
 
24
 
 
25
c = canvas.canvas()
 
26
for t in tree(7):
 
27
    # apply the transformation to a "sub"-canvas and insert it into the "main" canvas
 
28
    c.insert(canvas.canvas([t])).stroke(path.line(0, 0, 0, l))
 
29
c.writeEPSfile("tree", paperformat="a4")
 
30