Attract
Generate beautiful mathematical art with the power of chaos theory and Rust's performance.
Features
- Multiple Attractor Types: Clifford, De Jong, Hénon, Ikeda, Tinkerbell, Duffing, Chirikov Standard Map, and Gingerbreadman
- Flexible Sampling: Gaussian, circular, and axis-aligned bounding box generators for initial conditions
- High Performance: Multi-threaded rendering with configurable parallelization
- Generic Design: Works with any floating-point type (
f32,f64) - Memory Efficient: Density-based rendering that scales to millions of sample points
- Progress Tracking: Built-in progress bars for long-running computations
Quick Start
Add this to your Cargo.toml:
[]
= "0.0.0"
Basic Example
use ;
use Complex;
// Create a Clifford attractor with classic parameters
let attractor = Boxnew;
// Set up a Gaussian generator for initial sampling points
let generator = Gaussian ;
// Configure rendering settings
let settings = Settings ;
// Render the attractor
let density_map = render;
// The density_map is a 2D array where each cell contains
// the number of points that visited that pixel
Supported Attractors
Clifford Attractor
One of the most visually striking attractors, generating intricate butterfly-like patterns.

Equations:
x_{n+1} = sin(a * y_n) + c * cos(a * x_n)y_{n+1} = sin(b * x_n) + d * cos(b * y_n)
let clifford = new;
De Jong Attractor
Creates organic, flowing patterns with four parameters controlling the dynamics.

Equations:
x_{n+1} = sin(a * y_n) - cos(b * x_n)y_{n+1} = sin(c * x_n) - cos(d * y_n)
let de_jong = new;
Hénon Map
A classic discrete-time dynamical system that exhibits chaotic behavior.

Equations:
x_{n+1} = 1 - a * x_n^2 + y_ny_{n+1} = b * x_n
let henon = new;
Ikeda Map

Models the behavior of light in an optical cavity, creating spiral patterns.
Equations:
t = 0.4 - 6.0 / (1 + x_n^2 + y_n^2)x_{n+1} = 1 + u * (x_n * cos(t) - y_n * sin(t))y_{n+1} = u * (x_n * sin(t) + y_n * cos(t))
let ikeda = new;
Tinkerbell Map

A four-parameter map that produces fairy-like patterns, often used in fractal art.
Equations:
x_{n+1} = x_n^2 - y_n^2 + a * x_n + b * y_ny_{n+1} = 2 * x_n * y_n + c * x_n + d * y_n
let tinkerbell = new;
Duffing Attractor

A chaotic oscillator model that simulates the behavior of a forced, damped oscillator.
Equations:
x_{n+1} = y_ny_{n+1} = -b * x_n + a * y_n - y_n^3
let duffing = new;
Gingerbreadman Attractor

A unique attractor with a distinctive shape, defined by a simple iterative process.
Equations:
x_{n+1} = 1 - y_n + |x_n|y_{n+1} = x_n
let gingerbreadman = new;
Chirikov Standard Map

A map that exhibits chaotic behavior in Hamiltonian systems, often used in studies of chaos.
Equations:
impl<T: Float + Copy> Attractor for Chirikov { #[inline] fn iterate(&self, p: Complex) -> Complex { let x = p.re; // position let p_momentum = p.im; // momentum
let p_new = p_momentum + self.k * x.sin();
let x_new = x + p_new;
Complex::new(x_new, p_new)
}
}
x_{n+1} = x_n + p_np_{n+1} = p_n + k * sin(x_n)
Bring Your Own Attractor
The library is designed to be extensible. You can implement your own custom attractors by simply implementing the Attractor trait:
use Attractor;
use Complex;
use Float;
// Example: A simple custom attractor
// Your custom attractor now works with all rendering functions!
let custom_attractor = Boxnew;
let settings = Settings ;
let result = render;
Once you implement the Attractor trait, your custom attractor is immediately compatible with all the library's rendering functions, sampling methods, and performance optimizations.
Sampling Generators
Control how initial points are distributed in the complex plane:
Gaussian Distribution
let generator = Gaussian ;
Circular Region
let generator = Circle ;
Rectangular Region
let generator = Aabb ;
Performance Optimization
Multi-threading
Control parallelization with the num_groups parameter:
let settings = Settings ;
Memory vs Quality Trade-offs
- Higher
num_samples: Better quality, more computation time - Higher
max_iter: More detailed attractors, slower rendering - Larger
resolution: Higher detail, more memory usage warmupiterations: Skip transient behavior, focus on the attractor
Recommended Settings
For quick previews:
num_samples: 100_000,
max_iter: 1_000,
resolution: ,
For high-quality renders:
num_samples: 10_000_000,
max_iter: 50_000,
resolution: ,
Advanced Usage
Custom Viewport
Focus on specific regions of the attractor:
let settings = Settings ;
Generic Float Types
Use different precision levels:
// High precision
let attractor = Boxnew;
// Fast computation
let attractor = Boxnew;
Output Processing
The render function returns a 2D density array (Array2<u32>) where each cell contains the visit count for that pixel. You can:
- Apply logarithmic scaling to enhance visibility of low-density regions
- Convert to images using your preferred image processing library
- Apply color maps for artistic visualization
- Perform statistical analysis on the density distribution
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Areas where contributions would be particularly valuable:
- Additional attractor implementations
- Performance optimizations
- New sampling methods
- Documentation improvements
- Example applications