35 lines
1017 B
Rust
35 lines
1017 B
Rust
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<const N: usize> {
|
|
pub(crate) color: PixelColor,
|
|
pub(crate) stability: usize,
|
|
pub(crate) max_iteration: Option<usize>,
|
|
#[serde(default)]
|
|
pub(crate) current_iteration: usize,
|
|
}
|
|
|
|
impl<const N: usize> Pattern for FillUnstable<N> {
|
|
impl_pattern_none!(FadeRandom, N);
|
|
}
|
|
|
|
impl<const N: usize> Iterator for FillUnstable<N> {
|
|
type Item = Strip<N>;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
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::<N>::new(unstable_color))
|
|
}
|
|
}
|