Skip to main content

MathFunction

Enum MathFunction 

Source
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.

Fields

§slope: f32
§offset: f32
§

Sine

Sinusoidal oscillation.

Fields

§amplitude: f32
§frequency: f32
§phase: f32
§

Cosine

Cosinusoidal oscillation.

Fields

§amplitude: f32
§frequency: f32
§phase: f32
§

Triangle

Triangle wave oscillation.

Fields

§amplitude: f32
§frequency: f32
§phase: f32
§

Square

Square wave (snaps between +/- amplitude).

Fields

§amplitude: f32
§frequency: f32
§duty: f32
§

Lorenz

Lorenz attractor trajectory (x-coordinate).

Fields

§sigma: f32
§rho: f32
§beta: f32
§scale: f32
§

Perlin

Perlin noise.

Fields

§frequency: f32
§octaves: u8
§amplitude: f32
§

Simplex

Simplex noise.

Fields

§frequency: f32
§amplitude: f32
§

Exponential

Exponential approach to target: target + (start - target) * e^(-rate * t).

Fields

§start: f32
§target: f32
§rate: f32
§

LogisticMap

Logistic map iteration: x_{n+1} = r * x_n * (1 - x_n). Exhibits bifurcation.

Fields

§x0: f32
§

Collatz

Collatz sequence mapped to a float path. Bouncy convergence.

Fields

§seed: u64
§scale: f32
§

Orbit

Circular or elliptical orbit around a center point.

Fields

§center: Vec3
§radius: f32
§speed: f32
§eccentricity: f32
§

Spiral

Outward (or inward) spiral.

Fields

§center: Vec3
§radius_rate: f32
§speed: f32
§

GoldenSpiral

Golden-ratio spiral.

Fields

§center: Vec3
§scale: f32
§speed: f32
§

Lissajous

Lissajous figure.

Fields

§delta: f32
§scale: f32
§

StrangeAttractor

Move along a strange attractor trajectory (x-coordinate output).

Fields

§attractor_type: AttractorType
§scale: f32
§strength: f32
§

MandelbrotEscape

Mandelbrot escape-time mapped to float.

Fields

§c_real: f32
§c_imag: f32
§scale: f32
§

JuliaSet

Julia set escape-time mapped to float.

Fields

§c_real: f32
§c_imag: f32
§scale: f32
§

SpringDamper

Spring-damper: approaches target with optional overshoot.

Fields

§target: f32
§stiffness: f32
§damping: f32
§

CriticallyDamped

Critically damped spring (no overshoot, fastest convergence).

Fields

§target: f32
§speed: f32
§

HeartBeat

Realistic cardiac waveform (P, QRS, T waves).

Fields

§bpm: f32
§intensity: f32
§

Breathing

Four-phase breathing cycle: inhale → hold → exhale → hold.

Fields

§rate: f32
§depth: f32
§

Pendulum

Physical pendulum with gravity and damping.

Fields

§length: f32
§gravity: f32
§damping: f32
§

Wave

Traveling wave.

Fields

§wavelength: f32
§speed: f32
§amplitude: f32
§decay: f32
§

Sawtooth

Sawtooth wave (rising ramp that resets to -1).

Fields

§amplitude: f32
§frequency: f32
§phase: f32
§

Ramp

Ramp: linearly rises from 0 to amplitude over duration, then resets.

Fields

§amplitude: f32
§duration: f32
§

Sinc

Sinc function: sin(π·x) / (π·x). Used for signal reconstruction.

Fields

§frequency: f32
§amplitude: f32
§

Gaussian

Gaussian bell curve: amplitude · e^(-((t-center)/width)²).

Fields

§amplitude: f32
§center: f32
§width: f32
§

BeatFrequency

Two-frequency beat: interference between slightly detuned oscillators.

Fields

§freq1: f32
§freq2: f32
§amplitude: f32
§

WavePacket

Wave packet: Gaussian envelope × carrier sine.

Fields

§carrier_freq: f32
§envelope_width: f32
§amplitude: f32
§center: f32
§

FourierSeries

Fourier series: sum of harmonics with user-specified coefficients.

Fields

§fundamental: f32
§coefficients: Vec<(f32, f32)>
§

Sigmoid

Sigmoid (logistic) function maps any input → (0, 1).

Fields

§steepness: f32
§center: f32
§

Tanh

Hyperbolic tangent: amplitude · tanh(steepness · t).

Fields

§amplitude: f32
§steepness: f32
§

