add oneshotman

This commit is contained in:
Michael Sippel 2024-08-04 00:32:02 +02:00
parent 56a9480f0a
commit 1dd9ab4e94
Signed by: senvas
GPG key ID: 060F22F65102F95C
4 changed files with 55 additions and 2 deletions

View file

@ -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 {

View file

@ -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,
}

View file

@ -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
};

View file

@ -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<f32>) -> Rgb<f32> {
if p.y < self.pos {
Rgb::from_color(
&Hsv::<f32, Turns<f32>>::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)
}
}
}