use crate::patterns::fade::Fade; use crate::Strip; use serde::{Serialize, Deserialize}; use crate::patterns::Pattern; /// # Blink /// /// fade from one color to an other then go back several times #[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 { type Strip = Strip; fn init(&mut self) -> Option { None } 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) } } } }