前言
跨年倒计时20天?我已经开始整烟花了,虽然不是很好看吧,但是也能将就看看 😥
这个的背景图,音乐,还有文字都是可以自己修改的哦
效果展示

导入库
import random
import pygame as py
import tkinter as tk
from time import time, sleep
from tkinter import filedialog
from PIL import Image, ImageTk
from math import sin, cos, radians
from random import choice, uniform, randint
实现代码
生成随机颜色
原码.点击即可领取 (备注:苏)
def randomcolor():
#生成随机颜色
colArr = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
color = ""
for i in range(6):
color += colArr[random.randint(0,14)]
return "#"+color
GRAVITY = 0.06
#重力变量
colors = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'seagreen','indigo', 'cornflowerblue', 'pink']
#颜色列表
属性
Generic class for particles
particles are emitted almost randomly on the sky, forming a round of circle (a star) before falling and getting removed
from canvas
Attributes(属性):
- id: 粒子的id
- x, y: 粒子的坐标
- vx, vy: 粒子在对应坐标的变化速度
- total:一颗烟花里的粒子总数
- age: 粒子在画布上停留的时间
- color: 自我移植
- cv: 画布
- lifespan: 粒子在画布上停留的时间
粒子运动的速度
这个里面的新年快乐是可以自己更改的哦
python学习交流Q群:465688591 ### 源码领取
class part:
#为每一个烟花绽放出来的粒子单独构建一个类的对象 ,每个粒子都会有一些重要的属性,决定它的外观(大小、颜色)、移动速度等
def __init__(self, cv, idx, total, explosion_speed, x=

使用Python和pygame库制作的粒子烟花效果展示。通过生成随机颜色、设定粒子速度、xy轴位移和膨胀效果,实现粒子的生命周期管理。用户可自定义背景、音乐和文字内容。
最低0.47元/天 解锁文章
2万+

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



