more patterns
This commit is contained in:
parent
8be1d4b0df
commit
393f7aa891
1 changed files with 78 additions and 11 deletions
89
src/main.rs
89
src/main.rs
|
@ -30,7 +30,7 @@ use crate::{
|
|||
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Inputs {
|
||||
pub struct Inputs {
|
||||
t: Duration,
|
||||
transition_time: Duration,
|
||||
|
||||
|
@ -39,7 +39,7 @@ struct Inputs {
|
|||
intensity: f32,
|
||||
cycle_len: Duration,
|
||||
|
||||
wave_peak: f32,
|
||||
wave_peak: f32
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,11 +57,11 @@ impl ColorGrid for Breathing {
|
|||
let mirrorphi = if phi < 0.5 { phi } else { 1.0-phi };
|
||||
let gamma =
|
||||
(
|
||||
(30.0) *
|
||||
(5.0) *
|
||||
mirrorphi *
|
||||
(
|
||||
0.5+ 0.5*f32::sin(
|
||||
inputs.t.as_millis() as f32
|
||||
inputs.t.as_millis() as f32
|
||||
/ inputs.cycle_len.as_millis() as f32
|
||||
)
|
||||
)
|
||||
|
@ -76,9 +76,8 @@ impl ColorGrid for Breathing {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct Anim2 { inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for Anim2 {
|
||||
struct PastelFade { inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for PastelFade {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let inputs = self.inputs.read().unwrap().clone();
|
||||
// let millis = self
|
||||
|
@ -95,6 +94,60 @@ impl ColorGrid for Anim2 {
|
|||
}
|
||||
}
|
||||
|
||||
struct UbootPrüfstandFade { inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for UbootPrüfstandFade {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
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;
|
||||
|
||||
let pi2 = 2.0 * 3.1415926;
|
||||
|
||||
let col1 =
|
||||
Rgb::from_color(
|
||||
&Hsv::<f32, Turns<f32>>::new(
|
||||
Turns( 0.65 ),
|
||||
0.9,
|
||||
0.5 + 0.5*f32::sin(i*pi2),//(4.0*i) %1.0
|
||||
)
|
||||
);
|
||||
|
||||
let col2 = Rgb::new(0.5+0.5*f32::sin(i*pi2), 0.0, 0.0);
|
||||
|
||||
let p = ( inputs.t.as_millis() as f32 / (32.0*inputs.cycle_len.as_millis() as f32)) % 1.0;
|
||||
if p >= 0.7 {
|
||||
col2
|
||||
} else {
|
||||
col1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ArcticRain { inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for ArcticRain {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
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;
|
||||
|
||||
let pi2 = 2.0 * 3.1415926;
|
||||
|
||||
let col1 =
|
||||
Rgb::from_color(
|
||||
&Hsv::<f32, Turns<f32>>::new(
|
||||
Turns( 0.65 ),
|
||||
0.9,
|
||||
1.0 - ((i + (2.0-p.y/4.0)) * 12.0) % 1.0,
|
||||
// (f32::sin(-p.y+i) * 12.0) % 1.0,
|
||||
)
|
||||
);
|
||||
|
||||
col1
|
||||
}
|
||||
}
|
||||
|
||||
enum Waveform {
|
||||
Sawtooth{ pulse_width: Duration },
|
||||
Square{ },
|
||||
|
@ -144,7 +197,9 @@ impl SceneLibrary {
|
|||
Box::new( Strobe{ inputs: inputs.clone(), subdivision: 16 } ),
|
||||
|
||||
// others
|
||||
Box::new( Anim2{ inputs: inputs.clone() } ),
|
||||
Box::new( PastelFade{ inputs: inputs.clone() } ),
|
||||
Box::new( UbootPrüfstandFade{ inputs: inputs.clone() } ),
|
||||
Box::new( ArcticRain{ inputs: inputs.clone() } ),
|
||||
],
|
||||
current_scene: RwLock::new(0),
|
||||
inputs,
|
||||
|
@ -217,7 +272,7 @@ async fn main() {
|
|||
// .with_driver( Box::new(MatrixTcpDriver::new("ip:port")) ),
|
||||
|
||||
Fixture::new_stripe()
|
||||
// .with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())) )
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())) )
|
||||
.offset(Vector2::new(-0.5, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
|
@ -225,7 +280,7 @@ async fn main() {
|
|||
.offset(Vector2::new(-0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
// .with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
.offset(Vector2::new(0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe()
|
||||
|
@ -249,7 +304,7 @@ async fn main() {
|
|||
inputs.write().unwrap().t = tcur - tbegin;
|
||||
inputs.write().unwrap().transition_time = tcur - transition_begin;
|
||||
lighting_setup.update_buffers();
|
||||
//lighting_setup.update_outputs();
|
||||
lighting_setup.update_outputs();
|
||||
|
||||
match event {
|
||||
Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } if window_id == window.id() => {
|
||||
|
@ -313,6 +368,18 @@ async fn main() {
|
|||
inputs.write().unwrap().scene_select = 4;
|
||||
transition_begin = std::time::Instant::now();
|
||||
}
|
||||
"5" => {
|
||||
inputs.write().unwrap().scene_select = 5;
|
||||
transition_begin = std::time::Instant::now();
|
||||
},
|
||||
"6" => {
|
||||
inputs.write().unwrap().scene_select = 6;
|
||||
transition_begin = std::time::Instant::now();
|
||||
}
|
||||
"7" => {
|
||||
inputs.write().unwrap().scene_select = 7;
|
||||
transition_begin = std::time::Instant::now();
|
||||
}
|
||||
|
||||
_=>{}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue