import pygame
import numpy as np
import math
import time
import random
pygame.init()
WIDTH, HEIGHT = 1280, 720
CENTER = np.array([WIDTH // 2, HEIGHT // 2])
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("The Memory of Ash and Silver")
clock = pygame.time.Clock()
font_path = pygame.font.match_font('georgia') # Can use a serif font for poetic elegance
font = pygame.font.Font(font_path, 36)
# Colors
BLACK = (0, 0, 0)
def glow_text(text, alpha, size=48):
f = pygame.font.Font(font_path, size)
text_surf = f.render(text, True, (255, 255, 255))
text_surf.set_alpha(alpha)
return text_surf
class Particle:
def __init__(self, pos, color, glow=4):
self.original_pos = np.array(pos, dtype=float)
self.pos = np.copy(self.original_pos)
self.target = np.copy(self.pos)
self.velocity = np.zeros(2)
self.color = color
self.glow = glow
def update(self, dt):
direction = self.target - self.pos
dist = np.linalg.norm(direction)
if dist > 1:
direction /= dist
self.velocity += direction * 0.1
self.velocity *= 0.92 # drag
self.pos += self.velocity * dt
def draw(self, surf):
x, y = int(self.pos[0]), int(self.pos[1])
for i in range(self.glow):
alpha = int(255 / (i + 1))
r = max(1, int(3 / (i + 0.5)))
glow_surf = pygame.Surface((r * 2, r * 2), pygame.SRCALPHA)
pygame.draw.circle(glow_surf, self.color + (alpha,), (r, r), r)
surf.blit(glow_surf, (x - r, y - r))
class ParticleSystem:
def __init__(self, count):
self.particles = [Particle(np.random.rand(2) * [WIDTH, HEIGHT], (200, 200, 255)) for _ in range(count)]
def move_to_shape(self, shape_points, color_func=None):
for i, p in enumerate(self.particles):
idx = i % len(shape_points)
p.target = shape_points[idx]
if color_func:
p.color = color_func(shape_points[idx], i / len(self.particles))
def update(self, dt):
for p in self.particles:
p.update(dt)
def draw(self, surf):
for p in self.particles:
p.draw(surf)
def generate_circle(center, radius, count):
return [center + np.array([math.cos(2 * math.pi * i / count), math.sin(2 * math.pi * i / count)]) * radius
for i in range(count)]
def generate_line(start, end, count):
return [start + (end - start) * (i / count) for i in range(count)]
def generate_human_shape(center, scale):
"""Simple figure with head, body, arms, legs"""
points = []
# Head
points += generate_circle(center + [0, -scale], scale * 0.3, 30)
# Body
points += generate_line(center + [0, -0.7 * scale], center + [0, 0.7 * scale], 50)
# Arms
points += generate_line(center + [-0.5*scale, 0], center + [0.5*scale, 0], 30)
# Legs
points += generate_line(center + [0, 0.7*scale], center + [-0.3*scale, scale], 20)
points += generate_line(center + [0, 0.7*scale], center + [0.3*scale, scale], 20)
return points
# STORY ELEMENTS
story_sentences = [
"He was born in silence, where winds had forgotten to sing.",
"Dust was his cradle, stars his lullaby.",
"He walked through ruins older than memory, barefoot on the ashes of time.",
"With every step, sand rose — a thousand particles remembering light.",
"He knelt, and the dust remembered form — a boy, arms stretched toward sunlight.",
"And the world, long dead... blinked.",
"The sky cracked open in silver dreams.",
"From that fracture, color returned, trembling, healing.",
"And thus began the return — not of kings, but kindness.",
"Not of empires, but echoing laughter by streams reborn.",
"He was not a god... but a gardener of memory.",
"And the seeds he sowed? They bloomed into waking hope.",
"The boy of ash and starlight vanished — but in his place, Life learned to dream again."
]
particle_system = ParticleSystem(800)
# Main Loop
running = True
sentence_index = 0
next_sentence_time = time.time() + 2
fade_alpha = 0
fade_in = True
text_surface = None
text_lifetime = 4 # seconds
sentence_start_time = time.time()
staged_shapes = [
lambda: generate_circle(CENTER, 100, 300),
lambda: generate_human_shape(CENTER + [0, 30], 100),
lambda: [np.array([random.randint(0, WIDTH), random.randint(HEIGHT // 2, HEIGHT)]) for _ in range(500)],
lambda: generate_line(np.array([200, HEIGHT // 2]), np.array([WIDTH - 200, HEIGHT // 2]), 300),
lambda: generate_circle(CENTER, 200, 500)
]
def sky_color(pos, phase=0):
"""Return glowing star color based on Y position and time phase."""
intensity = int(180 + 50 * math.sin(pos[1] * 0.01 + phase))
return (intensity, intensity, 255)
while running:
dt = clock.tick(60) / 10.0
screen.fill(BLACK)
current_time = time.time()
if sentence_index < len(story_sentences):
# Manage text fade in/out
elapsed = current_time - sentence_start_time
progress = elapsed / text_lifetime
if fade_in:
fade_alpha = min(255, int(progress * 255))
else:
fade_alpha = max(0, 255 - int(progress * 255))
if fade_in and fade_alpha >= 255:
fade_in = False
sentence_start_time = current_time # reset for fade out
elif not fade_in and fade_alpha <= 0:
sentence_index += 1
fade_in = True
sentence_start_time = current_time
if sentence_index < len(story_sentences):
# Prepare particles for next shape
idx = sentence_index % len(staged_shapes)
new_shape = staged_shapes[idx]()
particle_system.move_to_shape(new_shape, color_func=sky_color)
else:
fade_alpha = 0
if sentence_index < len(story_sentences):
current_sentence = story_sentences[sentence_index]
text_surface = glow_text(current_sentence, fade_alpha, size=48)
screen.blit(text_surface, (WIDTH // 2 - text_surface.get_width() // 2, 60))
particle_system.update(dt)
particle_system.draw(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
pygame.quit()