From 8a3939155b6d15341f3b55968ec4af67d4d7a11a Mon Sep 17 00:00:00 2001 From: 4JX <79868816+4JX@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:22:10 +0200 Subject: [PATCH] Allow custom colors in the Lightning effect --- app/src/effects/lightning.rs | 14 ++++++++++++-- app/src/enums.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/effects/lightning.rs b/app/src/effects/lightning.rs index 0bebfac..cd6cc25 100644 --- a/app/src/effects/lightning.rs +++ b/app/src/effects/lightning.rs @@ -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)); diff --git a/app/src/enums.rs b/app/src/enums.rs index 84bfe4a..7d8054d 100644 --- a/app/src/enums.rs +++ b/app/src/enums.rs @@ -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 {