pub fn oscillate(elapsed: Duration, period: Duration) -> f32Expand description
A continuous sine wave sampled at elapsed, completing one full cycle every period, mapped
from its natural -1.0..=1.0 range to 0.0..=1.0.
For a finite transition that starts, runs once, and stops, see Tween
instead. This is for motion with no start or end (a pulsing indicator, a breathing effect):
keep accumulating elapsed every frame and re-sample.
Equivalent to oscillate_with_phase with phase 0.0. Two callers driving independent
pulses (say, a row of status dots) that both call plain oscillate with the same elapsed
and period will always be perfectly in sync; use oscillate_with_phase to stagger them.
use core::time::Duration;
use retroglyph_ui::oscillate;
let period = Duration::from_secs(2);
assert_eq!(oscillate(Duration::ZERO, period), 0.5); // sin(0) == 0, remapped to the midpoint
assert!((oscillate(Duration::from_millis(1500), period) - 0.0).abs() < 1e-6); // 3/4 through