没有合适的资源?快使用搜索试试~ 我知道了~
Python放烟花代码(源码在里面).docx
需积分: 1 0 下载量 18 浏览量
2024-05-26
14:57:19
上传
评论
收藏 11KB DOCX 举报
温馨提示
试读
1页
Python放烟花代码(源码在里面).docx
资源推荐
资源详情
资源评论
import turtle
import random
import time
# 初始化屏幕
screen = turtle.Screen()
screen.bgcolor("black")
# 创建烟花类
class Firework:
def __init__(self, x, y):
self.x = x
self.y = y
self.colors = ["red", "orange", "yellow", "green", "blue", "purple", "white"]
self.turtle = turtle.Turtle()
self.turtle.speed(0)
self.turtle.hideturtle()
self.turtle.penup()
self.turtle.goto(x, y)
self.turtle.pendown()
def explode(self):
for _ in range(10):
color = random.choice(self.colors)
self.turtle.pencolor(color)
self.turtle.forward(random.randint(10, 50))
self.turtle.backward(random.randint(10, 50))
self.turtle.left(random.randint(10, 360))
self.turtle.clear()
# 创建烟花并爆炸
def create_firework():
x = random.randint(-250, 250)
y = random.randint(-200, -100)
firework = Firework(x, y)
firework.explode()
# 循环创建烟花
while True:
create_firework()
time.sleep(0.5)
turtle.done()
# 谢谢使用
资源评论
爱编程的小芒果
- 粉丝: 2493
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功