Fix Fade pattern

This commit is contained in:
Austen Adler 2021-08-28 01:07:36 -04:00
parent 65aa41d780
commit 81bb9a2de0
2 changed files with 11 additions and 5 deletions

View File

@ -84,6 +84,11 @@ pub const RAINBOW: [Rgb; 7] = [
Rgb(148, 0, 211), // V 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 /// Merges a color by some factor
pub fn merge_colors(from_color: Rgb, to_color: Rgb, factor: f32) -> Rgb { 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(); let (from_r, from_g, from_b) = from_color.to_float_tuple();

View File

@ -1,8 +1,9 @@
use super::{FormRender, InputRender, Pattern}; use super::{FormRender, InputRender, Pattern};
use crate::color::{self, Rgb}; use crate::color::{self, merge_colors_u8, Rgb};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::vec_deque; use std::collections::vec_deque;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::iter;
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FadeParams { pub struct FadeParams {
@ -60,10 +61,10 @@ impl Pattern for Fade {
} }
self.step = self.step.saturating_sub(1); self.step = self.step.saturating_sub(1);
} }
self.lights_buf = VecDeque::from(vec![
Rgb(self.step, self.step, self.step); self.lights_buf = iter::repeat(merge_colors_u8(color::BLACK, self.color, self.step))
self.num_lights.into() .take(self.num_lights.into())
]); .collect();
Ok(true) Ok(true)
} }
fn init(&mut self, num_lights: u16) -> Result<(), ()> { fn init(&mut self, num_lights: u16) -> Result<(), ()> {