没有合适的资源?快使用搜索试试~ 我知道了~
python烟花代码
资源推荐
资源详情
资源评论
Python 绘制烟花效果的示例代码:
import turtle
import random
# 设置画布
screen = turtle.Screen()
screen.bgcolor("black")
# 创建烟花粒子类
class Particle(turtle.Turtle):
def __init__(self, x, y):
turtle.Turtle.__init__(self)
self.shape("circle")
self.color("red")
self.penup()
self.speed(0)
self.goto(x, y)
self.dx = random.uniform(-3, 3)
self.dy = random.uniform(5, 15)
self.gravity = 0.1
def update(self):
self.dy -= self.gravity
self.setx(self.xcor() + self.dx)
self.sety(self.ycor() + self.dy)
if self.ycor() < -300:
self.goto(random.randint(-200, 200), random.randint(300, 400))
self.dy = random.uniform(5, 15)
# 创建烟花爆炸类
class Firework(turtle.Turtle):
def __init__(self):
turtle.Turtle.__init__(self)
self.shape("circle")
self.color("white")
self.penup()
self.speed(0)
self.goto(random.randint(-200, 200), random.randint(300, 400))
self.dy = random.uniform(5, 15)
self.particles = []
def explode(self):
for _ in range(20):
资源评论
大宝贱
- 粉丝: 360
- 资源: 478
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功