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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
//! Various Functions and traits for colors.
//!
//! The majority of these traits are not intended to be implemented by users. Rather, they are
//! meant for allowing easy ways to fill iterators with color.
//!
//! ## Importing
//!
//! Importing is done with the following:
//!
//! ```
//! use cichlid::prelude::*;
//! ```
//!
//! It is preferable to import that traits anonymously with `use ... as _`. This is because
//! these traits are not meant to be implemented directly, so only the types implementing
//! the traits need to be imported.
//!
//! ## Traits
//!
//! - [`ColorIterMut`]:
//! - General functions applying on iterators over [`ColorRGB`]'s.
//! - Examples of functions: `fill()`, `clear()`.
//! - Implemented for all Iterators over `&mut ColorRGB`.
//! - [`ColorSliceMut`]:
//! - Special optimized functions implemented for slices / arrays of [`ColorRGB`]'s.
//! - Examples of functions: `blur()`, `fade_to_black()`, `blend()`.
//! - [`GradientFill`]:
//! - Fills a Gradient from one [`HSV`] to another using Linear Interpolation.
//! - Implemented for any iterators implementing `ExactSizeIter`.
//! - Also Generic over `Iterator::Item` for any item implementing `From<HSV>`, meaning
//! this method works on itorators over both `HSV` and `ColorRGB`.
//! - [`GradientFillToInclusive`]:
//! - Same as `GradientFill`, but creates a gradient inclusive of the last `HSV`. This means
//! that the last item iterated over will be garunteed to be the last `HSV`, rather than
//! being the color before.
//! - Generally Requires a `DoubleEndedIter` trait be implemented for implementee's type.
//! - [`GradientFillRGB`]:
//! - Works the same as`GradientFill`, but does a linear interpolation between two `ColorRGBs`.
//! - This results in a gradient that is a mathematically consistent transition, but isn't
//! as visually pleasing compared to doing Linear Interpolation with `HSV`s.
//! - [`GradientFillRGBToInclusive`]:
//! - The `GradientFillToInclusive` to `GradientFillRGB`, as it fills up to and including the
//! last color.
//! - Also requires that the Iterator implements `DoubleEndedIter`.
//! - [`RainbowFill`]:
//! - Fills an Iterator over `&mut From<HSV>` with a rainbow pattern. This pattern repeats
//! forever, starting at a specific hue and taking a user-defined step size for each new
//! element.
//! - [`RainbowFillSingleCycle`]:
//! - Fills an Iterator with a full rainbow cycle.
//!
//! [`ColorIterMut`]: ./trait.ColorIterMut.html
//! [`ColorSliceMut`]: ./trait.ColorSliceMut.html
//! [`GradientFill`]: ./trait.GradientFill.html
//! [`GradientFillToInclusive`]: ./trait.GradientFillToInclusive.html
//! [`GradientFillRGB`]: ./trait.GradientFill.html
//! [`GradientFillRGBToInclusive`]: ./trait.GradientFillRGBToInclusive.html
//! [`RainbowFill`]: ./trait.RainbowFill.html
//! [`RainbowFillSingleCycle`]: ./trait.RainbowFillSingleCycle.html
//! [`ColorRGB`]: ../struct.ColorRGB.html
//! [`HSV`]: ../struct.HSV.html
use crate::;
/// Useful methods when iterating over `ColorRGB`s.
///
/// This is `impl`'d for any Iterator over `&mut RGB`. This includes both arrays and slices, the
/// most common use case for this.
///
/// # Examples
///
/// Operating Directly on an array of `ColorRGB`s:
///
/// ```
/// use cichlid::{prelude::*, ColorRGB};
///
/// let mut colors = [ColorRGB::BlanchedAlmond; 100];
///
/// colors.fill(ColorRGB::Yellow);
/// colors.iter().for_each(|c| assert_eq!(*c, ColorRGB::Yellow));
/// ```
///
/// Operating on slices is supported as well:
///
/// ```
/// use cichlid::{prelude::*, ColorRGB};
///
/// let mut colors = [ColorRGB::Purple; 50];
/// let color_slice = &mut colors[0..40];
///
/// color_slice.clear();
/// color_slice.iter().for_each(|c| assert_eq!(*c, ColorRGB::Black));
/// ```
/// Optimized methods for iterating over arrays and slices of `ColorRGB`s.
///
/// # Usage
///
/// Normally, to scale an array by a fixed amount, something like is done:
///
/// ```
/// use cichlid::ColorRGB;
/// let mut colors = [ColorRGB::Pink; 50];
/// colors.iter_mut().for_each(|c| c.fade_to_black_by(200));
/// ```
///
///
/// But, when operating on arrays, it's often faster to operate on multiple values at once
/// using custom SIMD functions. `ColorSliceMut::fade_to_black()` implements this internally,
/// resulting in dimming that is twice as fast as the above method.
///
/// ```
/// use cichlid::{prelude::*, ColorRGB};
/// let mut colors = [ColorRGB::Pink; 50];
/// colors.fade_to_black(200); // Much faster!
/// ```
///
/// # Examples
///
/// ```
/// use cichlid::{prelude::*, ColorRGB};
///
/// let mut colors = [ColorRGB::Purple; 50];
/// colors.fade_to_black(50);
///
/// let color_slice = &mut colors[0..40];
/// color_slice.blur(50);
/// color_slice.blend(ColorRGB::Gold, 120);
/// ```
/// Fills an iterable object with a gradient from the `HSV` values `start` to `finish`, exclusive of the
/// `finish`.
///
/// # Examples
///
/// ```
/// use cichlid::{prelude::*, ColorRGB, HSV, GradientDirection};
///
/// let mut colors = [ColorRGB::Black; 24];
/// let start = HSV::new(0, 255, 255);
/// let end = HSV::new(100, 255, 180);
/// colors.gradient_fill(start, end, GradientDirection::Longest);
/// ```
///
/// Also usable over Iterators for `HSV`:
///
/// ```
/// use cichlid::{prelude::*, HSV, GradientDirection};
///
/// let mut colors = [HSV::BLANK; 80];
/// let start = HSV::new(0, 255, 255);
/// let end = HSV::new(100, 255, 180);
/// colors.gradient_fill(start, end, GradientDirection::Longest);
/// ```
/// Fills an iterable object with a gradient from the `HSV` values `start` to `finish`, inclusive of the
/// `finish`.
///
/// # Examples
///
/// ```
/// use cichlid::{prelude::*, ColorRGB, HSV, GradientDirection};
///
/// let mut colors = [ColorRGB::Black; 80];
/// let start = HSV::new(130, 200, 251);
/// let end = HSV::new(206, 100, 255);
///
/// colors.gradient_fill_to_inclusive(start, end, GradientDirection::Shortest);
/// assert_eq!(*colors.last().unwrap(), ColorRGB::from(end));
/// ```
/// Fills an iterable object with a gradient from the `ColorRGB` values `start` to `finish`, exclusive of the
/// `finish`.
/// Fills an iterable object with a gradient from the `ColorRGB` values `start` to `finish`, inclusive of the
/// `finish`.
/// Fills an iterable object with a rainbow hue of a desired step size.
///
/// Step sizes is a `u16`. The Most significant byte of each integer is used to represent the
/// full number of hues to increment between each iterated value, while the second (LSB)
/// byte is added as a fractional component.
///
/// For example, if one desires to change a single hue between each element, the `hue_delta`
/// should be set to `0x0100`. If a hue is desired to change every 256 elements, then the
/// `hue_delta` should be `0x0001`.
/// Fills an iterable object with a single complete rainbow.
///
/// If the the rainbow is needed backwards, try calling `iter.rev()` before calling this
/// method.
/// Possible Directions around the color wheel a hue can go.
/// Possible Directions around the color wheel a gradient can go.