写一段Python烟花特效代码
时间: 2023-11-05 12:00:24 浏览: 91
以下是一个简单的Python烟花特效代码:
```python
import random
import time
import turtle
turtle.bgcolor("black")
# 创建烟花
def create_firework():
firework = turtle.Turtle()
firework.hideturtle()
firework.speed(0)
firework.penup()
firework.color("white")
firework.goto(random.randint(-300, 300), random.randint(-200, -100))
firework.pendown()
return firework
# 烟花爆炸
def explode(firework):
firework.clear()
for i in range(30):
firework.speed(0)
firework.penup()
firework.goto(random.randint(-300, 300), random.randint(-200, 200))
firework.pendown()
for i in range(10):
firework.forward(5)
firework.right(360/10)
time.sleep(0.1)
# 主函数
while True:
firework = create_firework()
explode(firework)
```
运行该代码,将会在窗口内不断地出现烟花特效。
阅读全文