This repository serves as a playground and collection of small experiments exploring computer graphics, visualization, and generative art concepts across multiple programming languages. Each experiment is typically a standalone program that demonstrates techniques such as particle systems, flocking behavior, wave simulation, fractal generation, and other visual effects.
The project is organized by language (e.g., Rust, Python, JavaScript), with each experiment contained in its own subdirectory for modularity and ease of exploration. Shared assets and resources (such as images or shaders) are provided in a common directory.
Goals:
- Learn and compare graphics programming across different ecosystems
- Quickly prototype and visualize ideas in the most suitable language or framework
- Encourage experimentation and sharing of creative visual code
Features:
- Multi-language support: Rust, Python, JavaScript, and more
- Clear directory structure for organization and scalability
- Each experiment is self-contained with its own documentation and instructions
- Common assets directory for resources reusable by any language
gfx/
βββ js/
β βββ experiments/
βββ python/
β βββ experiments/
β βββ particles/ # Bouncing particles with trails (Pygame)
β β βββ main.py
β β βββ README.md
β β βββ requirements.txt
β βββ waves/ # Multi-layered sinusoidal wave simulation
β β βββ main.py
β β βββ README.md
β β βββ requirements.txt
β βββ flocking_boids/ # Craig Reynolds' boids flocking algorithm
β β βββ main.py
β β βββ README.md
β β βββ requirements.txt
β βββ fractal_tree/ # Animated recursive tree generation
β βββ main.py
β βββ README.md
β βββ requirements.txt
βββ rust/
β βββ experiments/
β βββ README.md # Rust experiments overview
β βββ gfx-stats/ # Advanced performance statistics library
β β βββ Cargo.toml
β β βββ src/
β β βββ lib.rs
β βββ particles/ # Bouncing particles with trails (Macroquad)
β β βββ Cargo.toml
β β βββ README.md
β β βββ build_wasm.sh
β β βββ src/
β β βββ main.rs
β βββ flocking_boids/ # Craig Reynolds' boids flocking algorithm
β β βββ Cargo.toml
β β βββ README.md
β β βββ build_wasm.sh
β β βββ src/
β β βββ main.rs
β βββ waves/ # Multi-layered sinusoidal wave simulation
β β βββ Cargo.toml
β β βββ README.md
β β βββ build_wasm.sh
β β βββ src/
β β βββ main.rs
β βββ fractal_tree/ # Animated recursive tree generation
β β βββ Cargo.toml
β β βββ README.md
β β βββ build_wasm.sh
β β βββ src/
β β βββ main.rs
β βββ build_all_wasm.sh # Build all experiments for web
βββ shared/
βββ assets/
The Rust experiments showcase advanced graphics programming using Macroquad, demonstrating:
π― Particles
Bouncing particles with trails inside a circular boundary
- Dynamic particle spawning with random properties
- Realistic collision physics and reflection
- Visual trails with alpha fade effects
- Real-time performance monitoring with CPU usage estimation
- WebAssembly support for browser deployment
π¦ Flocking Boids
Implementation of Craig Reynolds' classic boids flocking algorithm
- Three-rule flocking behavior (separation, alignment, cohesion)
- 50 colorful boids with natural group movement
- Emergent swarm intelligence patterns
- Triangle-shaped boids showing direction
- WebAssembly support for browser deployment
π Waves
Multi-layered sinusoidal wave simulation
- Three overlapping waves with different frequencies
- Real-time wave interference patterns
- Smooth animation with 100-point resolution
- Color-coded wave visualization
- WebAssembly support for browser deployment
π³ Fractal Tree
Animated recursive tree generation
- 10-level fractal branching with natural proportions
- Dynamic swaying animation mimicking wind
- Realistic trunk-to-leaf color transitions
- Mathematical beauty through recursion
- WebAssembly support for browser deployment
The Python experiments use Pygame for cross-platform graphics, providing rapid prototyping capabilities:
π― Particles
Bouncing particles with trails inside a circular boundary
- Dynamic particle spawning with random properties
- Realistic collision physics and reflection
- Visual trails with alpha fade effects
- Real-time performance monitoring
π Waves
Multi-layered sinusoidal wave simulation
- Three overlapping waves with different frequencies
- Real-time wave interference patterns
- Smooth animation with 100-point resolution
- Color-coded wave visualization
π¦ Flocking Boids
Implementation of Craig Reynolds' classic boids flocking algorithm
- Three-rule flocking behavior (separation, alignment, cohesion)
- 50 colorful boids with natural group movement
- Emergent swarm intelligence patterns
- Triangle-shaped boids showing direction
- NumPy-accelerated vector mathematics
π³ Fractal Tree
Animated recursive tree generation
- 10-level fractal branching with natural proportions
- Dynamic swaying animation mimicking wind
- Realistic trunk-to-leaf color transitions
- Mathematical beauty through recursion
Each experiment directory contains its own README with specific setup and run instructions. Generally:
cd rust/experiments/<experiment_name>/
cargo run --releasecd rust/experiments/<experiment_name>/
./build_wasm.sh
basic-http-server webcd rust/experiments/
./build_all_wasm.sh
basic-http-server .cd python/experiments/<experiment_name>/
pip install -r requirements.txt
python main.pyFollow individual project instructions for setup (coming soon)
- High Performance: 60 FPS rendering with efficient memory management
- Cross-Platform: Works on Windows, macOS, Linux, and Web (WASM)
- Mathematical Precision: Accurate physics simulation and vector operations
- Real-Time Monitoring: Built-in FPS and performance statistics with CPU usage tracking
- Modern Patterns: Async/await support and safe memory handling
- Web Deployment: Compile to WebAssembly for browser execution
- Rapid Prototyping: Quick iteration and experimentation
- Rich Ecosystem: NumPy for mathematical operations, extensive libraries
- Educational Value: Clear, readable code for learning algorithms
- Interactive Development: Easy debugging and live code modification
- Scientific Computing: Integration with data science and visualization tools
- Frame-rate independent animation
- Configurable parameters for experimentation
- Comprehensive documentation for each experiment
- Modular code structure for easy modification
- Consistent visual output and behavior
- Macroquad: Primary graphics and windowing library
- rand: Random number generation
- gfx-stats: Advanced performance monitoring library with CPU usage estimation
- Pygame: Cross-platform graphics library
- NumPy: Numerical computing for vector operations
- math: Built-in mathematical functions
- CPU Usage Estimation: Real-time performance tracking based on frame times
- Comprehensive Metrics: FPS, frame time, elapsed time, and entity counts
- Adaptive Display: Dynamic content sizing based on information displayed
- Custom Information: Support for experiment-specific statistics
- Best for: Native desktop applications requiring detailed performance analysis
// For native desktop apps with full features
use gfx_stats::StatsDisplay;
// For WebAssembly and universal compatibility
use simple_stats::StatsDisplay;
// Both libraries share the same API
let mut stats = StatsDisplay::new("Experiment Name");
stats.update(dt);
stats.draw(entity_count);All Rust experiments include comprehensive performance monitoring:
- Elapsed Time: Running time in minutes and seconds
- Entity Count: Dynamic count of simulation objects (particles, boids, waves, branches)
- FPS Tracking: Real-time frames per second calculation
- CPU Usage: Estimated CPU utilization based on frame timing (native builds)
- Visual Feedback: Semi-transparent overlay with consistent styling
- Native Builds: Full statistics with CPU monitoring using
gfx-stats - Automatic Fallback: Build scripts automatically handle library selection
- Consistent Experience: Same visual appearance across all platforms
Planned experiments include:
- Cellular Automata: Conway's Game of Life variations
- Ray Tracing: 2D light simulation and reflection
- Fluid Dynamics: Particle-based fluid simulation
- L-Systems: Grammar-based procedural generation
- Genetic Algorithms: Evolution simulation with visual organisms
- JavaScript Implementations: Browser-native versions using Canvas API or WebGL
- Macroquad Documentation
- Pygame Documentation
- The Nature of Code - Physics simulations and natural systems
- Red Blob Games - Interactive algorithm explanations
- Rust Book - Learn Rust fundamentals
- Python Graphics Programming - Pygame tutorials
- WebAssembly with Rust - WASM deployment guide
Each language implementation provides unique insights:
- Rust: Focus on performance, safety, and WebAssembly deployment with comprehensive monitoring
- Python: Emphasize rapid prototyping, educational clarity, and scientific computing integration
- Future languages: Explore different paradigms and ecosystems
The dual statistics library approach allows for:
- Maximum Performance: Use
gfx-statsfor native applications with full monitoring - Easy Migration: Identical APIs allow switching between libraries without code changes
Feel free to add new experiments, improve existing implementations, or port concepts between languages to explore different approaches to the same problems.