1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! # Pattern Interface
//!
//! A pattern, most similar to [a WLED effect], generates colors for LEDs based on time and
//! position.
//!
//! A [`Pattern`] receives:
//!
//! - The layout of the LEDs (through its type parameters)
//! - Configuration parameters during initialization
//! - The current time during each update cycle
//!
//! And produces:
//!
//! - A sequence of colors for each LED in the layout
//!
//! For the library of built-in patterns, see [patterns](crate::patterns).
//!
//! [a WLED effect]: https://kno.wled.ge/features/effects/
use crateLayoutForDim;
/// Trait for creating visual effects on LED layouts.
///
/// Patterns generate colors for each LED in a layout based on time and position.
/// They are generic over both the dimension they operate in and the specific
/// layout type.
///
/// # Type Parameters
///
/// - `Dim` - The dimension marker (Dim1d, Dim2d, or Dim3d)
/// - `Layout` - The specific layout type
///
/// # Associated Types
///
/// - `Params` - Configuration parameters for the pattern
/// - `Color` - The color type produced by the pattern
///
/// # Example
///
/// ```rust
/// # use blinksy::{color::Okhsv, markers::Dim1d, layout::Layout1d, pattern::Pattern};
///
/// struct RainbowParams {
/// speed: f32,
/// scale: f32,
/// }
///
/// struct Rainbow {
/// params: RainbowParams
/// }
///
/// impl<Layout> Pattern<Dim1d, Layout> for Rainbow
/// where
/// Layout: Layout1d,
/// {
/// type Params = RainbowParams;
/// type Color = Okhsv;
///
/// fn new(params: Self::Params) -> Self {
/// Self { params }
/// }
///
/// fn tick(&self, time_in_ms: u64) -> impl Iterator<Item = Self::Color> {
/// let offset = (time_in_ms as f32 * self.params.speed);
/// let step = 0.5 * self.params.scale;
///
/// Layout::points().map(move |x| {
/// let hue = x * step + offset;
/// Okhsv::new(hue, 1.0, 1.0)
/// })
/// }
/// }
/// ```