Skip to content

Commit

Permalink
Allow custom colors in the Lightning effect
Browse files Browse the repository at this point in the history
  • Loading branch information
4JX committed Oct 16, 2023
1 parent b959040 commit 8a39391
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions app/src/effects/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ pub(super) struct Lightning;
impl Lightning {
pub fn play(manager: &mut super::Inner, p: &Profile, thread_rng: &mut ThreadRng) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let profile_array = p.rgb_array();

if manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
break;
}
let zone = thread_rng.gen_range(0..4);
let zone_index = thread_rng.gen_range(0..4);
let steps = thread_rng.gen_range(50..=200);
manager.keyboard.set_zone_by_index(zone, [255; 3]).unwrap();

let mut arr = [0; 12];
let zone_start = zone_index * 3;

arr[zone_start] = profile_array[zone_start];
arr[zone_start + 1] = profile_array[zone_start + 1];
arr[zone_start + 2] = profile_array[zone_start + 2];

manager.keyboard.set_colors_to(&arr).unwrap();
manager.keyboard.transition_colors_to(&[0; 12], steps / p.speed, 5).unwrap();
let sleep_time = thread_rng.gen_range(100..=2000);
thread::sleep(Duration::from_millis(sleep_time));
Expand Down
2 changes: 1 addition & 1 deletion app/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PartialEq for Effects {
#[allow(dead_code)]
impl Effects {
pub fn takes_color_array(self) -> bool {
matches!(self, Self::Static | Self::Breath | Self::Swipe { .. } | Self::Fade | Self::Ripple)
matches!(self, Self::Static | Self::Breath | Self::Lightning | Self::Swipe { .. } | Self::Fade | Self::Ripple)
}

pub fn takes_direction(self) -> bool {
Expand Down

0 comments on commit 8a39391

Please sign in to comment.