use crate::patterns::fade::Fade; use crate::patterns::Pattern; use crate::Strip; use serde::{Deserialize, Serialize}; /// # Blink /// /// fade from one color to an other then go back several times #[derive(Serialize, Deserialize, Debug, Eq, Hash, PartialEq, Copy, Clone)] pub struct FadeUnstable { #[serde(default)] pub(crate) current_iteration: usize, pub(crate) max_iteration: Option, pub(crate) stability: usize, fade: Fade, } impl Pattern for FadeUnstable { 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 FadeUnstable { type Item = Strip; fn next(&mut self) -> Option { let strip = self.fade.next(); match strip { None => None, Some(fade) => { let mut rng = rand::thread_rng(); let pixel = fade[0].unwrap().random_delta(self.stability, &mut rng); Some(Strip::new(pixel)) } } } }