From 1dd9ab4e948f1fed4b2151bcc4a196090be61856 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 4 Aug 2024 00:32:02 +0200 Subject: [PATCH] add oneshotman --- src/controller.rs | 3 ++- src/inputs.rs | 2 ++ src/patterns/mod.rs | 4 +++- src/patterns/oneshotman.rs | 48 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/patterns/oneshotman.rs diff --git a/src/controller.rs b/src/controller.rs index 9a8efb1..96e1244 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -125,7 +125,8 @@ impl Controller { "z" => { inputs.wheel -=1; } "e" => { inputs.wheel2 += 1; } "p"=> { inputs.wheel2 -= 1; } - + "a"=> { inputs.wheel3 -= 1; } + "i" => { inputs.wheel3 += 1; } "-" => { inputs.master_intensity *= -1.0; } "." => { if inputs.active { diff --git a/src/inputs.rs b/src/inputs.rs index 7797cb6..2a28e99 100644 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -19,6 +19,7 @@ pub struct Inputs { pub master_intensity: f32, pub wheel: i32, pub wheel2: i32, + pub wheel3: i32, pub active: bool, } @@ -38,6 +39,7 @@ impl Default for Inputs { master_intensity: 1.0, wheel: 0, wheel2: 0, + wheel3: 0, active: false, } diff --git a/src/patterns/mod.rs b/src/patterns/mod.rs index ea1796a..a8e6c07 100644 --- a/src/patterns/mod.rs +++ b/src/patterns/mod.rs @@ -7,6 +7,7 @@ pub mod gastel_fade; pub mod wheel; pub mod wave_fade; pub mod alternate; +pub mod oneshotman; #[path = "uboot_prüfstand_fade.rs"] pub mod uboot; @@ -20,7 +21,8 @@ pub use { wave_fade::WaveFade, uboot::UbootPrüfstandFade, wheel::Wheel, - alternate::Alternate + alternate::Alternate, + oneshotman::OneShotMan }; diff --git a/src/patterns/oneshotman.rs b/src/patterns/oneshotman.rs new file mode 100644 index 0000000..cd4c325 --- /dev/null +++ b/src/patterns/oneshotman.rs @@ -0,0 +1,48 @@ +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}, util::get_angle} +}; + +#[derive(Default)] +pub struct OneShotMan { + pub inputs: Inputs, + velocity: f32, + pos: f32, + last_t: std::time::Duration +} + +impl Animation for OneShotMan { + fn advance(&mut self, inputs: &Inputs) { + self.inputs = inputs.clone(); + self.velocity = (inputs.wheel as f32) / 16.0; + + self.pos = -0.8 + self.velocity * (self.inputs.t.as_millis() as f32) / 1000.0; + } +} +q +impl ColorGrid for OneShotMan { + fn get(&self, p: &Vector2) -> Rgb { + if p.y < self.pos { + Rgb::from_color( + &Hsv::>::new( + Turns( (self.inputs.wheel2 as f32 / 64.0).abs() % 1.0 ), + 0.8, + f32::exp( -(1.0 + (self.inputs.wheel3 as f32) * (self.pos - p.y)) ) + ) + ) + } else { + Rgb::new(0.0,0.0,0.0) + } + } +} +