code wiki / _hdl_build / nx_viz_ease.nx
nx_viz_ease.nx source
↩ module page · 17 lines · 924 B
1// nx_viz_ease.nx -- the EASING math core of the INTERACTION layer (the d3-transition/d3-ease core, bits-up).
2// Easing functions over normalized time t in permil [0,1000] -> eased permil, + interpolate-at. Pure integer ->
3// WASM-deployable. Closes anim-transition (the timing math; the RAF tick is the thin browser glue). license_tier: ORIGINAL
4import "nx_syscalls.nx"
5const K_MAGIC_2000: i64 = 2000
6
7func ve_linear(t: i64) -> i64 { return t }
8func ve_cubic_in(t: i64) -> i64 { return t * t / 1000 * t / 1000 }
9// cubic in-out: t<0.5 -> 4t^3 ; else 1 - (2-2t)^3 / 2.
10func ve_cubic_inout(t: i64) -> i64 {
11 if t < 500 { return 4 * t * t / 1000 * t / 1000 }
12 let u: i64 = K_MAGIC_2000 - 2 * t
13 return 1000 - (u * u / 1000 * u / 1000) / 2
14}
15// value at eased time: start + (end-start)*t/1000.
16func ve_at(start: i64, end: i64, t: i64) -> i64 { return start + (end - start) * t / 1000 }
17func main() -> i64 { return 0 }