Skip to content

AlessandroPerazzetta/gfx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Multi-Language Graphics Experiments

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

Current Experiments

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/

Rust Experiments Collection

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

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

Python Experiments Collection

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

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

Getting Started

Each experiment directory contains its own README with specific setup and run instructions. Generally:

Rust Experiments

Native (Desktop)

cd rust/experiments/<experiment_name>/
cargo run --release

Web (WebAssembly)

cd rust/experiments/<experiment_name>/
./build_wasm.sh
basic-http-server web

Build All Web Experiments

cd rust/experiments/
./build_all_wasm.sh
basic-http-server .

Python Experiments

cd python/experiments/<experiment_name>/
pip install -r requirements.txt
python main.py

JavaScript Experiments

Follow individual project instructions for setup (coming soon)

Language Comparison

Rust Implementation Benefits

  • 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

Python Implementation Benefits

  • 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

Common Features Across Languages

  • Frame-rate independent animation
  • Configurable parameters for experimentation
  • Comprehensive documentation for each experiment
  • Modular code structure for easy modification
  • Consistent visual output and behavior

Technical Stack

Rust Dependencies

  • Macroquad: Primary graphics and windowing library
  • rand: Random number generation
  • gfx-stats: Advanced performance monitoring library with CPU usage estimation

Python Dependencies

  • Pygame: Cross-platform graphics library
  • NumPy: Numerical computing for vector operations
  • math: Built-in mathematical functions

Shared Libraries

Statistics Libraries (Rust)

gfx-stats - Advanced Performance Monitoring

  • 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

Usage Pattern

// 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);

Performance Monitoring Features

Real-Time Statistics Display

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

Cross-Platform Compatibility

  • 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

Future Directions

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

Learning Resources

Graphics Programming

Language-Specific

Contributing

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-stats for 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.

About

Multi-Language Graphics Experiments

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published