请用python turtle写一段递归画树的程序,但需要有粉色的花瓣随机飘零的动态效果
时间: 2024-06-01 14:10:31 浏览: 11
import turtle
import random
def draw_tree(branch_len, pen_size):
if branch_len > 5:
turtle.pensize(pen_size)
turtle.forward(branch_len)
turtle.right(20)
draw_tree(branch_len - 10, pen_size - 1)
turtle.left(40)
draw_tree(branch_len - 10, pen_size - 1)
turtle.right(20)
turtle.backward(branch_len)
def draw_flower(petal_num):
turtle.pencolor('pink')
turtle.fillcolor('pink')
turtle.begin_fill()
for i in range(petal_num):
turtle.circle(20, 360/petal_num)
turtle.left(360/petal_num)
turtle.end_fill()
def snowflake():
turtle.hideturtle()
turtle.speed('fastest')
turtle.pensize(3)
turtle.right(90)
turtle.penup()
turtle.backward(200)
turtle.pendown()
turtle.pencolor('brown')
draw_tree(80, 10)
for i in range(30):
x = random.randint(-300, 300)
y = random.randint(100, 400)
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
draw_flower(5)
turtle.done()
snowflake()
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)