-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractal_tree.py
56 lines (35 loc) · 972 Bytes
/
fractal_tree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from turtle import Turtle, mainloop, done
def tree(plist, length=200, angle=65, factor=0.62, width=12):
"""
plist is list of pens
length is length of branch
angle is half of the angle between 2 branches
factor is factor by which branch is shorented
width is current width of branches in that level
"""
if length > 3:
lst = []
for p in plist:
p.width(width)
if length < 7:
p.color('green')
p.forward(length)
q = p.clone()
p.left(angle)
q.right(angle)
lst.append(p)
lst.append(q)
tree(lst, length * factor,angle,factor, width * 0.75)
if __name__ == "__main__":
p = Turtle()
p.hideturtle()
p.speed(0)
p.getscreen()
p.getscreen()
p.left(90)
p.penup()
p.forward(-210)
p.pendown()
p.color('brown')
tree([p])
mainloop()