import tkinter as tk
import random
import math

root = tk.Tk()
root.title("烟花测试")
root.geometry("800x600")

canvas = tk.Canvas(root, bg="black")
canvas.pack(fill="both", expand=True)

particles = []

def launch():
    x = random.randint(200, 600)
    y = random.randint(150, 300)
    color = random.choice(["red","yellow","cyan","white","orange"])
    for i in range(60):
        angle = random.uniform(0, 2*math.pi)
        speed = random.uniform(2, 6)
        dx = math.cos(angle)*speed
        dy = math.sin(angle)*speed
        pid = canvas.create_oval(x-2, y-2, x+2, y+2, fill=color, outline="")
        particles.append([pid, dx, dy, 60])

def animate():
    alive = []
    for pid, dx, dy, life in particles:
        canvas.move(pid, dx, dy)
        life -= 1
        if life > 0:
            alive.append([pid, dx, dy, life])
    particles[:] = alive

    if random.random() < 0.05:
        launch()

    root.after(30, animate)

launch()
animate()
root.mainloop()