pub enum PixelAnimation {
Rainbow {
speed: f32,
},
Wave {
base_color: Rgb,
},
Pulse {
base_color: Rgb,
},
Blink {
on_color: Rgb,
off_color: Rgb,
},
Plasma {
scale: f32,
speed: f32,
},
Ripple {
base_color: Rgb,
speed: f32,
},
Gradient {
from: Rgb,
to: Rgb,
horizontal: bool,
},
Transformed {
base: Box<PixelAnimation>,
transform: ColorTransform,
},
Custom(ColorFn),
}Expand description
A per-cell color animation applied over an existing block of plain
(uncolored) ASCII text. See the module docs for how this differs from
crate::text::TextAnimation/crate::banner’s per-character
coloring.
Variants§
Rainbow
A hue sweep across both axes: hue depends on frame plus a
per-cell offset along x and y, so the rainbow band visibly
moves across the art over time instead of every cell cycling in
lockstep. speed is degrees of hue shift per frame.
Wave
A brightness band sweeps left-to-right across the art against
base_color — the same math as
crate::text::TextAnimation::Wave, extended from one line to a
whole grid (every row sees the same horizontal sweep).
Pulse
The whole grid breathes between dim and full brightness together (every cell shares one global brightness curve).
Blink
Alternates every other frame between two flat colors.
Plasma
Classic demoscene “plasma”: a sum of sine waves over x, y, and
time, mapped onto hue. Purely mathematical, needs no base color.
scale sets the spatial frequency (smaller = larger color blobs);
speed sets how fast it animates.
Ripple
Concentric rings of brightness expanding outward from the grid’s
center against base_color; another purely math-driven built-in,
provided as a second worked example alongside [Plasma]. speed
controls how fast the rings travel outward.
Gradient
A static (time-independent) linear gradient between from and
to, sweeping left-to-right if horizontal is true or
top-to-bottom otherwise. Unlike the other built-ins this ignores
frame entirely — it’s the simplest possible
Rgb::mix-based effect, provided as a ready-made built-in for
the common “just tint this art between two brand colors” case
instead of requiring a PixelAnimation::custom closure for it.
Transformed
Wraps base and applies transform (see
crate::color::ColorTransform) to whatever color base would
have produced for that cell — so, for example,
Transformed { base: Box::new(Rainbow { speed: 6.0 }), transform: ColorTransform::Saturate(0.4) }
is a desaturated rainbow sweep, without needing a bespoke
“desaturated rainbow” variant. Composes with any other
PixelAnimation, including another Transformed.
Custom(ColorFn)
A user-supplied ColorFn — see PixelAnimation::custom.
Implementations§
Source§impl PixelAnimation
impl PixelAnimation
Sourcepub fn custom(
f: impl Fn(usize, usize, u64, char) -> Rgb + Send + Sync + 'static,
) -> Self
pub fn custom( f: impl Fn(usize, usize, u64, char) -> Rgb + Send + Sync + 'static, ) -> Self
Wraps a closure as PixelAnimation::Custom. The closure receives
(x, y, frame_index, ch) for every non-space cell and returns that
cell’s color; use ordinary floating-point math over x/y/frame
for anything from a simple linear gradient to arbitrary generative
patterns.
use eger::colorize::PixelAnimation;
use eger::Rgb;
// A diagonal gradient from red (top-left) to blue (bottom-right),
// static in time (ignores `frame`).
let gradient = PixelAnimation::custom(|x, y, _frame, _ch| {
let t = ((x + y) as f32 / 40.0).clamp(0.0, 1.0);
Rgb::new((255.0 * (1.0 - t)) as u8, 0, (255.0 * t) as u8)
});Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PixelAnimation
impl !UnwindSafe for PixelAnimation
impl Freeze for PixelAnimation
impl Send for PixelAnimation
impl Sync for PixelAnimation
impl Unpin for PixelAnimation
impl UnsafeUnpin for PixelAnimation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more