A real-time mathematical function visualizer that creates beautiful, animated patterns using complex mathematical operations. The application supports GPU acceleration and includes advanced features for performance monitoring, saving/loading, and customization.
2025-08-08.13-17-48.mp4
- 15 Mathematical Operations: Sine/cosine waves, XOR patterns, cellular automata, domain warping, polar transformations, noise generation, SDF tiling, Gabor noise, and more
- Normalized Composition: Each function is normalized to [0,1] range before combining, with individual strength controls
- Real-time Animation: Smooth, time-based parameter evolution
- GPU Acceleration: CuPy support for faster computation when available
- Visual Fidelity Control: Adjustable resolution scaling for performance optimization
- Color Evolution: Sophisticated color mapping with harmonic layers and temperature variations
- Parameter Saving: Save your favorite visualizations with timestamps
- Preset System: Export and import parameter presets with metadata
- Real-time FPS Display: Monitor frame rate and performance
- Auto-optimization: Automatic fidelity adjustment based on performance
- Performance Warnings: Alerts for low FPS or high memory usage
- Optimization History: Track performance optimizations made
- JSON Configuration: Centralized settings management
- Customizable UI: Show/hide performance display, toolbar
- Hardware Detection: Automatic GPU/CPU selection
- Logging System: Comprehensive logging with file output
-
Clone the repository:
git clone <repository-url> cd function-visualizer
-
Install dependencies:
pip install -r requirements.txt
-
Optional GPU acceleration:
pip install cupy-cuda11x # Replace with your CUDA version
python visualizer.py
- R: Randomize parameters (new pattern)
- S: Save current state
- L: Load saved state
- F: Toggle fullscreen
- H: Toggle toolbar visibility
- P: Toggle performance display
- Step: Animation speed (0.0-0.2)
- Scale: Visual fidelity/performance (5-100%)
The application uses config.json
for settings. Key configuration options:
{
"window": {
"width": 800,
"height": 600,
"title": "Function Visualizer"
},
"visualization": {
"default_time_step": 0.05,
"default_visual_fidelity": 100.0,
"frame_rate": 20
},
"performance": {
"enable_gpu": true,
"auto_adjust_fidelity": true
},
"saving": {
"auto_save_interval": 0,
"save_directory": "saves"
}
}
function-visualizer/
βββ visualizer.py # Main application
βββ core/ # Core computation and rendering
β βββ nd.py # NumPy/CuPy selection and helpers
β βββ params.py # Parameter randomization and defaults
β βββ color/
β β βββ palettes.py # Palettes and sampling
β β βββ space.py # RGB/HSV utilities and vibrance
β β βββ tone.py # Contrast/gamma/brightness
β βββ feedback/
β β βββ state.py # Feedback state singleton
β β βββ compute.py # Feedback signal computation
β βββ patterns/ # Individual pattern operators
β β βββ sin_cos.py
β β βββ xor.py
β β βββ cellular.py
β β βββ domain_warp.py
β β βββ polar.py
β β βββ noise.py
β β βββ gabor_noise.py
β β βββ abs_transform.py
β β βββ power.py
β β βββ voronoi.py
β β βββ sdf_shapes.py
β β βββ reaction_diffusion.py
β β βββ sinusoidal_field.py
β βββ compute/
β β βββ compose.py # Orchestrates ops and color mapping
β β βββ registry.py # Maps op keys to functions
β βββ rendering/
β βββ image.py # Image generation from functions
βββ config.py # Configuration management
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ ui/
β βββ visualizer_ui.py # User interface
βββ utils/
β βββ hardware.py # GPU/CPU detection
β βββ logger.py # Logging system
β βββ save_manager.py # Save/load functionality
β βββ performance.py # Performance monitoring
βββ saves/ # Saved files (auto-created)
βββ parameters/ # Saved parameters
βββ images/ # Exported images
βββ videos/ # Video frames
The visualizer supports 15 different mathematical operations:
- Sine Waves (
use_sin
): Basic sine wave patterns - Cosine Waves (
use_cos
): Basic cosine wave patterns - XOR Patterns (
use_xor
): Bitwise XOR with morphing - Cellular Automata (
use_cellular
): Grid-based patterns - Domain Warping (
use_domain_warp
): Coordinate transformation - Polar Transformations (
use_polar
): Radial coordinate patterns - Noise Generation (
use_noise
): Multi-octave pseudo-noise - Absolute Value (
use_abs
): Absolute value transformations - Power Functions (
use_power
): Exponential transformations - Feedback Loops (
use_feedback
): Frame-to-frame feedback - Voronoi Diagrams (
use_voronoi
): Distance field patterns - Reaction-Diffusion (
use_reaction_diffusion
): Gray-Scott model - Sinusoidal Fields (
use_sinusoidal_field
): Complex 2D field patterns - SDF Shapes/Tiles (
use_sdf_shapes
): Tileable signed distance fields with circle/rounded-box mixing and smooth edges - Gabor Noise (
use_gabor_noise
): Oriented, band-limited noise with Gaussian envelope and time animation
- GPU Acceleration: Install CuPy for significant performance improvement
- Visual Fidelity: Lower the scale slider for better performance
- Auto-optimization: Enable auto-adjust fidelity in config
- Memory Monitoring: Install psutil for memory tracking
- Low FPS: Reduce visual fidelity or enable auto-optimization
- GPU Not Detected: Ensure CuPy is properly installed for your CUDA version
- Save/Load Errors: Check file permissions in saves directory
The application logs to both console and file (visualizer.log
). Check logs for detailed error information.
- Create a new operator in
core/patterns/your_op.py
exporting:apply(x, y, time_val, params)
β returns an array contribution (same shape asx
).
- Register the operator in
core/compute/registry.py
by mapping a key (e.g.,'use_your_op'
) to your function. - Add any parameters and ranges to
core/params.py
and include your op key in the randomized operations set if desired. - (Optional) Extend color behavior in
core/color/*
if your op needs custom color handling. - Run
visualizer.py
and test.
- Modify
ui/visualizer_ui.py
for new controls - Update the main visualizer class for new callbacks
- Add configuration options in
config.py
This project is open source. Feel free to contribute improvements!
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- PIL/Pillow for image processing
- NumPy for array operations
- CuPy for GPU acceleration
- Tkinter for the user interface