酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

帮我写一份关于祝福生日快乐的代码,要求酷炫,高级,科幻

# 科幻风格生日快乐祝福程序 下面是一个使用Python和Pygame库创建的酷炫科幻风格生日快乐动画: ```python import pygame import random import math import time from pygame import gfxdraw # 初始化pygame pygame.init() # 设置窗口 WIDTH, HEIGHT = 1200, 800 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("科幻生日快乐") # 颜色定义 BLACK = (0, 0, 0) CYAN = (0, 255, 255) MAGENTA = (255, 0, 255) YELLOW = (255, 255, 0) WHITE = (255, 255, 255) # 加载字体 try: font_large = pygame.font.Font(None, 120) font_medium = pygame.font.Font(None, 60) font_small = pygame.font.Font(None, 30) except: font_large = pygame.font.SysFont('arial', 120) font_medium = pygame.font.SysFont('arial', 60) font_small = pygame.font.SysFont('arial', 30) # 粒子系统 class Particle: def __init__(self, x, y): self.x = x self.y = y self.size = random.randint(2, 5) self.color = random.choice([CYAN, MAGENTA, YELLOW]) self.speed = random.uniform(1, 3) self.angle = random.uniform(0, math.pi * 2) self.life = random.randint(30, 90) def update(self): self.x += math.cos(self.angle) * self.speed self.y += math.sin(self.angle) * self.speed self.life -= 1 if self.life <= 0: self.size = max(0, self.size - 0.1) def draw(self, surface): alpha = min(255, self.life * 3) color = (self.color[0], self.color[1], self.color[2], alpha) gfxdraw.filled_circle(surface, int(self.x), int(self.y), int(self.size), color) # 星空 stars = [] for _ in range(200): x = random.randint(0, WIDTH) y = random.randint(0, HEIGHT) size = random.uniform(0.5, 2) speed = random.uniform(0.05, 0.2) stars.append([x, y, size, speed]) # 文字动画 class TextAnimation: def __init__(self, text, font, color, y_pos): self.text = text self.font = font self.color = color self.y_pos = y_pos self.alpha = 0 self.target_alpha = 255 self.surface = self.font.render(self.text, True, self.color) self.x_pos = (WIDTH - self.surface.get_width()) // 2 self.particles = [] def update(self): if self.alpha < self.target_alpha: self.alpha = min(self.alpha + 5, self.target_alpha) # 添加粒子效果 if random.random() < 0.3: for _ in range(3): px = random.randint(self.x_pos, self.x_pos + self.surface.get_width()) py = random.randint(self.y_pos, self.y_pos + self.surface.get_height()) self.particles.append(Particle(px, py)) # 更新粒子 for particle in self.particles[:]: particle.update() if particle.size <= 0: self.particles.remove(particle) def draw(self, surface): text_surface = self.font.render(self.text, True, self.color) text_surface.set_alpha(self.alpha) surface.blit(text_surface, (self.x_pos, self.y_pos)) for particle in self.particles: particle.draw(surface) # 创建文本动画 main_text = TextAnimation("生日快乐!", font_large, CYAN, HEIGHT // 3) sub_text = TextAnimation("愿你的未来如星辰般璀璨", font_medium, MAGENTA, HEIGHT // 2) footer_text = TextAnimation("AI祝福系统 v1.0", font_small, WHITE, HEIGHT - 50) # 主循环 clock = pygame.time.Clock() running = True start_time = time.time() while running: current_time = time.time() - start_time for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # 更新星空 for star in stars: star[1] += star[3] if star[1] > HEIGHT: star[1] = 0 star[0] = random.randint(0, WIDTH) # 更新文本动画 if current_time > 1: main_text.update() if current_time > 2: sub_text.update() if current_time > 3: footer_text.update() # 绘制 screen.fill(BLACK) # 绘制星空 for star in stars: brightness = min(255, int(star[2] * 150)) pygame.draw.circle(screen, (brightness, brightness, brightness), (int(star[0]), int(star[1])), int(star[2])) # 绘制文本 main_text.draw(screen) sub_text.draw(screen) footer_text.draw(screen) # 添加一些随机闪光 if random.random() < 0.05: x, y = random.randint(0, WIDTH), random.randint(0, HEIGHT) pygame.draw.circle(screen, WHITE, (x, y), random.randint(2, 5)) pygame.display.flip() clock.tick(60) pygame.quit() ``` ## 代码说明 1. 这个程序创建了一个科幻风格的生日快乐动画,包含以下元素: - 动态星空 - 粒子效果的文字动画 - 渐入渐出的文字效果 - 随机闪光效果 2. 运行要求: - 需要安装Python和Pygame库 - 安装命令: `pip install pygame` 3. 自定义选项: - 可以修改文字内容、颜色和位置 - 可以调整粒子数量和效果 - 可以更改动画速度和持续时间 ## 三条额外需要注意的逻辑点 1. 粒子系统使用了透明度渐变来创建淡出效果,注意粒子生命周期的管理。 2. 文字动画采用了分阶段显示,确保不同文本按顺序出现。 3. 星空使用简单的垂直移动算法,注意边界处理使星星循环出现。 [2025-06-23 15:00:40 | AI写代码神器 | 1528点数解答]

相关提问