import tkinter as tk
import random
import math
import pygame

# ===================== 新年烟花主程序 =====================
root = tk.Tk()
root.title("🧨 2026 马年新春烟花大会 🧨")
root.geometry("1000x700")
root.configure(bg="#000010")

canvas = tk.Canvas(root, width=1000, height=700, bg="#000010", highlightthickness=0)
canvas.pack()

# 初始化音乐
pygame.mixer.init()
try:
    # 喜庆新年背景音乐（你也可以替换成自己的 mp3）
    pygame.mixer.music.load("new_year.mp3")
    pygame.mixer.music.set_volume(0.4)
    pygame.mixer.music.play(-1)
except:
    print("未找到音乐文件，继续播放烟花～")

particles = []

# 新年喜庆颜色（红、金、橙）
NEW_YEAR_COLORS = [
    "#ff2222", "#ff4400", "#ff6600", "#ffcc00", "#ffd700",
    "#ffee00", "#ff0033", "#ff5555", "#ffbb22", "#ffffff"
]

class Particle:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        angle = random.uniform(0, math.pi * 2)
        speed = random.uniform(4, 8)
        self.vx = math.cos(angle) * speed
        self.vy = math.sin(angle) * speed
        self.color = random.choice(NEW_YEAR_COLORS)
        self.size = random.randint(3, 6)
        self.life = 90

    def update(self):
        self.x += self.vx
        self.y += self.vy
        self.vy += 0.13
        self.vx *= 0.97
        self.vy *= 0.97
        self.life -= 1

    def draw(self):
        canvas.create_oval(
            self.x - self.size, self.y - self.size,
            self.x + self.size, self.y + self.size,
            fill=self.color, outline=""
        )

# 鼠标点击放烟花
def fire(event):
    for _ in range(random.randint(100, 160)):
        particles.append(Particle(event.x, event.y))

# 动画循环
def animate():
    canvas.delete("all")
    alive = []
    for p in particles:
        if p.life > 0:
            p.update()
            p.draw()
            alive.append(p)
    particles[:] = alive
    root.after(16, animate)

# 绑定点击
canvas.bind("<Button-1>", fire)

# 绘制新年文字
canvas.create_text(500, 80, text="🧨 2026 马年大吉 · 新春快乐 🧨",
                  fill="gold", font=("微软雅黑", 28, "bold"))

animate()
root.mainloop()