Compare commits
No commits in common. "67d7afbd78e148fd37c84687fd223dd16d24da29" and "eb42f5fa54ed7420a56d92530b824e954f371898" have entirely different histories.
67d7afbd78
...
eb42f5fa54
17 changed files with 232 additions and 458 deletions
|
@ -1,154 +0,0 @@
|
|||
use {
|
||||
std::time::{Instant, Duration},
|
||||
crate::waveform::Waveform,
|
||||
};
|
||||
|
||||
pub struct Controller {
|
||||
pub tbegin: Instant,
|
||||
pub transition_begin: Instant,
|
||||
pub last_tap: Instant,
|
||||
|
||||
pub ctrl: bool
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
pub fn new() -> Self {
|
||||
Controller {
|
||||
tbegin: Instant::now(),
|
||||
transition_begin: Instant::now(),
|
||||
last_tap: Instant::now(),
|
||||
ctrl: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_key(
|
||||
&mut self,
|
||||
event: winit::event::KeyEvent,
|
||||
inputs: &mut crate::inputs::Inputs,
|
||||
setup: &mut crate::setup::LightingSetup
|
||||
) {
|
||||
if event.state == winit::event::ElementState::Released {
|
||||
match event.logical_key {
|
||||
winit::keyboard::Key::Named(
|
||||
winit::keyboard::NamedKey::Control
|
||||
) => {
|
||||
eprintln!("released control");
|
||||
self.ctrl = false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else
|
||||
if event.state == winit::event::ElementState::Pressed {
|
||||
match event.logical_key {
|
||||
winit::keyboard::Key::Named(
|
||||
winit::keyboard::NamedKey::Control
|
||||
) => {
|
||||
eprintln!("pressed control");
|
||||
self.ctrl = true;
|
||||
}
|
||||
winit::keyboard::Key::Character(c) => {
|
||||
eprintln!("pressed {}", c);
|
||||
|
||||
if self.ctrl {
|
||||
if c.is_ascii() {
|
||||
match &c[0..1] {
|
||||
"0" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(0) {
|
||||
eprintln!("toggle mirror_y of fixture 0");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"1" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(1) {
|
||||
eprintln!("toggle mirror_y of fixture 1");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"2" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(2) {
|
||||
eprintln!("toggle mirror_y of fixture 2");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"3" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(3) {
|
||||
eprintln!("toggle mirror_y of fixture 3");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
"4" => {
|
||||
if let Some(f) = setup.fixtures.get_mut(4) {
|
||||
eprintln!("toggle mirror_y of fixture 4");
|
||||
f.mirror_y = !f.mirror_y;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if c.is_ascii() {
|
||||
match &c[0..1] {
|
||||
"x" => {
|
||||
// tap tempo
|
||||
let old_tap = self.last_tap;
|
||||
self.last_tap = std::time::Instant::now();
|
||||
|
||||
if (self.last_tap - old_tap) < Duration::from_millis(20000) {
|
||||
inputs.cycle_len = self.last_tap - old_tap;
|
||||
}
|
||||
}
|
||||
"q" => {
|
||||
// sync
|
||||
inputs.t = Duration::from_millis(0);
|
||||
self.tbegin = std::time::Instant::now();
|
||||
},
|
||||
"0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9" => {
|
||||
let idx = c.chars().nth(0).unwrap().to_digit(10).unwrap() as u32;
|
||||
inputs.scene_select = idx as usize;
|
||||
self.transition_begin = std::time::Instant::now();
|
||||
}
|
||||
"r" => { inputs.master_wave = match inputs.master_wave {
|
||||
None => Some(Waveform::Sine),
|
||||
Some(Waveform::Sine) => Some(Waveform::Triangle),
|
||||
Some(Waveform::Triangle) => Some(Waveform::Square),
|
||||
Some(Waveform::Square) => Some(Waveform::Sawtooth),
|
||||
Some(Waveform::Sawtooth) => None
|
||||
}
|
||||
}
|
||||
"," => { inputs.master_wave = None; }
|
||||
"n" => { inputs.master_intensity += 0.1; }
|
||||
"m" => { inputs.master_intensity -= 0.1; }
|
||||
"s" => { inputs.master_subdivision +=1; }
|
||||
"b" => { inputs.master_subdivision -=1; }
|
||||
"o" => { inputs.wheel +=1; }
|
||||
"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 {
|
||||
eprintln!("DEACTIVATED");
|
||||
inputs.active = false;
|
||||
} else {
|
||||
inputs.active = true;
|
||||
eprintln!("ACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
_=>{}
|
||||
}
|
||||
}
|
||||
|
||||
eprintln!("--------------");
|
||||
eprintln!("updated inputs:\n {:?}", inputs);
|
||||
eprintln!("--------------");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,21 +15,19 @@ pub struct Fixture {
|
|||
pub position: Vector2<f32>,
|
||||
pub rotation: f32,
|
||||
pub scale: f32,
|
||||
pub mirror_y: bool,
|
||||
pub brightness: f32,
|
||||
pub buffer: Vec< Rgb<u8> >,
|
||||
pub driver: Option<Box<dyn FixtureDriver>>
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
pub fn new_stripe(mirror_y: bool) -> Self {
|
||||
pub fn new_stripe() -> Self {
|
||||
let mut fixture = Fixture {
|
||||
resolution: Vector2::new(1, 72),
|
||||
position: Vector2::new(0.0, 0.0),
|
||||
rotation: 0.0,
|
||||
scale: 0.015,
|
||||
brightness: 0.8,
|
||||
mirror_y,
|
||||
buffer: Vec::new(),
|
||||
driver: None
|
||||
};
|
||||
|
@ -45,7 +43,6 @@ impl Fixture {
|
|||
position: Vector2::new(0.0, 0.0),
|
||||
rotation: 0.0,
|
||||
scale: 0.03,
|
||||
mirror_y: false,
|
||||
brightness: 0.8,
|
||||
buffer: Vec::new(),
|
||||
driver: None
|
||||
|
@ -73,17 +70,12 @@ impl Fixture {
|
|||
self.position + centered_pixpos * self.scale
|
||||
}
|
||||
|
||||
pub fn update_buffer(&mut self, view: &dyn crate::view::Animation) {
|
||||
pub fn update_buffer(&mut self, view: &Box<dyn ColorGrid>) {
|
||||
for xi in 0 .. self.resolution.x {
|
||||
for yi in 0 ..self.resolution.y {
|
||||
let gpos = self.get_global_pos(&Vector2::new(xi, yi));
|
||||
let col = view.get(&gpos);
|
||||
|
||||
let yi = if self.mirror_y {
|
||||
self.resolution.y - 1 - yi
|
||||
} else {
|
||||
yi
|
||||
};
|
||||
let index = xi + yi * self.resolution.x;
|
||||
self.buffer[index as usize] = Rgb::new(
|
||||
(col.red() * 255.0 * self.brightness) as u8,
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
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,
|
||||
pub wheel3: i32,
|
||||
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
impl Default for Inputs {
|
||||
fn default() -> Inputs {
|
||||
Inputs {
|
||||
t: Duration::from_millis(0),
|
||||
transition_time: Duration::from_millis(0),
|
||||
cycle_len: Duration::from_millis(300),
|
||||
wave_peak: 0.5,
|
||||
|
||||
scene_select: 0,
|
||||
|
||||
master_wave: None,
|
||||
master_subdivision: 0,
|
||||
master_intensity: 1.0,
|
||||
wheel: 0,
|
||||
wheel2: 0,
|
||||
wheel3: 0,
|
||||
|
||||
active: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
159
src/main.rs
159
src/main.rs
|
@ -16,12 +16,10 @@ use {
|
|||
mod util;
|
||||
mod fixture;
|
||||
mod setup;
|
||||
mod inputs;
|
||||
mod view;
|
||||
mod stripe_driver;
|
||||
mod jack;
|
||||
mod waveform;
|
||||
mod controller;
|
||||
|
||||
mod patterns;
|
||||
mod scene_library;
|
||||
|
@ -34,10 +32,25 @@ use crate::{
|
|||
util::get_angle,
|
||||
|
||||
scene_library::SceneLibrary,
|
||||
waveform::Waveform,
|
||||
inputs::Inputs
|
||||
waveform::Waveform
|
||||
};
|
||||
|
||||
#[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();
|
||||
|
@ -51,52 +64,64 @@ async fn main() {
|
|||
socket.write().unwrap().set_read_timeout(Some(std::time::Duration::from_millis(1)));
|
||||
socket.write().unwrap().set_write_timeout(Some(std::time::Duration::from_millis(1)));
|
||||
|
||||
let mut inputs = Inputs::default();
|
||||
let inputs = Arc::new(RwLock::new(
|
||||
Inputs {
|
||||
t: Duration::from_millis(0),
|
||||
transition_time: Duration::from_millis(0),
|
||||
cycle_len: Duration::from_millis(300),
|
||||
wave_peak: 0.5,
|
||||
|
||||
scene_select: 0,
|
||||
|
||||
master_wave: None,
|
||||
master_subdivision: 0,
|
||||
master_intensity: 1.0,
|
||||
wheel: 0,
|
||||
wheel2: 0
|
||||
}
|
||||
));
|
||||
|
||||
let mut lighting_setup = LightingSetup::new(
|
||||
vec![
|
||||
Fixture::new_matrix(),
|
||||
// .with_driver( Box::new(MatrixTcpDriver::new("ip:port")) ),
|
||||
|
||||
Fixture::new_stripe(false)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())) )
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())) )
|
||||
.offset(Vector2::new(-0.5, 0.0)),
|
||||
|
||||
Fixture::new_stripe(true)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
||||
.offset(Vector2::new(-0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe(true)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.112:4210", socket.clone())) )
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.113:4210", socket.clone())) )
|
||||
.offset(Vector2::new(0.4, 0.0)),
|
||||
|
||||
Fixture::new_stripe(false)
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.111:4210", socket.clone())))
|
||||
Fixture::new_stripe()
|
||||
.with_driver( Box::new(StripeDriver::new("192.168.0.114:4210", socket.clone())))
|
||||
.offset(Vector2::new(0.5, 0.0))
|
||||
],
|
||||
|
||||
Box::new( SceneLibrary::new() )
|
||||
Box::new( SceneLibrary::new(inputs.clone()) )
|
||||
);
|
||||
|
||||
let mut controller = controller::Controller::new();
|
||||
let mut tbegin = std::time::Instant::now();
|
||||
let mut transition_begin = std::time::Instant::now();
|
||||
let mut last_tap = std::time::Instant::now();
|
||||
let mut z = 0;
|
||||
|
||||
let mut frame_count = 0;
|
||||
let mut fps_sum_window = std::time::Instant::now();
|
||||
|
||||
lighting_setup.advance( &inputs );
|
||||
let mut active = false;
|
||||
|
||||
for i in 0..5 {
|
||||
lighting_setup.sync_fixture(i);
|
||||
}
|
||||
|
||||
event_loop.run(move |event, elwt| {
|
||||
let tcur = std::time::Instant::now();
|
||||
|
||||
elwt.set_control_flow(
|
||||
ControlFlow::WaitUntil(
|
||||
tcur + Duration::from_millis(25)
|
||||
));
|
||||
|
||||
// FPS statistics
|
||||
if (tcur - fps_sum_window).as_millis() > 5000 {
|
||||
let avg_fps = (1000.0 * frame_count as f32) / ((tcur - fps_sum_window).as_millis() as f32);
|
||||
eprintln!("avg fps: {}", avg_fps);
|
||||
|
@ -106,13 +131,15 @@ async fn main() {
|
|||
frame_count += 1;
|
||||
}
|
||||
|
||||
// update animation
|
||||
inputs.t = tcur - controller.tbegin;
|
||||
inputs.transition_time = tcur - controller.transition_begin;
|
||||
lighting_setup.advance( &inputs );
|
||||
elwt.set_control_flow(ControlFlow::
|
||||
WaitUntil(
|
||||
tcur + Duration::from_millis(25)
|
||||
));
|
||||
inputs.write().unwrap().t = tcur - tbegin;
|
||||
inputs.write().unwrap().transition_time = tcur - transition_begin;
|
||||
lighting_setup.update_buffers();
|
||||
|
||||
// refresh fixture outputs
|
||||
if inputs.active {
|
||||
if active {
|
||||
// sync
|
||||
let mut rbuf = [0 as u8; 8];
|
||||
|
||||
|
@ -158,12 +185,76 @@ async fn main() {
|
|||
window_id: _,
|
||||
event: winit::event::WindowEvent::KeyboardInput{ device_id, event, is_synthetic }
|
||||
} => {
|
||||
controller.handle_key(
|
||||
event, &mut inputs, &mut lighting_setup
|
||||
);
|
||||
}
|
||||
if event.state == winit::event::ElementState::Pressed {
|
||||
match event.logical_key {
|
||||
winit::keyboard::Key::Character(c) => {
|
||||
eprintln!("pressed {}", c);
|
||||
|
||||
_ => {}
|
||||
let mut inputs = inputs.write().unwrap();
|
||||
if c.is_ascii() {
|
||||
match &c[0..1] {
|
||||
"x" => {
|
||||
// tap tempo
|
||||
let old_tap = last_tap;
|
||||
last_tap = std::time::Instant::now();
|
||||
|
||||
if (last_tap - old_tap) < Duration::from_millis(20000) {
|
||||
inputs.cycle_len = last_tap - old_tap;
|
||||
}
|
||||
}
|
||||
"q" => {
|
||||
// sync
|
||||
inputs.t = Duration::from_millis(0);
|
||||
tbegin = std::time::Instant::now();
|
||||
},
|
||||
"0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9" => {
|
||||
let idx = c.chars().nth(0).unwrap().to_digit(10).unwrap() as u32;
|
||||
inputs.scene_select = idx as usize;
|
||||
transition_begin = std::time::Instant::now();
|
||||
}
|
||||
"r" => { inputs.master_wave = match inputs.master_wave {
|
||||
None => Some(Waveform::Sine),
|
||||
Some(Waveform::Sine) => Some(Waveform::Triangle),
|
||||
Some(Waveform::Triangle) => Some(Waveform::Square),
|
||||
Some(Waveform::Square) => Some(Waveform::Sawtooth),
|
||||
Some(Waveform::Sawtooth) => None
|
||||
}
|
||||
}
|
||||
"," => { inputs.master_wave = None; }
|
||||
"n" => { inputs.master_intensity += 0.1; }
|
||||
"m" => { inputs.master_intensity -= 0.1; }
|
||||
"s" => { inputs.master_subdivision +=1; }
|
||||
"b" => { inputs.master_subdivision -=1; }
|
||||
"o" => { inputs.wheel +=1; }
|
||||
"z" => { inputs.wheel -=1; }
|
||||
"e" => { inputs.wheel2 += 1; }
|
||||
"p"=> { inputs.wheel2 -= 1; }
|
||||
|
||||
"-" => { inputs.master_intensity *= -1.0; }
|
||||
"." => {
|
||||
if active {
|
||||
eprintln!("DEACTIVATED");
|
||||
active = false;
|
||||
} else {
|
||||
active = true;
|
||||
eprintln!("ACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
_=>{}
|
||||
}
|
||||
|
||||
eprintln!("--------------");
|
||||
eprintln!("updated inputs:\n {:?}", inputs);
|
||||
eprintln!("--------------");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let (width, height) = *dim.lock().unwrap();
|
||||
|
|
|
@ -10,27 +10,22 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}}
|
||||
crate::{Inputs, view::ColorGrid}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Alternate {
|
||||
pub inputs: Inputs,
|
||||
}
|
||||
|
||||
impl Animation for Alternate {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
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 = (self.inputs.wheel as f32 * self.inputs.t.as_millis() as f32 / self.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 ((50.0+p.y*128.0) / self.inputs.wheel as f32) as u32 % 2 == 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 {
|
||||
|
@ -43,6 +38,9 @@ impl ColorGrid for Alternate {
|
|||
Rgb::new(0.0, 0.0, 0.6)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,21 +10,16 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}}
|
||||
crate::{Inputs, view::ColorGrid}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ArcticRain { pub inputs: Inputs }
|
||||
|
||||
impl Animation for ArcticRain {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArcticRain { pub inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for ArcticRain {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let i = ( self.inputs.t.as_millis() as f32 / (4.0*self.inputs.cycle_len.as_millis() as f32) ) % 1.0;
|
||||
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;
|
||||
|
||||
|
@ -32,9 +27,9 @@ impl ColorGrid for ArcticRain {
|
|||
Rgb::from_color(
|
||||
&Hsv::<f32, Turns<f32>>::new(
|
||||
// Turns( 0.65 + 0.3*(inputs.wheel%10) as f32*0.1 ),
|
||||
Turns( (self.inputs.wheel.abs() % 256) as f32 / 256.0 ),
|
||||
Turns( (inputs.wheel.abs() % 256) as f32 / 256.0 ),
|
||||
0.9,
|
||||
1.0 - ((i + (2.0-p.y/(0.2*(1+self.inputs.wheel3.abs()) as f32))) * 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,
|
||||
)
|
||||
);
|
||||
|
|
|
@ -9,25 +9,17 @@ use {
|
|||
cgmath::{Point2, Vector2},
|
||||
std::time::Duration,
|
||||
angle::Turns,
|
||||
crate::{
|
||||
Inputs,
|
||||
view::{ColorGrid, Animation},
|
||||
util::get_angle
|
||||
}
|
||||
|
||||
crate::{Inputs, view::ColorGrid, util::get_angle}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Breathing { pub inputs: Inputs }
|
||||
|
||||
impl Animation for Breathing {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Breathing { pub inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for Breathing {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let millis = self.inputs.t.as_millis();
|
||||
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;
|
||||
|
@ -40,8 +32,8 @@ impl ColorGrid for Breathing {
|
|||
mirrorphi *
|
||||
(
|
||||
0.5+ 0.5*f32::sin(
|
||||
self.inputs.t.as_millis() as f32
|
||||
/ self.inputs.cycle_len.as_millis() as f32
|
||||
inputs.t.as_millis() as f32
|
||||
/ inputs.cycle_len.as_millis() as f32
|
||||
)
|
||||
)
|
||||
) % 1.0;
|
||||
|
@ -50,7 +42,7 @@ impl ColorGrid for Breathing {
|
|||
&Hsv::<f32, Turns<f32>>::new(
|
||||
Turns( 0.25+0.25*f32::sin(millis as f32/8000.0) + gamma*0.5 ),
|
||||
0.5 + r2 * 0.5,
|
||||
self.inputs.wave_peak,
|
||||
inputs.wave_peak,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ 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;
|
||||
|
@ -21,8 +20,7 @@ pub use {
|
|||
wave_fade::WaveFade,
|
||||
uboot::UbootPrüfstandFade,
|
||||
wheel::Wheel,
|
||||
alternate::Alternate,
|
||||
oneshotman::OneShotMan
|
||||
alternate::Alternate
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,21 +10,15 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}, util::get_angle}
|
||||
crate::{Inputs, view::ColorGrid, util::get_angle}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PastelFade { pub inputs: Inputs }
|
||||
|
||||
impl Animation for PastelFade {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PastelFade { pub inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for PastelFade {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let i = ( 5.0 + 0.7 * self.inputs.t.as_millis() as f32 / (16.0*self.inputs.cycle_len.as_millis() as f32) ) % 1.0;
|
||||
let inputs = self.inputs.read().unwrap().clone();
|
||||
|
||||
let i = ( 5.0 + 0.7 * inputs.t.as_millis() as f32 / (16.0*inputs.cycle_len.as_millis() as f32) ) % 1.0;
|
||||
|
||||
Rgb::from_color(
|
||||
&Hsv::<f32, Turns<f32>>::new(
|
||||
|
|
|
@ -10,23 +10,18 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}}
|
||||
crate::{Inputs, view::ColorGrid}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Strobe {
|
||||
pub inputs: Inputs,
|
||||
}
|
||||
|
||||
impl Animation for Strobe {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
pub inputs: Arc<RwLock< Inputs >>,
|
||||
}
|
||||
|
||||
impl ColorGrid for Strobe {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let t = (self.inputs.wheel as f32 * self.inputs.t.as_millis() as f32 / self.inputs.cycle_len.as_millis() as f32) % 1.0;
|
||||
let inputs = self.inputs.read().unwrap().clone();
|
||||
|
||||
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 {
|
||||
Rgb::new(0.3, 0.3, 0.3)
|
||||
|
|
|
@ -10,21 +10,16 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}}
|
||||
crate::{Inputs, view::ColorGrid}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UbootPrüfstandFade { pub inputs: Inputs }
|
||||
|
||||
impl Animation for UbootPrüfstandFade {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UbootPrüfstandFade { pub inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for UbootPrüfstandFade {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let i = ( self.inputs.t.as_millis() as f32 / (4.0*self.inputs.cycle_len.as_millis() as f32) ) % 1.0;
|
||||
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;
|
||||
|
||||
|
@ -39,7 +34,7 @@ impl ColorGrid for UbootPrüfstandFade {
|
|||
|
||||
let col2 = Rgb::new(0.8, 0.0, 0.0);
|
||||
|
||||
let p = ( self.inputs.t.as_millis() as f32 / (32.0*self.inputs.cycle_len.as_millis() as f32)) % 1.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 {
|
||||
|
|
|
@ -10,25 +10,21 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}, util::get_angle, waveform::Waveform}
|
||||
crate::{Inputs, view::ColorGrid, util::get_angle, waveform::Waveform}
|
||||
};
|
||||
|
||||
pub struct WaveFade { pub inputs: Inputs,
|
||||
pub struct WaveFade { pub inputs: Arc<RwLock< Inputs >>,
|
||||
pub hue: f32,
|
||||
}
|
||||
|
||||
impl Animation for WaveFade {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorGrid for WaveFade {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let nt = ( self.inputs.t.as_millis() as f32 / self.inputs.cycle_len.as_millis() as f32 );
|
||||
let inputs = self.inputs.read().unwrap().clone();
|
||||
|
||||
let nt = ( inputs.t.as_millis() as f32 / inputs.cycle_len.as_millis() as f32 );
|
||||
|
||||
let i =
|
||||
match self.inputs.wheel % 4 {
|
||||
match inputs.wheel % 4 {
|
||||
0 => Waveform::Sine{}.get_norm(nt),
|
||||
1 => Waveform::Triangle{}.get_norm(nt),
|
||||
2 => Waveform::Sawtooth{}.get_norm(nt),
|
||||
|
|
|
@ -10,21 +10,16 @@ use {
|
|||
std::time::Duration,
|
||||
angle::Turns,
|
||||
|
||||
crate::{Inputs, view::{ColorGrid, Animation}, util::get_angle}
|
||||
crate::{Inputs, view::ColorGrid, util::get_angle}
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Wheel { pub inputs: Inputs }
|
||||
|
||||
impl Animation for Wheel {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Wheel { pub inputs: Arc<RwLock< Inputs >> }
|
||||
impl ColorGrid for Wheel {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let millis = self.inputs.t.as_millis();
|
||||
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;
|
||||
|
@ -36,8 +31,8 @@ impl ColorGrid for Wheel {
|
|||
(5.0) *
|
||||
mirrorphi *
|
||||
(
|
||||
self.inputs.t.as_millis() as f32
|
||||
/ (self.inputs.cycle_len.as_millis() as f32 * (1.0 + (self.inputs.wheel as f32).abs()))
|
||||
inputs.t.as_millis() as f32
|
||||
/ (inputs.cycle_len.as_millis() as f32 * (1.0 + (inputs.wheel as f32).abs()))
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -45,7 +40,7 @@ impl ColorGrid for Wheel {
|
|||
&Hsv::<f32, Turns<f32>>::new(
|
||||
Turns( gamma*0.5 ),
|
||||
0.5 + r2 * 0.5,
|
||||
(self.inputs.wheel as f32 / 16.0),
|
||||
(inputs.wheel as f32 / 16.0),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -11,67 +11,56 @@ use {
|
|||
angle::Turns,
|
||||
|
||||
crate::Inputs,
|
||||
crate::view::{ColorGrid, Animation},
|
||||
crate::view::ColorGrid,
|
||||
crate::patterns::*
|
||||
};
|
||||
|
||||
|
||||
pub struct SceneLibrary {
|
||||
library: Vec< Box<dyn Animation> >,
|
||||
current_scene: usize,
|
||||
inputs: Inputs,
|
||||
library: Vec< Box<dyn ColorGrid> >,
|
||||
current_scene: RwLock<usize>,
|
||||
inputs: Arc<RwLock< Inputs >>,
|
||||
|
||||
transition_length: Duration,
|
||||
// transition_curve: enum { Constant, Linear, Sigmoid, Sinus }
|
||||
}
|
||||
|
||||
impl SceneLibrary {
|
||||
pub fn new() -> Self {
|
||||
pub fn new( inputs: Arc<RwLock<Inputs>> ) -> Self {
|
||||
SceneLibrary {
|
||||
library: vec![
|
||||
// 0
|
||||
Box::new( Breathing::default() ),
|
||||
Box::new( Breathing{ inputs: inputs.clone() } ),
|
||||
|
||||
// 1
|
||||
Box::new( Strobe::default() ),
|
||||
Box::new( Strobe{ inputs: inputs.clone() } ),
|
||||
// 2
|
||||
// Box::new( WaveFade{ inputs: inputs.clone(), hue: 0.5 } ),
|
||||
Box::new( WaveFade{ inputs: inputs.clone(), hue: 0.5 } ),
|
||||
// 3
|
||||
Box::new( UbootPrüfstandFade::default() ),
|
||||
Box::new( UbootPrüfstandFade{ inputs: inputs.clone() } ),
|
||||
//4
|
||||
Box::new( ArcticRain::default() ),
|
||||
Box::new( ArcticRain{ inputs: inputs.clone() } ),
|
||||
//5
|
||||
Box::new( Wheel::default() ),
|
||||
Box::new( Wheel{ inputs: inputs.clone() } ),
|
||||
//6
|
||||
Box::new( Alternate::default() ),
|
||||
Box::new( Alternate{ inputs: inputs.clone() } ),
|
||||
//7
|
||||
Box::new( PastelFade::default() ),
|
||||
//8
|
||||
Box::new( OneShotMan::default() )
|
||||
Box::new( PastelFade{ inputs: inputs.clone() } ),
|
||||
],
|
||||
current_scene: 0,
|
||||
inputs: Inputs::default(),
|
||||
current_scene: RwLock::new(0),
|
||||
inputs,
|
||||
transition_length: Duration::from_millis(200),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Animation for SceneLibrary {
|
||||
fn advance(&mut self, inputs: &Inputs) {
|
||||
self.inputs = inputs.clone();
|
||||
|
||||
if self.inputs.transition_time.as_millis() as f32 > self.transition_length.as_millis() as f32 {
|
||||
// change own state:
|
||||
self.current_scene = self.inputs.scene_select;
|
||||
}
|
||||
|
||||
if let Some(a) = self.library.get_mut(self.current_scene) {
|
||||
a.advance( inputs );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorGrid for SceneLibrary {
|
||||
fn get(&self, p: &Vector2<f32>) -> Rgb<f32> {
|
||||
let mut intensity: f32 = self.inputs.master_intensity;
|
||||
let inputs = self.inputs.read().unwrap().clone();
|
||||
|
||||
let sc = *self.current_scene.read().unwrap();
|
||||
|
||||
let mut intensity: f32 = inputs.master_intensity;
|
||||
if intensity > 1.0 {
|
||||
intensity = 1.0;
|
||||
}
|
||||
|
@ -79,19 +68,20 @@ impl ColorGrid for SceneLibrary {
|
|||
intensity = -1.0;
|
||||
}
|
||||
|
||||
if let Some(w) = self.inputs.master_wave.clone() {
|
||||
if let Some(w) = inputs.master_wave {
|
||||
intensity *= w.get_doub(
|
||||
self.inputs.t.as_millis() as f32
|
||||
/ self.inputs.cycle_len.as_millis() as f32
|
||||
inputs.t.as_millis() as f32
|
||||
/ inputs.cycle_len.as_millis() as f32
|
||||
);
|
||||
}
|
||||
|
||||
if self.inputs.scene_select < self.library.len() {
|
||||
if inputs.scene_select < self.library.len() {
|
||||
|
||||
if self.inputs.scene_select == self.current_scene {
|
||||
|
||||
if inputs.scene_select == sc {
|
||||
// display only one animation
|
||||
let mut hsv = Hsv::from_color(
|
||||
&self.library[ self.current_scene ].get(p)
|
||||
&self.library[ sc ].get(p)
|
||||
);
|
||||
|
||||
hsv = Hsv::<f32>::new(
|
||||
|
@ -103,18 +93,24 @@ impl ColorGrid for SceneLibrary {
|
|||
Rgb::from_color(&hsv)
|
||||
} else {
|
||||
// display transition
|
||||
let cur_scene = &self.library[ self.current_scene ];
|
||||
let nxt_scene = &self.library[ self.inputs.scene_select ];
|
||||
let cur_scene = &self.library[ sc ];
|
||||
let nxt_scene = &self.library[ inputs.scene_select ];
|
||||
|
||||
// crossfade param
|
||||
let w = ( self.inputs.transition_time.as_millis() as f32 / self.transition_length.as_millis() as f32 );
|
||||
let w = ( inputs.transition_time.as_millis() as f32 / self.transition_length.as_millis() as f32 );
|
||||
|
||||
if w >= 1.0 {
|
||||
// change own state:
|
||||
*self.current_scene.write().unwrap() = inputs.scene_select;
|
||||
}
|
||||
|
||||
cur_scene.get(p)
|
||||
.lerp(
|
||||
&nxt_scene.get(p),
|
||||
w
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Rgb::new(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
|
20
src/setup.rs
20
src/setup.rs
|
@ -1,8 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
fixture::Fixture,
|
||||
inputs::Inputs,
|
||||
view::{ColorGrid, Animation}
|
||||
view::ColorGrid
|
||||
},
|
||||
cgmath::Vector2,
|
||||
std::time::Duration,
|
||||
|
@ -10,25 +9,25 @@ use {
|
|||
};
|
||||
|
||||
pub struct LightingSetup {
|
||||
pub fixtures: Vec<Fixture>,
|
||||
fixtures: Vec<Fixture>,
|
||||
t: Arc<RwLock<Duration>>,
|
||||
|
||||
animation: Box<dyn Animation>
|
||||
view: Box<dyn ColorGrid>
|
||||
}
|
||||
|
||||
impl LightingSetup {
|
||||
pub fn new(fixtures: Vec<Fixture>, animation: Box<dyn Animation>) -> Self {
|
||||
pub fn new(fixtures: Vec<Fixture>, view: Box<dyn ColorGrid>) -> Self {
|
||||
let t = Arc::new(RwLock::new(Duration::from_millis(0)));
|
||||
LightingSetup {
|
||||
fixtures,
|
||||
t: t.clone(),
|
||||
animation
|
||||
view
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_buffers(&mut self) {
|
||||
for fixture in self.fixtures.iter_mut() {
|
||||
fixture.update_buffer( self.animation.as_ref() );
|
||||
fixture.update_buffer( &self.view );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,11 +46,6 @@ impl LightingSetup {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn advance(&mut self, inputs: &Inputs) {
|
||||
self.animation.advance(inputs);
|
||||
self.update_buffers();
|
||||
}
|
||||
|
||||
pub fn draw_preview(
|
||||
&self,
|
||||
buffer: &mut softbuffer::Buffer<'_, Arc<winit::window::Window>, Arc<winit::window::Window>>,
|
||||
|
@ -71,7 +65,7 @@ impl LightingSetup {
|
|||
let xf = (x as f32 - width as f32/2.0) / mindim as f32;
|
||||
let yf = -(y as f32 - height as f32/2.0) / mindim as f32;
|
||||
|
||||
let color = self.animation.get(&Vector2::new(xf, yf));
|
||||
let color = self.view.get(&Vector2::new(xf, yf));
|
||||
|
||||
|
||||
let red = (color.red() * 16.0) as u32;
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
use {
|
||||
cgmath::Vector2,
|
||||
prisma::Rgb,
|
||||
|
||||
crate::inputs::Inputs
|
||||
prisma::Rgb
|
||||
};
|
||||
|
||||
pub trait ColorGrid {
|
||||
fn get(&self, pos: &Vector2<f32>) -> Rgb<f32>;
|
||||
}
|
||||
pub trait Animation : ColorGrid {
|
||||
fn advance(&mut self, inputs: &Inputs);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue