python动态爱心烟花代码
时间: 2023-07-23 10:35:10 浏览: 117
以下是一个Python动态爱心烟花代码,您可以复制:
```python
import turtle
import random
turtle.bgcolor("black")
turtle.speed(0)
colors = ["red", "yellow", "blue", "green", "purple", "white", "orange"]
def draw_heart(x, y, size, fill_color):
turtle.penup()
turtle.setpos(x, y)
turtle.pendown()
turtle.color(fill_color)
turtle.begin_fill()
turtle.left(45)
turtle.forward(size)
turtle.circle(size/2, 180)
turtle.right(90)
turtle.circle(size/2, 180)
turtle.forward(size)
turtle.end_fill()
def draw_fireworks():
x = random.randint(-350, 350)
y = random.randint(-250, 250)
size = random.randint(50, 150)
fill_color = random.choice(colors)
draw_heart(x, y, size, fill_color)
for i in range(10):
turtle.color(random.choice(colors))
turtle.pensize(i/5)
turtle.forward(i*4)
turtle.left(170)
turtle.penup()
turtle.setpos(x, y)
turtle.pendown()
turtle.color("white")
turtle.dot(size/10)
while True:
draw_fireworks()
```
运行该代码后,将会在屏幕中央随机出现爱心烟花,并伴随着彩色烟花效果。
阅读全文