use crate::patterns::fade::Fade; use crate::patterns::Pattern; use crate::{impl_pattern_none, Strip}; use serde::{Deserialize, Serialize}; /// # FadeRandom /// /// fade from one color to an other with random variations applied to each pixel #[derive(Serialize, Deserialize, Debug, Eq, Hash, PartialEq, Copy, Clone)] pub struct FadeRandom { #[serde(default)] pub(crate) current_iteration: usize, pub(crate) max_iteration: Option, pub(crate) stability: usize, fade: Fade, } impl Pattern for FadeRandom { impl_pattern_none!(FadeRandom, N); } // // impl Pattern for FadeRandom { // type Strip = Strip; // // fn is_last_iteration(&self) -> bool { // match self.max_iteration { // None => false, // Some(max_iter) => { // if self.current_iteration >= max_iter { // true // } else { // false // } // } // } // } // } impl Iterator for FadeRandom { type Item = Strip; fn next(&mut self) -> Option { let strip = self.fade.next(); match strip { None => None, Some(mut fade) => { let rng = rand::thread_rng(); for i in 0..N { match fade[i] { None => {} Some(pixel) => { fade[i] = Some(pixel.random_delta(self.stability, &mut rng.clone())) } } } Some(fade) } } } }