pub enum MathFunction {
Show 62 variants
Constant(f32),
Linear {
slope: f32,
offset: f32,
},
Sine {
amplitude: f32,
frequency: f32,
phase: f32,
},
Cosine {
amplitude: f32,
frequency: f32,
phase: f32,
},
Triangle {
amplitude: f32,
frequency: f32,
phase: f32,
},
Square {
amplitude: f32,
frequency: f32,
duty: f32,
},
Lorenz {
sigma: f32,
rho: f32,
beta: f32,
scale: f32,
},
Perlin {
frequency: f32,
octaves: u8,
amplitude: f32,
},
Simplex {
frequency: f32,
amplitude: f32,
},
Exponential {
start: f32,
target: f32,
rate: f32,
},
LogisticMap {
r: f32,
x0: f32,
},
Collatz {
seed: u64,
scale: f32,
},
Orbit {
center: Vec3,
radius: f32,
speed: f32,
eccentricity: f32,
},
Spiral {
center: Vec3,
radius_rate: f32,
speed: f32,
},
GoldenSpiral {
center: Vec3,
scale: f32,
speed: f32,
},
Lissajous {
a: f32,
b: f32,
delta: f32,
scale: f32,
},
StrangeAttractor {
attractor_type: AttractorType,
scale: f32,
strength: f32,
},
MandelbrotEscape {
c_real: f32,
c_imag: f32,
scale: f32,
},
JuliaSet {
c_real: f32,
c_imag: f32,
scale: f32,
},
SpringDamper {
target: f32,
stiffness: f32,
damping: f32,
},
CriticallyDamped {
target: f32,
speed: f32,
},
HeartBeat {
bpm: f32,
intensity: f32,
},
Breathing {
rate: f32,
depth: f32,
},
Pendulum {
length: f32,
gravity: f32,
damping: f32,
},
Wave {
wavelength: f32,
speed: f32,
amplitude: f32,
decay: f32,
},
Sawtooth {
amplitude: f32,
frequency: f32,
phase: f32,
},
Ramp {
amplitude: f32,
duration: f32,
},
Sinc {
frequency: f32,
amplitude: f32,
},
Gaussian {
amplitude: f32,
center: f32,
width: f32,
},
BeatFrequency {
freq1: f32,
freq2: f32,
amplitude: f32,
},
WavePacket {
carrier_freq: f32,
envelope_width: f32,
amplitude: f32,
center: f32,
},
FourierSeries {
fundamental: f32,
coefficients: Vec<(f32, f32)>,
},
Sigmoid {
steepness: f32,
center: f32,
},
Tanh {
amplitude: f32,
steepness: f32,
},
SoftPlus {
amplitude: f32,
steepness: f32,
},
Relu {
slope: f32,
offset: f32,
},
PowerLaw {
exponent: f32,
scale: f32,
},
VanDerPol {
mu: f32,
amplitude: f32,
},
Duffing {
alpha: f32,
beta: f32,
delta: f32,
gamma: f32,
omega: f32,
},
TentMap {
r: f32,
x0: f32,
},
HenonMap {
a: f32,
b: f32,
x0: f32,
y0: f32,
},
Roessler {
a: f32,
b: f32,
c: f32,
scale: f32,
},
DoublePendulum {
l1: f32,
l2: f32,
m1: f32,
m2: f32,
theta1_0: f32,
theta2_0: f32,
},
Projectile {
v0: f32,
angle_deg: f32,
gravity: f32,
},
SimpleHarmonic {
omega: f32,
amplitude: f32,
phase: f32,
decay: f32,
},
DampedSine {
omega: f32,
zeta: f32,
amplitude: f32,
phase: f32,
},
Epicycle {
r1: f32,
r2: f32,
omega1: f32,
omega2: f32,
},
FractionalBrownian {
frequency: f32,
octaves: u8,
hurst: f32,
amplitude: f32,
},
DomainWarp {
frequency: f32,
warp_strength: f32,
octaves: u8,
amplitude: f32,
},
Cellular {
frequency: f32,
amplitude: f32,
},
Sum(Box<MathFunction>, Box<MathFunction>),
Product(Box<MathFunction>, Box<MathFunction>),
Chain(Vec<MathFunction>),
Modulate {
carrier: Box<MathFunction>,
modulator: Box<MathFunction>,
},
Clamp {
inner: Box<MathFunction>,
min: f32,
max: f32,
},
Abs(Box<MathFunction>),
Scale {
inner: Box<MathFunction>,
factor: f32,
},
Offset {
inner: Box<MathFunction>,
offset: f32,
},
Invert(Box<MathFunction>),
Normalize {
inner: Box<MathFunction>,
t_range: f32,
steps: u32,
},
Delay {
inner: Box<MathFunction>,
delay: f32,
},
Mirror {
inner: Box<MathFunction>,
period: f32,
},
}Expand description
A continuous mathematical function that maps (time, input) → f32.
Functions are composable: Sum, Product, and Chain allow building
arbitrarily complex behaviors from simple primitives.
Variants§
Constant(f32)
Always returns the same value.
Linear
Linear function: slope * t + offset.
Sine
Sinusoidal oscillation.
Cosine
Cosinusoidal oscillation.
Triangle
Triangle wave oscillation.
Square
Square wave (snaps between +/- amplitude).
Lorenz
Lorenz attractor trajectory (x-coordinate).
Perlin
Perlin noise.
Simplex
Simplex noise.
Exponential
Exponential approach to target: target + (start - target) * e^(-rate * t).
LogisticMap
Logistic map iteration: x_{n+1} = r * x_n * (1 - x_n). Exhibits bifurcation.
Collatz
Collatz sequence mapped to a float path. Bouncy convergence.
Orbit
Circular or elliptical orbit around a center point.
Spiral
Outward (or inward) spiral.
GoldenSpiral
Golden-ratio spiral.
Lissajous
Lissajous figure.
StrangeAttractor
Move along a strange attractor trajectory (x-coordinate output).
MandelbrotEscape
Mandelbrot escape-time mapped to float.
JuliaSet
Julia set escape-time mapped to float.
SpringDamper
Spring-damper: approaches target with optional overshoot.
CriticallyDamped
Critically damped spring (no overshoot, fastest convergence).
HeartBeat
Realistic cardiac waveform (P, QRS, T waves).
Breathing
Four-phase breathing cycle: inhale → hold → exhale → hold.
Pendulum
Physical pendulum with gravity and damping.
Wave
Traveling wave.
Sawtooth
Sawtooth wave (rising ramp that resets to -1).
Ramp
Ramp: linearly rises from 0 to amplitude over duration, then resets.
Sinc
Sinc function: sin(π·x) / (π·x). Used for signal reconstruction.
Gaussian
Gaussian bell curve: amplitude · e^(-((t-center)/width)²).
BeatFrequency
Two-frequency beat: interference between slightly detuned oscillators.
WavePacket
Wave packet: Gaussian envelope × carrier sine.
FourierSeries
Fourier series: sum of harmonics with user-specified coefficients.
Sigmoid
Sigmoid (logistic) function maps any input → (0, 1).
Tanh
Hyperbolic tangent: amplitude · tanh(steepness · t).
SoftPlus
Soft-plus: amplitude · ln(1 + e^(steepness·t)) / steepness.
Relu
Rectified linear: max(0, slope·t + offset).
PowerLaw
Power law: sign(t) · |t|^exponent.
VanDerPol
Van der Pol oscillator (nonlinear oscillator with limit cycle).
Duffing
Duffing oscillator (chaotic forced nonlinear oscillator).
TentMap
Tent map iterated n times: exhibits period-doubling route to chaos.
HenonMap
Hénon map: chaotic 2D map (returns x-coordinate).
Roessler
Rössler system x-coordinate trajectory.
DoublePendulum
Double pendulum: chaotic system of two connected pendulums (angle θ₁).
Projectile
Projectile motion: height above ground (y-axis) at time t.
SimpleHarmonic
Simple harmonic motion with optional initial displacement.
DampedSine
Damped sine with exact analytic form.
Epicycle
Epicyclic motion: small circle of radius r2 orbiting at radius r1.
FractionalBrownian
Fractional Brownian motion: multi-octave noise with Hurst exponent H.
DomainWarp
Domain-warped noise: the input to the noise is itself displaced by another noise.
Cellular
Cellular / Worley noise: distance to nearest point in a Poisson point process.
Sum(Box<MathFunction>, Box<MathFunction>)
Add two function outputs.
Product(Box<MathFunction>, Box<MathFunction>)
Multiply two function outputs.
Chain(Vec<MathFunction>)
Chain: output of each function feeds as input to the next.
Modulate
Modulate amplitude of inner function by outer function output.
Clamp
Clamp the output to [min, max].
Abs(Box<MathFunction>)
Absolute value of inner.
Scale
Scale: multiply output of inner by factor.
Offset
Offset: add offset to output of inner.
Invert(Box<MathFunction>)
Invert: negate the output of inner.
Normalize
Normalize inner to [-1, 1] over a given sample window of t_range seconds.
(sampled at steps points; expensive — use sparingly.)
Delay
Delay: evaluate inner at (t - delay_seconds).
Mirror
Mirror: map t → |t mod (2·period) - period| creating a symmetric waveform.
Implementations§
Source§impl MathFunction
impl MathFunction
Sourcepub fn evaluate(&self, t: f32, input: f32) -> f32
pub fn evaluate(&self, t: f32, input: f32) -> f32
Evaluate the function at time t with chained input.
Sourcepub fn derivative(&self, t: f32, epsilon: f32) -> f32
pub fn derivative(&self, t: f32, epsilon: f32) -> f32
Numerical derivative dF/dt at time t using central differences.
Epsilon defaults to 1e-4 — reduce for smoother but less accurate results.
Sourcepub fn integrate(&self, from: f32, to: f32, steps: u32) -> f32
pub fn integrate(&self, from: f32, to: f32, steps: u32) -> f32
Numerical integral ∫F dt over [from, to] using Simpson’s rule with steps intervals.
steps must be even (rounded up if not).
Sourcepub fn sample_range(&self, t_start: f32, t_end: f32, n: u32) -> Vec<f32>
pub fn sample_range(&self, t_start: f32, t_end: f32, n: u32) -> Vec<f32>
Sample the function at n uniformly spaced points over [t_start, t_end].
Sourcepub fn find_range(&self, t_start: f32, t_end: f32, steps: u32) -> (f32, f32)
pub fn find_range(&self, t_start: f32, t_end: f32, steps: u32) -> (f32, f32)
Find the approximate minimum and maximum output over [t_start, t_end].
Sourcepub fn zero_crossings(&self, t_start: f32, t_end: f32, steps: u32) -> Vec<f32>
pub fn zero_crossings(&self, t_start: f32, t_end: f32, steps: u32) -> Vec<f32>
Find approximate zero-crossings in [t_start, t_end].
Sourcepub fn evaluate_vec3(&self, t: f32) -> Vec3
pub fn evaluate_vec3(&self, t: f32) -> Vec3
Evaluate as a 3D trajectory: x = f(t, 0), y = f(t+1, 0), z = f(t+2, 0).
This is the default particle behavior — all three axes driven by the same function but offset in time, producing organic non-planar motion.
Sourcepub fn evaluate_vec3_phased(
&self,
t: f32,
phase_x: f32,
phase_y: f32,
phase_z: f32,
) -> Vec3
pub fn evaluate_vec3_phased( &self, t: f32, phase_x: f32, phase_y: f32, phase_z: f32, ) -> Vec3
Evaluate as a 3D trajectory with explicit phase offsets per axis.
Sourcepub fn add(self, other: MathFunction) -> MathFunction
pub fn add(self, other: MathFunction) -> MathFunction
Create a Sum of this function and another.
Sourcepub fn mul(self, other: MathFunction) -> MathFunction
pub fn mul(self, other: MathFunction) -> MathFunction
Create a Product of this function and another.
Sourcepub fn scale(self, factor: f32) -> MathFunction
pub fn scale(self, factor: f32) -> MathFunction
Scale the output by factor.
Sourcepub fn offset(self, offset: f32) -> MathFunction
pub fn offset(self, offset: f32) -> MathFunction
Add a constant offset to the output.
Sourcepub fn clamp(self, min: f32, max: f32) -> MathFunction
pub fn clamp(self, min: f32, max: f32) -> MathFunction
Clamp the output to [min, max].
Sourcepub fn delay(self, seconds: f32) -> MathFunction
pub fn delay(self, seconds: f32) -> MathFunction
Delay the function by seconds.
Sourcepub fn invert(self) -> MathFunction
pub fn invert(self) -> MathFunction
Invert (negate) the output.
Sourcepub fn modulate(self, modulator: MathFunction) -> MathFunction
pub fn modulate(self, modulator: MathFunction) -> MathFunction
Modulate by another function (amplitude modulation).
Trait Implementations§
Source§impl Clone for MathFunction
impl Clone for MathFunction
Source§fn clone(&self) -> MathFunction
fn clone(&self) -> MathFunction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MathFunction
impl RefUnwindSafe for MathFunction
impl Send for MathFunction
impl Sync for MathFunction
impl Unpin for MathFunction
impl UnsafeUnpin for MathFunction
impl UnwindSafe for MathFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.