light-control/src/patterns/strobe.rs

39 lines
903 B
Rust

use {
std::num::NonZeroU32,
std::sync::{Arc, RwLock, Mutex},
std::rc::Rc,
winit::event::{Event, WindowEvent},
winit::event_loop::{ControlFlow, EventLoop},
winit::window::WindowBuilder,
prisma::{Rgb,Hsv,FromColor, Lerp},
cgmath::{Point2, Vector2},
std::time::Duration,
angle::Turns,
crate::{Inputs, view::{ColorGrid, Animation}}
};
#[derive(Default)]
pub struct Strobe {
pub inputs: Inputs,
}
impl Animation for Strobe {
fn advance(&mut self, inputs: &Inputs) {
self.inputs = inputs.clone();
}
}
impl ColorGrid for Strobe {
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
let t = (self.inputs.wheel as f32 * self.inputs.t.as_millis() as f32 / self.inputs.cycle_len.as_millis() as f32) % 1.0;
if t < 0.6 {
Rgb::new(0.3, 0.3, 0.3)
} else {
Rgb::new(0.05, 0.05, 0.05)
}
}
}