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: f32Column of this cell.
y: f32Row of this cell, stretched so it matches x.
t: f32Seconds since the sketch started.
mouse_x: f32Column the mouse is over.
mouse_y: f32Row the mouse is over, stretched like y.
mouse_down: boolWhether the left mouse button is held.
width: f32Width of the window.
height: f32Height of the window, stretched like y.
Implementations§
Source§impl Cell
impl Cell
Sourcepub fn dist_to_mouse(&self) -> f32
pub fn dist_to_mouse(&self) -> f32
Distance from this cell to the mouse.
Examples found in repository?
More examples
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}