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.pyexporting:apply(x, y, time_val, params)→ returns an array contribution (same shape asx).
- Register the operator in
core/compute/registry.pyby mapping a key (e.g.,'use_your_op') to your function. - Add any parameters and ranges to
core/params.pyand 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.pyand test.
- Modify
ui/visualizer_ui.pyfor 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