Fix Fade pattern
This commit is contained in:
parent
65aa41d780
commit
81bb9a2de0
@ -84,6 +84,11 @@ pub const RAINBOW: [Rgb; 7] = [
|
||||
Rgb(148, 0, 211), // V
|
||||
];
|
||||
|
||||
pub fn merge_colors_u8(from_color: Rgb, to_color: Rgb, factor: u8) -> Rgb {
|
||||
let factor = (factor as f32) / 255.0_f32;
|
||||
merge_colors(from_color, to_color, factor)
|
||||
}
|
||||
|
||||
/// Merges a color by some factor
|
||||
pub fn merge_colors(from_color: Rgb, to_color: Rgb, factor: f32) -> Rgb {
|
||||
let (from_r, from_g, from_b) = from_color.to_float_tuple();
|
||||
|
@ -1,8 +1,9 @@
|
||||
use super::{FormRender, InputRender, Pattern};
|
||||
use crate::color::{self, Rgb};
|
||||
use crate::color::{self, merge_colors_u8, Rgb};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::vec_deque;
|
||||
use std::collections::VecDeque;
|
||||
use std::iter;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct FadeParams {
|
||||
@ -60,10 +61,10 @@ impl Pattern for Fade {
|
||||
}
|
||||
self.step = self.step.saturating_sub(1);
|
||||
}
|
||||
self.lights_buf = VecDeque::from(vec![
|
||||
Rgb(self.step, self.step, self.step);
|
||||
self.num_lights.into()
|
||||
]);
|
||||
|
||||
self.lights_buf = iter::repeat(merge_colors_u8(color::BLACK, self.color, self.step))
|
||||
.take(self.num_lights.into())
|
||||
.collect();
|
||||
Ok(true)
|
||||
}
|
||||
fn init(&mut self, num_lights: u16) -> Result<(), ()> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user