Skip to main content

PixelAnimation

Enum PixelAnimation 

Source
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.

Fields

§speed: f32
§

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).

Fields

§base_color: Rgb
§

Pulse

The whole grid breathes between dim and full brightness together (every cell shares one global brightness curve).

Fields

§base_color: Rgb

Alternates every other frame between two flat colors.

Fields

§on_color: Rgb
§off_color: Rgb
§

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.

Fields

§scale: f32
§speed: f32
§

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.

Fields

§base_color: Rgb
§speed: f32
§

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.

Fields

§from: Rgb
§to: Rgb
§horizontal: bool
§

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.

Fields

§transform: ColorTransform
§

Custom(ColorFn)

A user-supplied ColorFn — see PixelAnimation::custom.

Implementations§

Source§

impl PixelAnimation

Source

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§

Source§

impl Clone for PixelAnimation

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.