Below is a Python script that fulfills the requirements you outlined. It uses pygame for rendering and animation, and it incorporates a captivating narrative with synchronized particle animations. The script is designed to be immersive, blending storytelling with visual effects.
Python Script: Sand Art Storytelling with Particle Animations
import pygame
import random
import math
from itertools import cycle
# Initialize Pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 1280, 720
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Sand Art Storytelling")
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GOLD = (255, 215, 0)
BLUE = (0, 191, 255)
RED = (255, 99, 71)
GREEN = (0, 255, 0)
# Font settings
pygame.font.init()
title_font = pygame.font.SysFont("Arial", 48, bold=True)
text_font = pygame.font.SysFont("Arial", 32)
# Clock for controlling frame rate
clock = pygame.time.Clock()
# Narrative story (original and captivating)
story = [
"In the heart of an ancient desert, where time flows like grains of sand...",
"A lone traveler emerged, cloaked in the golden glow of twilight.",
"The wind whispered secrets, weaving tales of forgotten kingdoms.",
"As the moon rose, the sands began to dance, forming shapes of wonder.",
"Each grain carried the weight of history, telling stories of joy and sorrow.",
"And so, the traveler journeyed onward, guided by the stars above."
]
# Particle class for animations
class Particle:
def __init__(self, x, y, size, color):
self.x = x
self.y = y
self.size = size
self.color = color
self.vx = random.uniform(-1, 1)
self.vy = random.uniform(-1, 1)
self.life = 255
def update(self):
self.x += self.vx
self.y += self.vy
self.life -= 1
def draw(self, surface):
if self.life > 0:
pygame.draw.circle(surface, (*self.color, self.life), (int(self.x), int(self.y)), self.size)
# Function to create particles in a circular pattern
def create_particles(center_x, center_y, num_particles, color):
particles = []
angle_step = 2 * math.pi / num_particles
radius = 100
for i in range(num_particles):
angle = i * angle_step
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
particles.append(Particle(x, y, random.randint(2, 5), color))
return particles
# Function to display text with fade-in and fade-out effects
def display_text(text, y_offset, color, fade_in_time=2000, fade_out_time=2000):
start_time = pygame.time.get_ticks()
while True:
elapsed_time = pygame.time.get_ticks() - start_time
if elapsed_time < fade_in_time:
alpha = int(255 * (elapsed_time / fade_in_time))
elif elapsed_time < fade_in_time + fade_out_time:
alpha = 255
else:
alpha = max(0, 255 - int(255 * ((elapsed_time - fade_in_time - fade_out_time) / fade_out_time)))
if alpha == 0:
break
text_surface = text_font.render(text, True, (*color, alpha))
screen.blit(text_surface, (WIDTH // 2 - text_surface.get_width() // 2, y_offset))
pygame.display.flip()
clock.tick(60)
# Main animation loop
def main():
running = True
current_scene = 0
particles = []
# Scene transitions
scenes = cycle([
{"text": story[0], "color": GOLD, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 100, GOLD)},
{"text": story[1], "color": BLUE, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 150, BLUE)},
{"text": story[2], "color": RED, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 200, RED)},
{"text": story[3], "color": GREEN, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 250, GREEN)},
{"text": story[4], "color": WHITE, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 300, WHITE)},
{"text": story[5], "color": GOLD, "particles": create_particles(WIDTH // 2, HEIGHT // 2, 350, GOLD)}
])
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear screen
screen.fill(BLACK)
# Update and draw particles
for particle in particles[:]:
particle.update()
particle.draw(screen)
if particle.life <= 0:
particles.remove(particle)
# Display text with fade effects
scene = next(scenes)
display_text(scene["text"], 50, scene["color"])
# Add new particles for the next scene
particles.extend(scene["particles"])
# Limit frame rate
clock.tick(60)
pygame.quit()
if __name__ == "__main__":
main()