源码下载地址:https://download.csdn.net/download/mosquito_lover1/90295693
核心源码:
import pygame
import random
import math
from PIL import Image
import io
# 初始化pygame
pygame.init()
# 设置窗口
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("烟花秀")
# 添加字体设置
try:
# 使用更适合英文的字体
font = pygame.font.Font(None, 96) # None 使用默认字体,96是字体大小
except:
font = pygame.font.SysFont("arial", 96) # 备用字体
# 烟花粒子类
class Particle:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color
self.speed = random.uniform(3, 8)
self.angle = random.uniform(0, 2 * math.pi)
self.lifetime = 150
self.radius = 2.5
self.static_time = 30 # 静止时间(帧数)
self.is_static = False # 是否处于静止状态
def move(self):
if not self.is_static:
self.speed *= 0.97
self.x +&