import pygame import math import random pygame.init() W, H = 1000, 1000 CX, CY = W // 2, H // 2 BLACK = (0, 0, 0) TITLE="刘淑涵天天开心" SUB="送你一束不会枯萎的玫瑰" TEXT_Y=680 screen = pygame.display.set_mode((W, H)) pygame.display.set_caption(TITLE) clock = pygame.time.Clock() # ---------------- 玫瑰图 ---------------- rose_img = pygame.image.load("rose_glow.png").convert_alpha() ROSE_BASE = 620 # ---------------- 爱心形状 ---------------- HEART_PTS = [] for k in range(0, 360, 18): a = math.radians(k) x = 16 * math.sin(a) ** 3 y = -(13 * math.cos(a) - 5 * math.cos(2 * a) - 2 * math.cos(3 * a) - math.cos(4 * a)) HEART_PTS.append((x, y)) def draw_heart(surf, x, y, size, color, width=0): pts = [(x + px * size / 16, y + py * size / 16) for px, py in HEART_PTS] pygame.draw.polygon(surf, color, pts, width) # ---------------- 飞行的爱心 ---------------- COLORS = [(255, 105, 180), (255, 160, 200), (200, 90, 220), (255, 90, 150)] class Heart: def __init__(self): self.reset(True) def reset(self, anywhere=False): self.x = random.uniform(0, W) self.y = random.uniform(0, H) if anywhere else random.choice([-20, H + 20]) ang = random.uniform(0, 2 * math.pi) spd = random.uniform(1.2, 3.6) self.vx = math.cos(ang) * spd self.vy = math.sin(ang) * spd - 0.4 self.size = random.uniform(10, 24) self.color = random.choice(COLORS) def update(self): self.x += self.vx self.y += self.vy self.vx += random.uniform(-0.12, 0.12) self.vy += random.uniform(-0.12, 0.08) if not (-80 < self.x < W + 80 and -80 < self.y < H + 80): self.reset() hearts = [Heart() for _ in range(80)] # ---------------- 残影画布 ---------------- trail = pygame.Surface((W, H)) trail.fill(BLACK) fade = pygame.Surface((W, H)) fade.fill(BLACK) fade.set_alpha(26) # ---------------- 光环粒子 ---------------- ring_parts = [] for i in range(260): a = 2 * math.pi * i / 260 ring_parts.append({"a": a, "sz": random.uniform(1.5, 3.2)}) try: font = pygame.font.SysFont("Microsoft YaHei", 38, bold=True) except Exception: font = pygame.font.SysFont(None, 44) t = 0.0 running = True while running: for e in pygame.event.get(): if e.type == pygame.QUIT: running = False elif e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE: running = False t += 0.016 rot = t * 0.20 pulse = 1 + 0.045 * math.sin(t * 1.2) screen.fill(BLACK) trail.blit(fade, (0, 0)) # 残影衰减 for h in hearts: # 飞行爱心(留光轨) h.update() draw_heart(trail, h.x, h.y, h.size, h.color) pygame.draw.circle(trail, (255, 190, 225), (int(h.x), int(h.y - 1)), 1) base_y = CY + 250 # 底部发光环 ring_rx, ring_ry = 310, 78 pts = [(CX + ring_rx * math.cos(math.radians(d)), base_y + ring_ry * math.sin(math.radians(d))) for d in range(0, 361, 4)] pygame.draw.lines(screen, (255, 150, 200), True, pts, 2) for p in ring_parts: a = p["a"] + rot * 2 pygame.draw.circle(screen, (255, 225, 242), (int(CX + ring_rx * math.cos(a)), int(base_y + ring_ry * math.sin(a))), int(p["sz"])) trail.set_alpha(120) # 叠上爱心光轨 screen.blit(trail, (0, 0), special_flags=pygame.BLEND_RGB_ADD) trail.set_alpha(255) rose = pygame.transform.rotozoom(rose_img, math.degrees(rot) * 0.6, (ROSE_BASE / rose_img.get_width()) * pulse) screen.blit(rose, (CX - rose.get_width() // 2, CY - 200 - rose.get_height() // 2)) txt1 = font.render("刘淑涵天天开心", True, (200, 140, 255)) screen.blit(txt1, (CX - txt1.get_width() // 2, H - 220)) txt2 = font.render("送你一束不会枯萎的玫瑰", True, (255, 175, 210)) screen.blit(txt2, (CX - txt2.get_width() // 2, H - 110)) pygame.display.update() clock.tick(60) pygame.quit()