From 783631182ca1bae4f10b2d1e945a45421dc851dd Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sat, 3 Aug 2024 19:58:25 +0200 Subject: [PATCH] move inputs to separate file & add Animation trait --- src/inputs.rs | 24 ++++++++++++++++++++++++ src/main.rs | 20 +++----------------- src/patterns/arctic_rain.rs | 1 - src/view.rs | 8 +++++++- 4 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 src/inputs.rs diff --git a/src/inputs.rs b/src/inputs.rs new file mode 100644 index 0000000..1dfaaaa --- /dev/null +++ b/src/inputs.rs @@ -0,0 +1,24 @@ + +use { + std::time::Duration, + crate::waveform::Waveform +}; + + +#[derive(Clone, Debug)] +pub struct Inputs { + pub t: Duration, + pub transition_time: Duration, + + pub scene_select: usize, + pub cycle_len: Duration, + pub wave_peak: f32, + + pub master_wave: Option< Waveform >, + pub master_subdivision: i32, + pub master_intensity: f32, + pub wheel: i32, + pub wheel2: i32, +} + + diff --git a/src/main.rs b/src/main.rs index 69761da..eddc3bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use { mod util; mod fixture; mod setup; +mod inputs; mod view; mod stripe_driver; mod jack; @@ -32,25 +33,10 @@ use crate::{ util::get_angle, scene_library::SceneLibrary, - waveform::Waveform + waveform::Waveform, + inputs::Inputs }; -#[derive(Clone, Debug)] -pub struct Inputs { - t: Duration, - transition_time: Duration, - - scene_select: usize, - cycle_len: Duration, - wave_peak: f32, - - master_wave: Option< Waveform >, - master_subdivision: i32, - master_intensity: f32, - wheel: i32, - wheel2: i32, -} - #[async_std::main] async fn main() { let event_loop = EventLoop::new().unwrap(); diff --git a/src/patterns/arctic_rain.rs b/src/patterns/arctic_rain.rs index c665b9e..4c21ba8 100644 --- a/src/patterns/arctic_rain.rs +++ b/src/patterns/arctic_rain.rs @@ -17,7 +17,6 @@ pub struct ArcticRain { pub inputs: Arc> } impl ColorGrid for ArcticRain { fn get(&self, p: &Vector2) -> Rgb { let inputs = self.inputs.read().unwrap().clone(); -// let millis = self let i = ( inputs.t.as_millis() as f32 / (4.0*inputs.cycle_len.as_millis() as f32) ) % 1.0; diff --git a/src/view.rs b/src/view.rs index e8359c2..8263636 100644 --- a/src/view.rs +++ b/src/view.rs @@ -1,9 +1,15 @@ use { cgmath::Vector2, - prisma::Rgb + prisma::Rgb, + + crate::inputs::Inputs }; pub trait ColorGrid { fn get(&self, pos: &Vector2) -> Rgb; } +pub trait Animation { + fn advance(&mut self, inputs: Inputs); +} +