import turtle import random # 设置窗口大小 turtle.screensize(600, 600) # 设置画笔颜色和宽度 turtle.pencolor('green') turtle.pensize(3) turtle.left(90) # 画树函数 def draw_tree(l, angle): if l < 5: return turtle.forward(l) turtle.right(angle) draw_tree(l - random.randint(10, 20), angle) turtle.left(2 * angle) draw_tree(l - random.randint(10, 20), angle) turtle.right(angle) turtle.backward(l) # 调用函数画树 draw_tree(100, 30) # 控制窗口不关闭 turtle.done()