前言
2023 已经接近尾声了,2024 即将到来,本文我们用 Python 送你一场跨年烟花秀。

我们用到的 Python 模块包括:tkinter、PIL、time、random、math,如果第三方模块没有装的话,pip install 一下即可,下面看一下代码实现。
导库
import tkinter as tk
from PIL import Image, ImageTk
from time import time, sleep
from random import choice, uniform, randint
from math import sin, cos, radians
烟花颜色
colors = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'seagreen', 'indigo', 'cornflowerblue']
定义烟花类
class fireworks:
def __init__(self, cv, idx, total, explosion_speed, x=0., y=0., vx=0., vy=0., size=2., color='red', lifespan=2, **kwargs):
self.id = idx
# 烟花绽放 x 轴
self.x = x
# 烟花绽放 x 轴
self.y = y
self.initial_speed = explosion_speed
# 外放 x 轴速度
self.vx = vx
# 外放 y 轴速度
self.vy = vy
# 绽放的粒子数
self.total = total
# 已停留时间
self.age = 0
# 颜色
self.color = color
# 画布
self.cv = cv
self.cid = self.cv.create_ov

最低0.47元/天 解锁文章
5435

被折叠的 条评论
为什么被折叠?



