Skip to main content

Cell

Struct Cell 

Source
pub struct Cell {
    pub x: f32,
    pub y: f32,
    pub t: f32,
    pub mouse_x: f32,
    pub mouse_y: f32,
    pub mouse_down: bool,
    pub width: f32,
    pub height: f32,
}
Expand description

What a formula is told about the cell it is colouring.

x is the column. y is the row stretched by two, so one unit looks as tall as one unit of x is wide (terminal cells are about twice as tall as they are wide) and circles come out round. The mouse position and the window size use the same units.

When a sketch is drawn into part of the screen (see Screen::backdrop_in), x and y count from that part’s top left, and the window size and mouse position are measured from it too.

Fields§

§x: f32

Column of this cell.

§y: f32

Row of this cell, stretched so it matches x.

§t: f32

Seconds since the sketch started.

§mouse_x: f32

Column the mouse is over.

§mouse_y: f32

Row the mouse is over, stretched like y.

§mouse_down: bool

Whether the left mouse button is held.

§width: f32

Width of the window.

§height: f32

Height of the window, stretched like y.

Implementations§

Source§

impl Cell

Source

pub fn dist_to_mouse(&self) -> f32

Distance from this cell to the mouse.

Examples found in repository?
examples/plasma.rs (line 6)
3fn main() -> std::io::Result<()> {
4    // Move the mouse to send ripples across it. Press q to quit.
5    sketch_with(Palette::fire(), |cell| {
6        let ripple = cell.dist_to_mouse() * 0.25 - cell.t * 3.0;
7        ((cell.x * 0.15 + cell.t).sin() + (cell.y * 0.2 - cell.t * 0.7).sin() + ripple.sin()) / 3.0
8    })
9}
More examples
Hide additional examples
examples/rings.rs (line 6)
3fn main() -> std::io::Result<()> {
4    // Rainbow rings that follow the mouse. Hold the button to mix in waves.
5    sketch_with(Palette::rainbow(), |cell| {
6        let rings = (cell.dist_to_mouse() * 0.35 - cell.t * 2.0).sin();
7        let waves = (cell.x * 0.1 + cell.y * 0.1 + cell.t).sin();
8        if cell.mouse_down {
9            rings * waves
10        } else {
11            (rings + waves) / 2.0
12        }
13    })
14}
examples/waves.rs (line 9)
3fn main() -> std::io::Result<()> {
4    // An ocean. The mouse makes a glow, and the waves roll on.
5    sketch_with(Palette::ocean(), |cell| {
6        let swell =
7            (cell.x * 0.08 + cell.t).sin() * 0.5 + (cell.x * 0.19 - cell.t * 1.3).sin() * 0.25;
8        let surface = cell.height / 2.0 + swell * 6.0;
9        let glow = (-(cell.dist_to_mouse() * 0.12)).exp();
10        ((surface - cell.y) * 0.25 + glow * 0.5).clamp(-1.0, 1.0)
11    })
12}

Trait Implementations§

Source§

impl Clone for Cell

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 Cell

Source§

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

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

impl PartialEq for Cell

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cell

Auto Trait Implementations§

§

impl Freeze for Cell

§

impl RefUnwindSafe for Cell

§

impl Send for Cell

§

impl Sync for Cell

§

impl Unpin for Cell

§

impl UnsafeUnpin for Cell

§

impl UnwindSafe for Cell

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