patterns from saturday
- add wheel input parameter - gastel fade - alternate
This commit is contained in:
parent
132e999153
commit
58e95eb2bc
11 changed files with 212 additions and 15 deletions
|
@ -5,10 +5,9 @@ use {
|
||||||
crate::view::ColorGrid
|
crate::view::ColorGrid
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub trait FixtureDriver {
|
pub trait FixtureDriver {
|
||||||
fn send(&self, pixels: &Vec<Rgb<u8>>);
|
fn send(&self, pixels: &Vec<Rgb<u8>>);
|
||||||
|
fn sync(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Fixture {
|
pub struct Fixture {
|
||||||
|
|
50
src/main.rs
50
src/main.rs
|
@ -43,7 +43,8 @@ pub struct Inputs {
|
||||||
intensity: f32,
|
intensity: f32,
|
||||||
cycle_len: Duration,
|
cycle_len: Duration,
|
||||||
|
|
||||||
wave_peak: f32
|
wave_peak: f32,
|
||||||
|
wheel: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::main]
|
#[async_std::main]
|
||||||
|
@ -68,7 +69,8 @@ async fn main() {
|
||||||
cycle_len: Duration::from_millis(300),
|
cycle_len: Duration::from_millis(300),
|
||||||
wave_peak: 0.5,
|
wave_peak: 0.5,
|
||||||
|
|
||||||
scene_select: 0
|
scene_select: 0,
|
||||||
|
wheel: 0
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -84,10 +86,11 @@ async fn main() {
|
||||||
Fixture::new_stripe()
|
Fixture::new_stripe()
|
||||||
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
||||||
.offset(Vector2::new(-0.4, 0.0)),
|
.offset(Vector2::new(-0.4, 0.0)),
|
||||||
|
/*
|
||||||
Fixture::new_stripe()
|
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)),
|
.offset(Vector2::new(0.4, 0.0)),
|
||||||
|
*/
|
||||||
|
|
||||||
Fixture::new_stripe()
|
Fixture::new_stripe()
|
||||||
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())))
|
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())))
|
||||||
|
@ -100,17 +103,25 @@ async fn main() {
|
||||||
let mut tbegin = std::time::Instant::now();
|
let mut tbegin = std::time::Instant::now();
|
||||||
let mut transition_begin = std::time::Instant::now();
|
let mut transition_begin = std::time::Instant::now();
|
||||||
let mut last_tap = std::time::Instant::now();
|
let mut last_tap = std::time::Instant::now();
|
||||||
|
let mut z = 0;
|
||||||
|
|
||||||
|
let mut active = true;
|
||||||
|
|
||||||
event_loop.run(move |event, elwt| {
|
event_loop.run(move |event, elwt| {
|
||||||
let tcur = std::time::Instant::now();
|
let tcur = std::time::Instant::now();
|
||||||
elwt.set_control_flow(ControlFlow::WaitUntil(
|
elwt.set_control_flow(ControlFlow::
|
||||||
|
WaitUntil(
|
||||||
tcur + Duration::from_millis(10)
|
tcur + Duration::from_millis(10)
|
||||||
));
|
));
|
||||||
|
|
||||||
inputs.write().unwrap().t = tcur - tbegin;
|
inputs.write().unwrap().t = tcur - tbegin;
|
||||||
inputs.write().unwrap().transition_time = tcur - transition_begin;
|
inputs.write().unwrap().transition_time = tcur - transition_begin;
|
||||||
lighting_setup.update_buffers();
|
lighting_setup.update_buffers();
|
||||||
lighting_setup.update_outputs();
|
|
||||||
|
if active {
|
||||||
|
for i in 1..4 {
|
||||||
|
lighting_setup.update_outputs(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } if window_id == window.id() => {
|
Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } if window_id == window.id() => {
|
||||||
|
@ -186,6 +197,33 @@ async fn main() {
|
||||||
inputs.write().unwrap().scene_select = 7;
|
inputs.write().unwrap().scene_select = 7;
|
||||||
transition_begin = std::time::Instant::now();
|
transition_begin = std::time::Instant::now();
|
||||||
}
|
}
|
||||||
|
"8" => {
|
||||||
|
inputs.write().unwrap().scene_select = 8;
|
||||||
|
transition_begin = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
"9" => {
|
||||||
|
inputs.write().unwrap().scene_select = 9;
|
||||||
|
transition_begin = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
"a" => {
|
||||||
|
inputs.write().unwrap().scene_select = 10;
|
||||||
|
transition_begin = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
"m" => {
|
||||||
|
if active {
|
||||||
|
eprintln!("DEACTIVATED");
|
||||||
|
active = false;
|
||||||
|
} else {
|
||||||
|
active = true;
|
||||||
|
eprintln!("ACTIVATED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"+" => {
|
||||||
|
inputs.write().unwrap().wheel +=1;
|
||||||
|
}
|
||||||
|
"-" => {
|
||||||
|
inputs.write().unwrap().wheel -=1;
|
||||||
|
}
|
||||||
|
|
||||||
_=>{}
|
_=>{}
|
||||||
}
|
}
|
||||||
|
|
47
src/patterns/alternate.rs
Normal file
47
src/patterns/alternate.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Alternate {
|
||||||
|
pub inputs: Arc<RwLock< Inputs >>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ColorGrid for Alternate {
|
||||||
|
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||||
|
let inputs = self.inputs.read().unwrap().clone();
|
||||||
|
|
||||||
|
let switch = 0;
|
||||||
|
|
||||||
|
let t = (inputs.wheel as f32 * inputs.t.as_millis() as f32 / inputs.cycle_len.as_millis() as f32) % 1.0;
|
||||||
|
|
||||||
|
if ((50.0+p.y*128.0) / inputs.wheel as f32) as u32 % 2 == 0 {
|
||||||
|
if t < 0.5 {
|
||||||
|
Rgb::new(0.5, 0.2, 0.2)
|
||||||
|
} else {
|
||||||
|
Rgb::new(0.05, 0.05, 0.05)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if t < 0.5 {
|
||||||
|
Rgb::new(0.05, 0.05, 0.05)
|
||||||
|
} else {
|
||||||
|
Rgb::new(0.3, 0.3, 0.6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl ColorGrid for ArcticRain {
|
||||||
let col1 =
|
let col1 =
|
||||||
Rgb::from_color(
|
Rgb::from_color(
|
||||||
&Hsv::<f32, Turns<f32>>::new(
|
&Hsv::<f32, Turns<f32>>::new(
|
||||||
Turns( 0.65 ),
|
Turns( 0.65 + 0.3*(inputs.wheel%10) as f32*0.1 ),
|
||||||
0.9,
|
0.9,
|
||||||
1.0 - ((i + (2.0-p.y/4.0)) * 12.0) % 1.0,
|
1.0 - ((i + (2.0-p.y/4.0)) * 12.0) % 1.0,
|
||||||
// (f32::sin(-p.y+i) * 12.0) % 1.0,
|
// (f32::sin(-p.y+i) * 12.0) % 1.0,
|
||||||
|
|
37
src/patterns/gastel_fade.rs
Normal file
37
src/patterns/gastel_fade.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
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, util::get_angle}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct GastelFade { pub inputs: Arc<RwLock< Inputs >> }
|
||||||
|
impl ColorGrid for GastelFade {
|
||||||
|
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||||
|
let inputs = self.inputs.read().unwrap().clone();
|
||||||
|
|
||||||
|
let i = ( inputs.t.as_millis() as f32 / (4.0*inputs.cycle_len.as_millis() as f32) ) % 1.0;
|
||||||
|
|
||||||
|
let w = (inputs.t.as_millis() as f32 / (inputs.wheel as f32*inputs.cycle_len.as_millis() as f32)) % 1.0;
|
||||||
|
|
||||||
|
Rgb::from_color(
|
||||||
|
&Hsv::<f32, Turns<f32>>::new(
|
||||||
|
Turns( 0.73 + f32::cos(i/100.0)*0.2 ),
|
||||||
|
w,
|
||||||
|
if i < 0.25 {
|
||||||
|
1.0
|
||||||
|
} else {
|
||||||
|
f32::cos(i*3.0)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,9 @@ pub mod breathing;
|
||||||
pub mod strobe;
|
pub mod strobe;
|
||||||
pub mod arctic_rain;
|
pub mod arctic_rain;
|
||||||
pub mod pastel_fade;
|
pub mod pastel_fade;
|
||||||
|
pub mod gastel_fade;
|
||||||
|
pub mod wheel;
|
||||||
|
pub mod alternate;
|
||||||
|
|
||||||
#[path = "uboot_prüfstand_fade.rs"]
|
#[path = "uboot_prüfstand_fade.rs"]
|
||||||
pub mod uboot;
|
pub mod uboot;
|
||||||
|
@ -12,7 +15,10 @@ pub use {
|
||||||
strobe::Strobe,
|
strobe::Strobe,
|
||||||
arctic_rain::ArcticRain,
|
arctic_rain::ArcticRain,
|
||||||
pastel_fade::PastelFade,
|
pastel_fade::PastelFade,
|
||||||
uboot::UbootPrüfstandFade
|
gastel_fade::GastelFade,
|
||||||
|
uboot::UbootPrüfstandFade,
|
||||||
|
wheel::Wheel,
|
||||||
|
alternate::Alternate
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@ impl ColorGrid for Strobe {
|
||||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||||
let inputs = self.inputs.read().unwrap().clone();
|
let inputs = self.inputs.read().unwrap().clone();
|
||||||
|
|
||||||
let t = (self.subdivision as f32 * inputs.t.as_millis() as f32 / inputs.cycle_len.as_millis() as f32) % 1.0;
|
let t = (inputs.wheel as f32 * inputs.t.as_millis() as f32 / inputs.cycle_len.as_millis() as f32) % 1.0;
|
||||||
|
|
||||||
if t < 0.6 {
|
if t < 0.6 {
|
||||||
Rgb::new(0.6, 0.6, 0.6)
|
Rgb::new(0.3, 0.3, 0.3)
|
||||||
} else {
|
} else {
|
||||||
Rgb::new(0.0, 0.0, 0.0)
|
Rgb::new(0.05, 0.05, 0.05)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
src/patterns/wheel.rs
Normal file
48
src/patterns/wheel.rs
Normal 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, util::get_angle}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Wheel { pub inputs: Arc<RwLock< Inputs >> }
|
||||||
|
impl ColorGrid for Wheel {
|
||||||
|
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||||
|
let inputs = self.inputs.read().unwrap().clone();
|
||||||
|
|
||||||
|
let millis = inputs.t.as_millis();
|
||||||
|
|
||||||
|
let p1 = p + Vector2::new(0.0,0.5);
|
||||||
|
let r2 = p1.x*p1.x + p1.y*p1.y;
|
||||||
|
let v = if r2 > 1.0 { 1.0 } else { r2 };
|
||||||
|
let phi = ( get_angle(&p1) );
|
||||||
|
let mirrorphi = if phi < 0.5 { phi } else { 1.0-phi };
|
||||||
|
let gamma =
|
||||||
|
0.5 + 0.5*f32::cos(
|
||||||
|
(5.0) *
|
||||||
|
mirrorphi *
|
||||||
|
(
|
||||||
|
inputs.t.as_millis() as f32
|
||||||
|
/ (inputs.cycle_len.as_millis() as f32 * (1.0 + (inputs.wheel as f32).abs()))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Rgb::from_color(
|
||||||
|
&Hsv::<f32, Turns<f32>>::new(
|
||||||
|
Turns( gamma*0.5 ),
|
||||||
|
0.5 + r2 * 0.5,
|
||||||
|
(inputs.wheel as f32 / 16.0),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,12 @@ impl SceneLibrary {
|
||||||
Box::new( PastelFade{ inputs: inputs.clone() } ),
|
Box::new( PastelFade{ inputs: inputs.clone() } ),
|
||||||
Box::new( UbootPrüfstandFade{ inputs: inputs.clone() } ),
|
Box::new( UbootPrüfstandFade{ inputs: inputs.clone() } ),
|
||||||
Box::new( ArcticRain{ inputs: inputs.clone() } ),
|
Box::new( ArcticRain{ inputs: inputs.clone() } ),
|
||||||
|
|
||||||
|
Box::new( GastelFade{ inputs: inputs.clone() } ),
|
||||||
|
Box::new( Wheel{ inputs: inputs.clone() } ),
|
||||||
|
|
||||||
|
|
||||||
|
Box::new( Alternate{ inputs: inputs.clone() } ),
|
||||||
],
|
],
|
||||||
current_scene: RwLock::new(0),
|
current_scene: RwLock::new(0),
|
||||||
inputs,
|
inputs,
|
||||||
|
|
16
src/setup.rs
16
src/setup.rs
|
@ -31,12 +31,26 @@ impl LightingSetup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_outputs(&mut self) {
|
pub fn update_outputs(&mut self, id: usize) {
|
||||||
|
/*
|
||||||
for fixture in self.fixtures.iter() {
|
for fixture in self.fixtures.iter() {
|
||||||
if let Some(driver) = fixture.driver.as_ref() {
|
if let Some(driver) = fixture.driver.as_ref() {
|
||||||
driver.send( &fixture.buffer );
|
driver.send( &fixture.buffer );
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
let fixture = &self.fixtures[id];
|
||||||
|
if let Some(driver) = fixture.driver.as_ref() {
|
||||||
|
driver.send( &fixture.buffer );
|
||||||
|
//driver.sync();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
for fixture in self.fixtures.iter() {
|
||||||
|
if let Some(driver) = fixture.driver.as_ref() {
|
||||||
|
driver.sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_preview(
|
pub fn draw_preview(
|
||||||
|
|
|
@ -30,7 +30,9 @@ impl FixtureDriver for StripeDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.socket.write().unwrap().send_to(&buf, &self.addr);
|
self.socket.write().unwrap().send_to(&buf, &self.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync(&self) {
|
||||||
let mut rbuf = [0 as u8; 8];
|
let mut rbuf = [0 as u8; 8];
|
||||||
match
|
match
|
||||||
self.socket.write().unwrap().recv(&mut rbuf) {
|
self.socket.write().unwrap().recv(&mut rbuf) {
|
||||||
|
|
Loading…
Reference in a new issue