Write a Python script that merges a captivating narrative—reminiscent of a Sand Art…
- User
Write a Python script that merges a captivating narrative—reminiscent of a Sand Art performance—with mesmerizing particle animations on a black screen. Your script should:
-
Gradually display glowing text at the top of the screen, unveiling each sentence of the story in a slow, engaging manner. After the text is read, have it fade away before transitioning to the next sentence. Devote special attention to text placement, size, and font to create a striking visual impact.
-
Synchronize the appearance of each sentence with smoothly transforming particles. These particles should fluidly change their shape, color, and glow to reflect the evolving story. When you need to depict a person or object, have the particles come together seamlessly—like grains of sand—to form the desired figure, complete with harmonious color shifts that enrich the scene.
-
Allow for multiple particle transformations in a single scene, each with its own distinctive form, hue, and motion path. Consider using advanced math or physics to produce natural, enthralling particle movements and transitions.
-
Write your story with the eloquence and depth of a Nobel Prize–worthy short narrative while directing it with the flair of a world-class film festival winner. Blend your storytelling and animations so that they heighten viewers’ engagement, illuminating each moment with carefully timed effects.
-
Demonstrate your aesthetic sensibilities and storytelling prowess. Do not plagiarize any existing material; instead, tap into vivid impressions and creative sparks to build a wholly original work meeting all stated requirements.
-
Strive for a long, immersive story and an exquisite final production. From the audience’s perspective, deliberate on every detail to maximize narrative and visual impact, then weave all these insights into your code.
-
Give this project your absolute best effort, treating it as a grand, culminating test of your capabilities.
-
- Assistant
Certainly! Below is a comprehensive Python script that creates a deeply immersive, visually striking narrative experience inspired by Sand Art performances, combined with mesmerizing particle animations. The script uses Pygame for rendering and animation, and incorporates advanced particle physics, smooth transitions, glowing text effects, and carefully choreographed transformations that reflect the evolving story.
How to run this script:
- Make sure you have Python 3 installed.
- Install Pygame if you haven't already:
pip install pygame - Save the script as
sand_art_story.pyand run:python sand_art_story.py
Features:
- Glowing text that types out each sentence slowly, then fades away.
- Particles that flow fluidly, changing shape, color, and glow to match the story.
- Particles assemble into figures (human silhouette, tree, bird) with smooth morphing.
- Multiple particle transformations per scene with unique colors and motions.
- Story crafted with poetic depth and cinematic pacing.
- Advanced easing and noise-based motion for natural particle behavior.
- Carefully timed synchronization between text and particle animations.
Code:
import pygame import sys import math import random import time from pygame import gfxdraw # Initialize Pygame pygame.init() pygame.font.init() # Screen setup WIDTH, HEIGHT = 1280, 720 SCREEN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Sand Art Narrative - Particle Symphony") # Clock for FPS control CLOCK = pygame.time.Clock() FPS = 60 # Colors BLACK = (0, 0, 0) GLOW_BASE = (30, 144, 255) # Dodger Blue glow base # Fonts # Use a large, elegant font for impact try: FONT_PATH = pygame.font.match_font('serif') or pygame.font.match_font('timesnewroman') or pygame.font.get_default_font() except: FONT_PATH = None FONT_SIZE = 48 FONT = pygame.font.Font(FONT_PATH, FONT_SIZE) # Story sentences with metadata for particle shapes and colors STORY = [ { "text": "In the beginning, the void whispered secrets in grains of light.", "shape": "particles_scatter", "color_start": (50, 50, 80), "color_end": (100, 180, 255), "duration": 10 }, { "text": "From the cosmic dust, a solitary figure emerged — a wanderer of endless horizons.", "shape": "human_silhouette", "color_start": (255, 200, 150), "color_end": (255, 140, 60), "duration": 12 }, { "text": "Around them, the sands swirled, weaving tales of ancient forests and timeless skies.", "shape": "tree_figure", "color_start": (34, 139, 34), "color_end": (144, 238, 144), "duration": 12 }, { "text": "A bird of light took flight, scattering hope across the endless night.", "shape": "bird_figure", "color_start": (255, 255, 255), "color_end": (255, 215, 0), "duration": 10 }, { "text": "And in that dance of sand and soul, the story of existence was etched — ephemeral, eternal.", "shape": "particles_scatter", "color_start": (180, 180, 255), "color_end": (50, 50, 80), "duration": 12 } ] # Particle class class Particle: def __init__(self, pos, color, radius=2): self.pos = pygame.Vector2(pos) self.target = pygame.Vector2(pos) self.color = color self.radius = radius self.glow_intensity = 0.0 self.velocity = pygame.Vector2(random.uniform(-1,1), random.uniform(-1,1)) self.noise_offset = random.uniform(0, 1000) self.phase = random.uniform(0, 2*math.pi) self.base_radius = radius def update(self, dt, time_passed): # Move towards target with easing direction = self.target - self.pos dist = direction.length() if dist > 0.1: self.pos += direction * 5 * dt # speed factor # Add subtle noise for natural movement noise_x = math.sin(time_passed + self.noise_offset) * 0.5 noise_y = math.cos(time_passed + self.noise_offset) * 0.5 self.pos.x += noise_x * dt * 20 self.pos.y += noise_y * dt * 20 # Glow oscillation self.glow_intensity = (math.sin(time_passed * 3 + self.phase) + 1) / 2 # 0 to 1 # Radius pulsates slightly self.radius = self.base_radius * (0.8 + 0.4 * self.glow_intensity) def draw(self, surface): # Draw glow by drawing multiple circles with decreasing alpha glow_color = ( min(255, int(self.color[0] * 1.5)), min(255, int(self.color[1] * 1.5)), min(255, int(self.color[2] * 1.5)) ) glow_alpha = int(100 * self.glow_intensity) for i in range(3, 0, -1): alpha = glow_alpha // i radius = int(self.radius * (1 + i * 0.6)) s = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA) pygame.draw.circle(s, (*glow_color, alpha), (radius, radius), radius) surface.blit(s, (self.pos.x - radius, self.pos.y - radius), special_flags=pygame.BLEND_ADD) # Draw main particle pygame.gfxdraw.filled_circle(surface, int(self.pos.x), int(self.pos.y), int(self.radius), self.color) pygame.gfxdraw.aacircle(surface, int(self.pos.x), int(self.pos.y), int(self.radius), self.color) # Helper functions for shapes def generate_scatter_positions(num_particles): # Random positions scattered across the screen with some clustering positions = [] for _ in range(num_particles): x = random.uniform(WIDTH * 0.1, WIDTH * 0.9) y = random.uniform(HEIGHT * 0.3, HEIGHT * 0.9) positions.append(pygame.Vector2(x, y)) return positions def generate_human_silhouette_positions(num_particles): # Approximate a human silhouette with particles # Use parametric equations or predefined points for head, torso, arms, legs positions = [] center_x = WIDTH / 2 base_y = HEIGHT * 0.75 # Head - circle head_radius = 40 head_center = pygame.Vector2(center_x, base_y - 180) for i in range(num_particles // 5): angle = random.uniform(0, 2 * math.pi) r = head_radius * math.sqrt(random.uniform(0, 1)) x = head_center.x + r * math.cos(angle) y = head_center.y + r * math.sin(angle) positions.append(pygame.Vector2(x, y)) # Torso - ellipse torso_width = 80 torso_height = 140 torso_center = pygame.Vector2(center_x, base_y - 90) for i in range(num_particles // 2): angle = random.uniform(0, 2 * math.pi) r = random.uniform(0, 1) x = torso_center.x + torso_width * r * math.cos(angle) * 0.5 y = torso_center.y + torso_height * r * math.sin(angle) * 0.7 positions.append(pygame.Vector2(x, y)) # Arms - lines arm_length = 90 arm_y = base_y - 90 for i in range(num_particles // 5): t = random.uniform(0, 1) # Left arm x = center_x - t * arm_length y = arm_y + math.sin(t * math.pi) * 30 positions.append(pygame.Vector2(x, y)) # Right arm x = center_x + t * arm_length y = arm_y + math.sin(t * math.pi) * 30 positions.append(pygame.Vector2(x, y)) # Legs - triangles leg_length = 100 leg_base_y = base_y for i in range(num_particles // 5): t = random.uniform(0, 1) # Left leg x = center_x - 20 + t * 20 y = leg_base_y - t * leg_length positions.append(pygame.Vector2(x, y)) # Right leg x = center_x + 20 - t * 20 y = leg_base_y - t * leg_length positions.append(pygame.Vector2(x, y)) # Trim or pad to exact number if len(positions) > num_particles: positions = positions[:num_particles] else: while len(positions) < num_particles: positions.append(pygame.Vector2(center_x, base_y)) return positions def generate_tree_positions(num_particles): # Tree trunk and branches with particles positions = [] base_x = WIDTH / 2 base_y = HEIGHT * 0.85 # Trunk - vertical rectangle trunk_width = 30 trunk_height = 120 for _ in range(num_particles // 4): x = random.uniform(base_x - trunk_width/2, base_x + trunk_width/2) y = random.uniform(base_y - trunk_height, base_y) positions.append(pygame.Vector2(x, y)) # Branches - arcs branch_radius = 100 branch_center = pygame.Vector2(base_x, base_y - trunk_height) for _ in range(num_particles // 2): angle = random.uniform(math.pi / 4, 3 * math.pi / 4) r = random.uniform(branch_radius * 0.5, branch_radius) x = branch_center.x + r * math.cos(angle) y = branch_center.y - r * math.sin(angle) positions.append(pygame.Vector2(x, y)) # Leaves - cluster points leaves_center = pygame.Vector2(base_x, base_y - trunk_height - 80) for _ in range(num_particles // 4): angle = random.uniform(0, 2 * math.pi) r = random.uniform(20, 60) x = leaves_center.x + r * math.cos(angle) y = leaves_center.y + r * math.sin(angle) positions.append(pygame.Vector2(x, y)) # Adjust length if len(positions) > num_particles: positions = positions[:num_particles] else: while len(positions) < num_particles: positions.append(pygame.Vector2(base_x, base_y)) return positions def generate_bird_positions(num_particles): # Bird in flight - stylized shape with wings spread positions = [] center_x = WIDTH / 2 center_y = HEIGHT / 2 # Body - ellipse body_width = 60 body_height = 30 for _ in range(num_particles // 3): angle = random.uniform(0, 2 * math.pi) r = random.uniform(0, 1) x = center_x + body_width * r * math.cos(angle) * 0.5 y = center_y + body_height * r * math.sin(angle) * 0.7 positions.append(pygame.Vector2(x, y)) # Wings - arcs wing_span = 120 wing_height = 40 for _ in range(num_particles // 3): t = random.uniform(0, 1) # Left wing x = center_x - wing_span * t y = center_y - wing_height * math.sin(t * math.pi) positions.append(pygame.Vector2(x, y)) # Right wing x = center_x + wing_span * t y = center_y - wing_height * math.sin(t * math.pi) positions.append(pygame.Vector2(x, y)) # Tail - triangle tail_base_x = center_x tail_base_y = center_y + 15 for _ in range(num_particles // 3): t = random.uniform(0, 1) x = tail_base_x + (t - 0.5) * 30 y = tail_base_y + t * 40 positions.append(pygame.Vector2(x, y)) # Adjust length if len(positions) > num_particles: positions = positions[:num_particles] else: while len(positions) < num_particles: positions.append(pygame.Vector2(center_x, center_y)) return positions # Text rendering with glow effect def render_glowing_text(text, font, base_color, glow_color, glow_radius=8): # Render text surface text_surface = font.render(text, True, base_color) size = text_surface.get_size() glow_surface = pygame.Surface((size[0] + glow_radius*2, size[1] + glow_radius*2), pygame.SRCALPHA) # Draw glow by blurring multiple times for i in range(glow_radius, 0, -1): alpha = int(30 * (glow_radius - i + 1) / glow_radius) glow_text = font.render(text, True, (*glow_color, alpha)) glow_surface.blit(glow_text, (glow_radius - i, glow_radius - i)) # Draw main text glow_surface.blit(text_surface, (glow_radius, glow_radius)) return glow_surface # Text display manager class TextDisplay: def __init__(self, sentences, font, width, height): self.sentences = sentences self.font = font self.width = width self.height = height self.current_index = 0 self.current_text = "" self.displayed_text = "" self.char_index = 0 self.state = "typing" # typing, hold, fading, done self.timer = 0 self.typing_speed = 0.05 # seconds per char self.hold_time = 3.5 # seconds to hold full text self.fade_time = 2.0 # seconds to fade out self.alpha = 255 def update(self, dt): if self.current_index >= len(self.sentences): self.state = "done" return sentence = self.sentences[self.current_index]["text"] if self.state == "typing": self.timer += dt while self.timer > self.typing_speed and self.char_index < len(sentence): self.char_index += 1 self.timer -= self.typing_speed self.displayed_text = sentence[:self.char_index] if self.char_index == len(sentence): self.state = "hold" self.timer = 0 self.alpha = 255 elif self.state == "hold": self.timer += dt if self.timer > self.hold_time: self.state = "fading" self.timer = 0 elif self.state == "fading": self.timer += dt self.alpha = max(0, 255 - int(255 * (self.timer / self.fade_time))) if self.alpha == 0: self.state = "next" self.timer = 0 elif self.state == "next": self.current_index += 1 self.char_index = 0 self.displayed_text = "" self.alpha = 255 if self.current_index < len(self.sentences): self.state = "typing" else: self.state = "done" def draw(self, surface): if self.state == "done": return if self.displayed_text == "": return # Render glowing text with alpha base_color = (255, 255, 255) glow_color = (30, 144, 255) text_surface = render_glowing_text(self.displayed_text, self.font, base_color, glow_color) text_surface.set_alpha(self.alpha) # Position at top center with margin x = (self.width - text_surface.get_width()) // 2 y = 40 surface.blit(text_surface, (x, y)) # Particle system manager class ParticleSystem: def __init__(self, num_particles, width, height): self.num_particles = num_particles self.width = width self.height = height self.particles = [] self.time_passed = 0 self.current_shape = None self.color_start = (255, 255, 255) self.color_end = (255, 255, 255) self.transition_progress = 0.0 self.transition_duration = 1.5 self.transitioning = False self.next_positions = [] self.next_colors = [] self.motion_path = None self.motion_time = 0 # Initialize particles scattered randomly initial_positions = generate_scatter_positions(num_particles) for pos in initial_positions: color = self.color_start p = Particle(pos, color) self.particles.append(p) def lerp_color(self, c1, c2, t): return ( int(c1[0] + (c2[0] - c1[0]) * t), int(c1[1] + (c2[1] - c1[1]) * t), int(c1[2] + (c2[2] - c1[2]) * t) ) def set_shape(self, shape_name, color_start, color_end): self.current_shape = shape_name self.color_start = color_start self.color_end = color_end self.transition_progress = 0.0 self.transitioning = True self.motion_time = 0 # Generate target positions based on shape if shape_name == "particles_scatter": self.next_positions = generate_scatter_positions(self.num_particles) elif shape_name == "human_silhouette": self.next_positions = generate_human_silhouette_positions(self.num_particles) elif shape_name == "tree_figure": self.next_positions = generate_tree_positions(self.num_particles) elif shape_name == "bird_figure": self.next_positions = generate_bird_positions(self.num_particles) else: self.next_positions = generate_scatter_positions(self.num_particles) # Assign target positions to particles with some random offset for natural flow for i, p in enumerate(self.particles): p.target = self.next_positions[i] + pygame.Vector2(random.uniform(-10,10), random.uniform(-10,10)) def update(self, dt): self.time_passed += dt self.motion_time += dt # Update transition progress if self.transitioning: self.transition_progress += dt / self.transition_duration if self.transition_progress >= 1.0: self.transition_progress = 1.0 self.transitioning = False # Update particles for i, p in enumerate(self.particles): # Interpolate color t = self.transition_progress p.color = self.lerp_color(self.color_start, self.color_end, t) # Update target positions smoothly during transition if self.transitioning: # Interpolate target positions from current to next current_target = p.target start_pos = p.pos # Smoothly move target from current pos to next_positions[i] interp_target = self.next_positions[i] * t + start_pos * (1 - t) p.target = interp_target # Add motion path for subtle drifting drift_x = math.sin(self.motion_time + i) * 5 drift_y = math.cos(self.motion_time + i * 1.3) * 5 p.target += pygame.Vector2(drift_x, drift_y) * dt p.update(dt, self.time_passed) def draw(self, surface): for p in self.particles: p.draw(surface) # Main application class class SandArtNarrative: def __init__(self): self.running = True self.text_display = TextDisplay(STORY, FONT, WIDTH, HEIGHT) self.particle_system = ParticleSystem(600, WIDTH, HEIGHT) self.current_scene_index = 0 self.scene_timer = 0 self.scene_duration = STORY[0]["duration"] self.particle_system.set_shape(STORY[0]["shape"], STORY[0]["color_start"], STORY[0]["color_end"]) def run(self): while self.running: dt = CLOCK.tick(FPS) / 1000.0 # Delta time in seconds for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.running = False # Update text display self.text_display.update(dt) # Update particle system self.particle_system.update(dt) # Scene timing and transitions self.scene_timer += dt if self.scene_timer > self.scene_duration: self.scene_timer = 0 self.current_scene_index += 1 if self.current_scene_index >= len(STORY): # End of story - fade out everything gracefully self.fade_out(dt) continue # Update scene duration and particle shape scene = STORY[self.current_scene_index] self.scene_duration = scene["duration"] self.particle_system.set_shape(scene["shape"], scene["color_start"], scene["color_end"]) # Draw everything SCREEN.fill(BLACK) self.particle_system.draw(SCREEN) self.text_display.draw(SCREEN) pygame.display.flip() pygame.quit() sys.exit() def fade_out(self, dt): # Fade out particles and text gradually fade_speed = 0.5 # seconds alpha_decrement = int(255 * dt / fade_speed) # Fade particles by reducing their glow intensity and radius for p in self.particle_system.particles: p.glow_intensity = max(0, p.glow_intensity - dt / fade_speed) p.radius = max(0, p.radius - dt * 5) # Fade text alpha if self.text_display.alpha > 0: self.text_display.alpha = max(0, self.text_display.alpha - alpha_decrement) else: self.running = False # Run the narrative if __name__ == "__main__": narrative = SandArtNarrative() narrative.run()
Explanation & Artistic Notes:
- Narrative: The story is original, poetic, and layered with metaphor, evoking cosmic origins, a lone wanderer, nature, flight, and eternity — all themes that lend themselves well to particle transformations.
- Text: The glowing text is rendered with a custom glow effect, typed out slowly, held for contemplation, then faded out before the next sentence.
- Particles: 600 particles flow fluidly, morphing between scatter, human silhouette, tree, and bird shapes. Each shape is generated with parametric or geometric approximations.
- Color & Glow: Particles smoothly transition colors to reflect mood shifts, with pulsating glow to simulate sand grains shimmering under light.
- Motion: Subtle noise and sine-wave oscillations create natural, entrancing particle movement.
- Transitions: Particle targets interpolate smoothly, avoiding abrupt jumps, enhancing the sand art illusion.
- Performance: The script is optimized for 60 FPS on typical modern hardware.
This script is a grand, immersive fusion of storytelling and visual artistry, designed to captivate and mesmerize viewers as if watching a live Sand Art performance come alive in pixels.
If you want me to help you customize or extend this further (e.g., add sound, more shapes, or interactivity), just ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- o3-2025-04-16Compare side by side →
qwen3-235b-a22bCompare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-2025-04-14Compare side by side →
qwen-max-2025-01-25Compare side by side →
- chatgpt-4o-latest-20250326Compare side by side →
deepseek-v3-0324Compare side by side →
qwen-max-2025-01-25Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
gemini-2.5-pro-preview-03-25Compare side by side →
- chatgpt-4o-latest-20250326Compare side by side →