Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions #1687_Waterfall_Animation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Digital Waterfall (Matrix-Style Animation)

This project is a **Matrix-inspired digital waterfall animation** implemented in Python using `pygame`. The animation features streams of characters falling down the screen with glowing heads, reminiscent of the iconic visual from the *Matrix* movie series.

## Features

- **Random Character Streams:** Streams of alphanumeric and special characters fall from the top of the screen.
- **Glowing Heads:** The leading character of each stream is highlighted for a dynamic effect.
- **Variable Speeds & Lengths:** Each stream moves at a different speed and length to create a natural flowing effect.
- **Interactive & Lightweight:** Runs smoothly at 30 FPS with adjustable parameters.

## How It Works

1. **Grid-Based Layout:** The screen is divided into columns based on the font size. Each column may spawn a stream.
2. **Stream Logic:** Each stream keeps track of its vertical position, length, speed, and character list.
3. **Animation:** Characters are updated every frame, and new streams spawn randomly. Characters also change randomly to simulate a flowing effect.
4. **Rendering:** Uses `pygame`'s font rendering to draw colored text on the screen.

## Controls

- Close the window to exit the program.

## Requirements

- Python 3.6 or higher
- `pygame` (`pip install pygame`)

## Customization

- **FONT_SIZE:** Change the size of the characters.
- **FALL_SPEED:** Adjust the speed at which streams fall.
- **SPAWN_CHANCE:** Control the likelihood of new streams spawning.
- **CHARS:** Customize the set of characters used in the streams.
- **COLORS:** Modify `STREAM_COLOR` and `HEAD_COLOR` for different visual effects.
77 changes: 77 additions & 0 deletions #1687_Waterfall_Animation/waterfall_animated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pygame
import random
import time

# --- Pygame Initialization & Constants ---
pygame.init()
FONT_SIZE = 16
W, H = 800, 600
SCREEN = pygame.display.set_mode((W, H))
pygame.display.set_caption("Digital Waterfall")
CLOCK = pygame.time.Clock()
BG_COLOR = (0, 0, 0) # Black background
STREAM_COLOR = (0, 255, 0) # Green stream
HEAD_COLOR = (200, 255, 200) # Bright head

# --- Grid and Character Setup ---
COLS = W // FONT_SIZE
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()"
FONT = pygame.font.SysFont('Consolas', FONT_SIZE, bold=True)
FALL_SPEED = 0.5 # Pixels/frame
SPAWN_CHANCE = 0.05 # Chance a stream starts in a column each frame

# Columns store [y_pos, length, speed, char_list]
streams = [None] * COLS

def get_char_surface(char, is_head):
"""Generates a text surface for drawing."""
color = HEAD_COLOR if is_head else STREAM_COLOR
return FONT.render(char, True, color)

# --- Main Animation Loop ---
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# 1. Update/Draw streams
SCREEN.fill(BG_COLOR)

for x in range(COLS):
stream = streams[x]

# Spawn new stream
if stream is None and random.random() < SPAWN_CHANCE:
length = random.randint(10, 20)
streams[x] = [0, length, random.uniform(2, 4), [random.choice(CHARS) for _ in range(length)]]
continue # Skip update this frame

if stream:
y_pos, length, speed, chars = stream
y_pos += speed # Move stream down

# Draw stream characters
for i in range(length):
char = chars[i]
current_y = int(y_pos - (i * FONT_SIZE))

# Check if char is on screen
if current_y >= 0 and current_y < H:
surface = get_char_surface(char, i == 0) # i=0 is the head
SCREEN.blit(surface, (x * FONT_SIZE, current_y))

# Cycle characters to simulate change
if random.random() < 0.05:
chars[i] = random.choice(CHARS)

# Check if stream is fully off screen
if y_pos - (length * FONT_SIZE) > H:
streams[x] = None # Kill stream
else:
streams[x][0] = y_pos # Update position

pygame.display.flip()
CLOCK.tick(30) # 30 FPS

pygame.quit()