import pygame
import math

# 初始化
pygame.init()
WIDTH, HEIGHT = 1000, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("上帝视角 - 八大行星")
clock = pygame.time.Clock()
font = pygame.font.SysFont("simhei", 16)

# 颜色
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
SUN_COL = (255, 200, 0)

# 行星数据：名字, 半径, 轨道半径, 速度, 颜色
PLANETS = [
    ("水星", 8, 100, 0.02, (120, 120, 120)),
    ("金星", 12, 140, 0.015, (255, 160, 0)),
    ("地球", 13, 180, 0.012, (50, 100, 255)),
    ("火星", 10, 220, 0.01, (255, 80, 50)),
    ("木星", 30, 290, 0.008, (200, 120, 70)),
    ("土星", 26, 350, 0.007, (230, 200, 80)),
    ("天王星", 18, 400, 0.005, (100, 200, 230)),
    ("海王星", 17, 440, 0.004, (50, 80, 200)),
]

# 详细介绍
INFO = {
    "水星": "直径:4879km 公转:88日",
    "金星": "直径:12104km 公转:225日",
    "地球": "直径:12742km 公转:365日",
    "火星": "直径:6779km 公转:687日",
    "木星": "直径:139822km 气态巨行星",
    "土星": "直径:116464km 气态巨行星",
    "天王星": "直径:50724km 冰巨行星",
    "海王星": "直径:49244km 冰巨行星"
}

angle = 0

# 主循环
running = True
while running:
    screen.fill(BLACK)
    cx, cy = WIDTH//2, HEIGHT//2

    # 退出事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # 画太阳
    pygame.draw.circle(screen, SUN_COL, (cx, cy), 40)

    # 画行星
    for i, (name, r, orbit, speed, col) in enumerate(PLANETS):
        a = angle * speed
        x = cx + orbit * math.cos(a)
        y = cy + orbit * math.sin(a)
        # 轨道
        pygame.draw.circle(screen, (50, 50, 50), (cx, cy), orbit, 1)
        # 行星
        pygame.draw.circle(screen, col, (int(x), int(y)), r)
        # 名字
        text = font.render(name, True, WHITE)
        screen.blit(text, (x+15, y+10))

    # 画信息
    ty = 20
    for name, text in INFO.items():
        t = font.render(f"{name}: {text}", True, WHITE)
        screen.blit(t, (20, ty))
        ty += 25

    angle += 1
    pygame.display.update()
    clock.tick(60)

pygame.quit()
