ยปCore Development>Code coverage>Lib/turtledemo/tree.py

# Python code coverage for Lib/turtledemo/tree.py

#countcontent
1n/a#!/usr/bin/env python3
2n/a""" turtle-example-suite:
3n/a
4n/a tdemo_tree.py
5n/a
7n/ato the classical Logo tree drawing programs,
8n/awhich use a depth-first-algorithm.
9n/a
10n/aUses:
11n/a(1) a tree-generator, where the drawing is
12n/aquasi the side-effect, whereas the generator
13n/aalways yields None.
14n/a(2) Turtle-cloning: At each branching point
15n/athe current pen is cloned. So in the end
16n/athere are 1024 turtles.
17n/a"""
18n/afrom turtle import Turtle, mainloop
19n/afrom time import clock
20n/a
22n/a """ plist is list of pens
23n/a l is length of branch
24n/a a is half of the angle between 2 branches
25n/a f is factor by which branch is shortened
26n/a from level to level."""
27n/a if l > 3:
28n/a lst = []
29n/a for p in plist:
30n/a p.forward(l)
31n/a q = p.clone()
32n/a p.left(a)
33n/a q.right(a)
34n/a lst.append(p)
35n/a lst.append(q)
36n/a for x in tree(lst, l*f, a, f):
37n/a yield None
38n/a
40n/a p = Turtle()
41n/a p.setundobuffer(None)
42n/a p.hideturtle()
43n/a p.speed(0)
44n/a p.getscreen().tracer(30,0)
45n/a p.left(90)
46n/a p.penup()
47n/a p.forward(-210)
48n/a p.pendown()
49n/a t = tree([p], 200, 65, 0.6375)
50n/a for x in t:
51n/a pass
52n/a print(len(p.getscreen().turtles()))
53n/a