// Periodic timing derived from the global `time` (seconds since start), so a
// script gets repeating behavior without hand-rolling a dt accumulator in state.
// Import with: import "std/timer" as timer; then timer::phase(time, 2.0).
// A 0..1 sawtooth that resets every `period` seconds.
fn phase(time, period) {
(time % period) / period
}
// A 0..1..0 triangle over each `period`, for smooth back-and-forth motion.
fn ping_pong(time, period) {
let p = (time % period) / period;
if p < 0.5 { p * 2.0 } else { 2.0 - p * 2.0 }
}
// True for the first half of each `period`, a simple on/off blink.
fn pulse(time, period) {
(time % period) < (period * 0.5)
}