import tkinter as tk
import math
import random

# 主窗口初始化
root = tk.Tk()
root.title("【超复杂动态图形】Python终极可视化")
root.geometry("1000x800")
root.configure(bg="#000000")

# 画布（核心绘图区域）
canvas = tk.Canvas(root, width=1000, height=800, bg="black", highlightthickness=0)
canvas.pack()

# 全局动画参数
angle = 0
scale = 1.0
colors = [
    "#FF006E", "#3A0CA3", "#4CC9F0", "#F72585", "#7209B7",
    "#4361EE", "#4895EF", "#560BAD", "#F15BB5", "#9B5DE5"
]

# ====================== 绘制超复杂组合图形 ======================
def draw_super_complex_graphic(angle):
    canvas.delete("all")  # 清空画布
    cx, cy = 500, 400     # 中心点
    
    # ========== 1. 多层分形圆环 ==========
    for r in range(20, 380, 12):
        color = colors[(r // 12) % len(colors)]
        points = []
        for i in range(0, 360, 8):
            rad = math.radians(i + angle)
            wave = math.sin(rad * 6 + angle / 20) * 20
            x = cx + (r + wave) * math.cos(rad)
            y = cy + (r + wave) * math.sin(rad)
            points.append((x, y))
        canvas.create_polygon(points, fill="", outline=color, width=2, smooth=True)

    # ========== 2. 动态旋转星型结构 ==========
    for s in range(50, 300, 50):
        star_points = []
        for i in range(0, 360, 36):
            rad = math.radians(i + angle * 2)
            r = s if i % 72 == 0 else s // 2
            x = cx + r * math.cos(rad)
            y = cy + r * math.sin(rad)
            star_points.append((x, y))
        canvas.create_polygon(star_points, fill="", outline=colors[s//50 % len(colors)], width=2)

    # ========== 3. 螺旋数学曲线 ==========
    spiral = []
    for i in range(0, 1440, 8):
        rad = math.radians(i)
        r = 2 + i / 14
        wave = math.cos(rad * 8 + angle / 10) * 15
        x = cx + (r + wave) * math.cos(rad + angle / 30)
        y = cy + (r + wave) * math.sin(rad + angle / 30)
        spiral.append((x, y))
    canvas.create_line(spiral, fill="#00FFFF", width=2, smooth=True)

    # ========== 4. 动态粒子光环 ==========
    for i in range(80):
        rad = math.radians(i * 4.5 + angle * 3)
        dist = 100 + math.sin(angle / 15 + i) * 60
        x = cx + dist * math.cos(rad)
        y = cy + dist * math.sin(rad)
        size = 3 + math.sin(angle + i) * 2
        canvas.create_oval(x-size, y-size, x+size, y+size, fill=colors[i % len(colors)])

    # ========== 5. 中心爆炸图形（已修复！） ==========
    for i in range(0, 360, 15):
        rad = math.radians(i + angle)
        length = 80 + math.sin(angle * 2 + i) * 40
        x2 = cx + length * math.cos(rad)
        y2 = cy + length * math.sin(rad)
        # 修复：加了 % len(colors) 防止越界
        canvas.create_line(cx, cy, x2, y2, fill=colors[(i//15) % len(colors)], width=3)

    # ========== 6. 随机漂浮装饰图形 ==========
    for _ in range(15):
        x = random.randint(0, 1000)
        y = random.randint(0, 800)
        s = random.randint(10, 40)
        canvas.create_oval(x-s, y-s, x+s, y+s, fill="", outline=random.choice(colors), width=1)

# ====================== 动画循环 ======================
def animate():
    global angle
    angle += 0.4
    draw_super_complex_graphic(angle)
    root.after(20, animate)

# 启动动画
animate()

# 界面底部文字
label = tk.Label(root, text="✨ Python 超复杂动态图形界面 | 纯Tkinter实现 ✨",
                fg="white", bg="black", font=("Arial", 14))
label.place(relx=0.5, rely=0.96, anchor="center")

# 运行主循环
root.mainloop()