use crate::patterns::{Pattern, PixelColor}; use crate::{impl_pattern_none, Strip}; use serde::{Deserialize, Serialize}; /// # FillUnstable /// /// fill strip with color then apply same random variation to all pixel #[derive(Serialize, Deserialize, Debug, Eq, Hash, PartialEq, Copy, Clone)] pub struct FillUnstable { pub(crate) color: PixelColor, pub(crate) stability: usize, pub(crate) max_iteration: Option, #[serde(default)] pub(crate) current_iteration: usize, } impl Pattern for FillUnstable { impl_pattern_none!(FadeRandom, N); } impl Iterator for FillUnstable { type Item = Strip; fn next(&mut self) -> Option { if self.is_last_iteration() { return None; } let mut rng = rand::thread_rng(); let unstable_color = self.color.random_delta(self.stability, &mut rng); self.current_iteration += 1; Some(Strip::::new(unstable_color)) } }