Skip to main content

Pixels

Struct Pixels 

Source
pub struct Pixels { /* private fields */ }
Expand description

A half-block pixel buffer: w × 2·h square pixels over a w × h cell region (CORE-R42). Ink::BLANK (any Role::Background ink) is an empty pixel.

Implementations§

Source§

impl Pixels

Source

pub fn new(cells: Size) -> Self

An empty buffer over cells terminal cells.

Source

pub fn pixel_size(&self) -> Size

Buffer dimensions in pixels, w × 2·h (saturated at u16::MAX).

Source

pub fn resize(&mut self, cells: Size)

Resize to cells and clear. Reuses the buffer unless it must grow.

Source

pub fn fill(&mut self, ink: Ink)

Set every pixel to ink.

Source

pub fn clear(&mut self)

Empty every pixel.

Source

pub fn set(&mut self, x: i32, y: i32, ink: Ink)

Set pixel (x, y); off-buffer pixels are ignored.

Source

pub fn get(&self, x: i32, y: i32) -> Option<Ink>

Pixel (x, y), or None off the buffer.

Source

pub fn cell_bg(&self, x: i32, y: i32) -> Ink

The one ink that stands for cell (x, y)’s two pixels (CORE-R84): the stronger of the two, or Ink::BLANK when both are empty or the cell is off the buffer. Dots::blit_over puts it behind a cell’s dots.

Source

pub fn backdrop(&self, canvas: &mut Canvas)

Give every glyph already drawn over this buffer’s pixels its cell’s cell_bg as background (CORE-R86), so line art, sprites and labels drawn after blit do not punch black boxes into a half-block picture. Glyphs and inks are kept; cells that already have a background, half and full blocks, and cells over empty pixels are left alone. Unicode only: an ASCII canvas has no half blocks to match.

Source

pub fn shade(&mut self, shader: impl FnMut(i32, i32) -> Ink)

Set every pixel to shader(x, y), row by row (CORE-R65): the Pixels analogue of draw::field, for sampling a simulation lattice (e.g. through a SampleMap) onto the display pixels.

Source

pub fn dissolve(&mut self, floor: u8)

Fade a glow’s faint fringe smoothly into the empty sky (CORE-R89, M14), so it ends in the terminal’s black instead of a ramp’s tinted floor, with no dither. A pixel of intensity i (as for stronger) below floor is emptied when i < floor / 2, and in the band [floor / 2, floor) its intensity becomes i·smoothstep((i − floor/2)/(floor/2)) (a Div pixel keeps its sign about 128), emptied if that rounds to 0. The fade is a pure function of the pixel’s own intensity, continuous and non-decreasing in it, so a uniform field stays uniform: no ordered or noise pattern. Pixels at or above floor, and Phase pixels (no intensity), are untouched; floor = 0 changes nothing. Allocation-free.

Source

pub fn blit<F>(&self, canvas: &mut Canvas, ascii: F)
where F: FnMut(i32, i32, Ink, Ink) -> Option<(char, Ink)>,

Draw the buffer onto canvas, one cell per vertical pixel pair.

Unicode mode: both pixels empty ⇒ cell untouched; top only ⇒ ▀ in the top ink; bottom only ⇒ ▄ in the bottom ink; both ⇒ ▀ with the top as foreground and the bottom as background. ASCII mode has no half blocks, so every cell goes through the scene’s own ascii(x, y, top, bottom) fallback, whose Some((ch, ink)) is written and None leaves the cell untouched (GEN-R10, ADR-0010).

Trait Implementations§

Source§

impl Clone for Pixels

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

impl Debug for Pixels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pixels

Source§

fn default() -> Self

A 1×1-cell buffer, the placeholder until a scene’s first resize.

Auto Trait Implementations§

§

impl Forget for Pixels

§

impl Freeze for Pixels

§

impl Move for Pixels

§

impl RefUnwindSafe for Pixels

§

impl Send for Pixels

§

impl Sync for Pixels

§

impl Unpin for Pixels

§

impl UnsafeUnpin for Pixels

§

impl UnwindSafe for Pixels

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V