1
0
mirror of https://github.com/4yn/slidershim.git synced 2024-11-27 23:10:49 +01:00

rainbow reactive

This commit is contained in:
4yn 2022-02-23 00:33:56 +08:00
parent d02990d5fc
commit 35da7d4874
3 changed files with 35 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use serde_json::Value;
pub enum ReactiveLayout {
Even { splits: usize },
Voltex,
Rainbow,
}
#[derive(Debug, Clone)]
@ -39,6 +40,10 @@ impl LightsMode {
layout: ReactiveLayout::Even { splits: 16 },
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-rainbow" => LightsMode::Reactive {
layout: ReactiveLayout::Rainbow,
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,
},
"reactive-voltex" => LightsMode::Reactive {
layout: ReactiveLayout::Voltex,
sensitivity: u8::try_from(v["ledSensitivity"].as_i64()?).ok()?,

View File

@ -114,6 +114,35 @@ impl LightsJob {
}
}
}
ReactiveLayout::Rainbow => {
let banks: Vec<bool> = flat_input
.chunks(2)
.take(16)
.map(|x| x.contains(&true))
.collect();
let theta = self
.started
.elapsed()
.div_duration_f64(Duration::from_secs(4))
% 1.0;
for idx in 0..31 {
let slice_theta = (&theta + (idx as f64) / 32.0) % 1.0;
let color = Srgb::from_color(Hsv::new(
slice_theta * 360.0,
match idx % 2 {
0 => match banks[idx / 2] {
true => 0.2,
false => 1.0,
},
1 => 1.0,
_ => unreachable!(),
},
1.0,
))
.into_format::<u8>();
lights.paint(idx, &[color.red, color.green, color.blue]);
}
}
}
}
LightsMode::Attract => {

View File

@ -328,6 +328,7 @@
<option value="reactive-4">Reactive, 4-Zone</option>
<option value="reactive-8">Reactive, 8-Zone</option>
<option value="reactive-16">Reactive, 16-Zone</option>
<option value="reactive-rainbow">Reactive, 16-Zone Rainbow</option>
<option value="reactive-voltex">Reactive, Voltex Layout</option>
<option value="attract">Rainbow Attract Mode</option>
<!-- <option value="websocket">Websocket</option> -->