-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path分型树
More file actions
49 lines (40 loc) · 880 Bytes
/
分型树
File metadata and controls
49 lines (40 loc) · 880 Bytes
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
"""
08/06/2019
wanghangkai
fractual_tree
1.0
"""
import turtle
def draw_branch(branch_length):
"""
绘制分型树
"""
if branch_length > 5:
# 绘制右侧树枝
turtle.forward(branch_length)
print('forward',branch_length)
turtle.right(20)
print('right',20)
draw_branch(branch_length - 15)
# 绘制左侧树枝
turtle.left(40)
print('left',40)
draw_branch(branch_length - 15)
# 返回之前的树枝
turtle.right(20)
print('right',20)
turtle.backward(branch_length)
print('backward',branch_length)
def main():
"""
zhuhanshu
"""
turtle.left(90)
turtle.penup()
turtle.backward(150)
turtle.pendown()
turtle.color('green')
draw_branch(100)
turtle.exitonclick()
if __name__ == '__main__':
main()