Skip to main content

vibe/animation/families/
generative.rs

1//! Generative Stochastic Fields Animation Family (Simplex flows, Vortices, Brownian walks).
2
3use crate::animation::pga::Motor;
4use crate::animation::presets::AnimationSample;
5
6/// Evaluates the families family.
7pub fn eval(preset: &str, t: f64) -> AnimationSample {
8    match preset {
9        "simplex_flow" | "simplex" => {
10            let vx = (t * 0.7).sin() * 0.6 + (t * 1.3).cos() * 0.4;
11            let vy = (t * 0.9).cos() * 0.5 + (t * 1.7).sin() * 0.5;
12            let speed = (vx * vx + vy * vy).sqrt();
13            AnimationSample {
14                scalar: speed,
15                vector: [vx, vy, 0.0],
16                motor: Motor::from_translation(vx * 2.0, vy * 2.0, 0.0),
17                secondary: speed,
18                settled: false,
19            }
20        }
21        "vortex_swirl" | "vortex" => {
22            let r = 1.0 + t * 0.5;
23            let theta = t * 4.0;
24            let x = r * theta.cos();
25            let z = r * theta.sin();
26            let motor = Motor::from_rotation_translation(
27                [(theta * 0.5).cos(), 0.0, (theta * 0.5).sin(), 0.0],
28                [x, 0.0, z],
29            );
30            AnimationSample {
31                scalar: theta,
32                vector: [x, 0.0, z],
33                motor,
34                secondary: r,
35                settled: false,
36            }
37        }
38        "brownian_drift" | "brownian" => {
39            let s1 = (t * 11.0).sin();
40            let s2 = (t * 17.0).cos();
41            let s3 = (t * 23.0).sin();
42            let val = (s1 + s2 + s3) / 3.0;
43            AnimationSample {
44                scalar: val,
45                vector: [s1 * 0.5, s2 * 0.5, s3 * 0.5],
46                motor: Motor::from_translation(s1 * 0.2, s2 * 0.2, s3 * 0.2),
47                secondary: val.abs(),
48                settled: false,
49            }
50        }
51        _ => AnimationSample::default(),
52    }
53}