SoftPlus

Soft-plus: amplitude · ln(1 + e^(steepness·t)) / steepness.

Fields

§amplitude: f32
§steepness: f32
§

Relu

Rectified linear: max(0, slope·t + offset).

Fields

§slope: f32
§offset: f32
§

PowerLaw

Power law: sign(t) · |t|^exponent.

Fields

§exponent: f32
§scale: f32
§

VanDerPol

Van der Pol oscillator (nonlinear oscillator with limit cycle).

Fields

§mu: f32
§amplitude: f32
§

Duffing

Duffing oscillator (chaotic forced nonlinear oscillator).

Fields

§alpha: f32
§beta: f32
§delta: f32
§gamma: f32
§omega: f32
§

TentMap

Tent map iterated n times: exhibits period-doubling route to chaos.

Fields

§x0: f32
§

HenonMap

Hénon map: chaotic 2D map (returns x-coordinate).

Fields

§x0: f32
§y0: f32
§

Roessler

Rössler system x-coordinate trajectory.

Fields

§scale: f32
§

DoublePendulum

Double pendulum: chaotic system of two connected pendulums (angle θ₁).

Fields

§l1: f32
§l2: f32
§m1: f32
§m2: f32
§theta1_0: f32
§theta2_0: f32
§

Projectile

Projectile motion: height above ground (y-axis) at time t.

Fields

§v0: f32
§angle_deg: f32
§gravity: f32
§

SimpleHarmonic

Simple harmonic motion with optional initial displacement.

Fields

§omega: f32
§amplitude: f32
§phase: f32
§decay: f32
§

DampedSine

Damped sine with exact analytic form.

Fields

§omega: f32
§zeta: f32
§amplitude: f32
§phase: f32
§

Epicycle

Epicyclic motion: small circle of radius r2 orbiting at radius r1.

Fields

§r1: f32
§r2: f32
§omega1: f32
§omega2: f32
§

FractionalBrownian

Fractional Brownian motion: multi-octave noise with Hurst exponent H.

Fields

§frequency: f32
§octaves: u8
§hurst: f32
§amplitude: f32
§

DomainWarp

Domain-warped noise: the input to the noise is itself displaced by another noise.

Fields

§frequency: f32
§warp_strength: f32
§octaves: u8
§amplitude: f32
§

Cellular

Cellular / Worley noise: distance to nearest point in a Poisson point process.

Fields

§frequency: f32
§amplitude: f32
§

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.

Fields

§modulator: Box<MathFunction>
§

Clamp

Clamp the output to [min, max].

Fields

§min: f32
§max: f32
§

Abs(Box<MathFunction>)

Absolute value of inner.

§

Scale

Scale: multiply output of inner by factor.

Fields

§factor: f32
§

Offset

Offset: add offset to output of inner.

Fields

§offset: f32
§

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.)

Fields

§t_range: f32
§steps: u32
§

Delay

Delay: evaluate inner at (t - delay_seconds).

Fields

§delay: f32
§

Mirror

Mirror: map t → |t mod (2·period) - period| creating a symmetric waveform.

Fields

§period: f32

Implementations§

Source§

impl MathFunction

Source

pub fn evaluate(&self, t: f32, input: f32) -> f32

Evaluate the function at time t with chained input.

Source

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.

Source

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).

Source

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].

Source

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].

Source

pub fn zero_crossings(&self, t_start: f32, t_end: f32, steps: u32) -> Vec<f32>

Find approximate zero-crossings in [t_start, t_end].

Source

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.

Source

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.

Source

pub fn add(self, other: MathFunction) -> MathFunction

Create a Sum of this function and another.

Source

pub fn mul(self, other: MathFunction) -> MathFunction

Create a Product of this function and another.

Source

pub fn scale(self, factor: f32) -> MathFunction

Scale the output by factor.

Source

pub fn offset(self, offset: f32) -> MathFunction

Add a constant offset to the output.

Source

pub fn clamp(self, min: f32, max: f32) -> MathFunction

Clamp the output to [min, max].

Source

pub fn delay(self, seconds: f32) -> MathFunction

Delay the function by seconds.

Source

pub fn invert(self) -> MathFunction

Invert (negate) the output.

Source

pub fn modulate(self, modulator: MathFunction) -> MathFunction

Modulate by another function (amplitude modulation).

Trait Implementations§

Source§

impl Clone for MathFunction

Source§

fn clone(&self) -> MathFunction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MathFunction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,