import pygame
import random
import math
# Initialize Pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 1280, 720
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Sand Art Performance")
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GLOW_COLORS = [(255, 200, 100), (255, 150, 50), (255, 100, 0)]
# Fonts
font = pygame.font.Font(None, 48)
# Particle class
class Particle:
def __init__(self, x, y):
self.x = x
self.y = y
self.size = random.randint(2, 5)
self.color = random.choice(GLOW_COLORS)
self.velocity = [random.uniform(-1, 1), random.uniform(-1, 1)]
self.life = random.randint(50, 150)
def update(self):
self.x += self.velocity[0]
self.y += self.velocity[1]
self.life -= 1
def draw(self, surface):
if self.life > 0:
pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.size)
# Text display function
def display_text(text, y_offset, alpha):
text_surface = font.render(text, True, WHITE)
text_surface.set_alpha(alpha)
text_rect = text_surface.get_rect(center=(WIDTH // 2, y_offset))
screen.blit(text_surface, text_rect)
# Fade-in and fade-out text
def animate_text(text, duration):
alpha_step = 255 / (duration // 2)
alpha = 0
for _ in range(duration // 2):
screen.fill(BLACK)
alpha += alpha_step
display_text(text, 50, int(alpha))
pygame.display.flip()
pygame.time.delay(10)
for _ in range(duration // 2):
screen.fill(BLACK)
alpha -= alpha_step
display_text(text, 50, int(alpha))
pygame.display.flip()
pygame.time.delay(10)
# Particle system
particles = []
def spawn_particles(count, center_x, center_y, spread=100):
for _ in range(count):
angle = random.uniform(0, 2 * math.pi)
radius = random.uniform(0, spread)
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
particles.append(Particle(x, y))
def update_particles():
for particle in particles[:]:
particle.update()
if particle.life <= 0:
particles.remove(particle)
def draw_particles(surface):
for particle in particles:
particle.draw(surface)
# Main loop
def main():
clock = pygame.time.Clock()
running = True
# Scene 1: Introduction
story = [
"In the beginning, there was only silence.",
"Then came the first whisper of creation...",
"Particles danced, forming shapes from the void."
]
for sentence in story:
animate_text(sentence, 2000)
spawn_particles(200, WIDTH // 2, HEIGHT // 2, spread=200)
# Particle animation
for _ in range(100):
screen.fill(BLACK)
update_particles()
draw_particles(screen)
pygame.display.flip()
clock.tick(60)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if __name__ == "__main__":
main()