Add alpha-only lerp iterator.
@@ -162,3 +162,52 @@ impl Iterator for RgbaLerp {
}
}
}
+
+/// Implements an Alpha-Only Lerp as an iterator
+pub struct AlphaLerp {
+ /// Starting color
+ start: RGBA,
+ /// Ending color
+ end: RGBA,
+ /// Number of lerp steps
+ n_steps: usize,
+ /// Current step (modified by the iterator)
+ step: usize,
+}
+
+impl AlphaLerp {
+ /// Creates a new RGB iterator
+ #[inline]
+ pub fn new<T>(start: RGBA, end: RGBA, steps: T) -> Self
+ where
+ T: TryInto<usize>,
+ {
+ Self {
+ start,
+ end,
+ n_steps: steps
+ .try_into()
+ .ok()
+ .expect("Not a usize-convertible integer"),
+ step: 0,
+ }
+ }
+}
+
+impl Iterator for AlphaLerp {
+ type Item = RGBA;
+
+ /// Returns the next step in the iterator
+ #[inline]
+ #[allow(clippy::cast_precision_loss)]
+ fn next(&mut self) -> Option<RGBA> {
+ if self.step > self.n_steps {
+ None
+ } else {
+ let percent = self.step as f32 / self.n_steps as f32;
+ self.step += 1;
+
+ Some(self.start.lerp_alpha(self.end, percent))
+ }
+ }
+}
\ No newline at end of file
