pub struct AnimationClock {
pub phase: f32,
cursor_phase: f32,
}
impl AnimationClock {
pub fn new() -> Self {
Self {
phase: 0.0,
cursor_phase: 0.0,
}
}
pub fn tick(&mut self, dt_ms: u64) {
self.phase += (dt_ms as f32 / 2000.0) * std::f32::consts::TAU;
if self.phase > std::f32::consts::TAU {
self.phase -= std::f32::consts::TAU;
}
self.cursor_phase += (dt_ms as f32 / 1200.0) * std::f32::consts::TAU;
if self.cursor_phase > std::f32::consts::TAU {
self.cursor_phase -= std::f32::consts::TAU;
}
}
pub fn cursor_visible(&self) -> bool {
self.cursor_phase.sin() >= 0.0
}
pub fn reset_cursor(&mut self) {
self.cursor_phase = 0.0;
}
}