#[non_exhaustive]pub struct Grid<T> {
pub width: usize,
pub height: usize,
pub cells: Vec<T>,
pub dead_glyph: char,
pub alive_glyph: char,
pub population: usize,
}Expand description
Grid holds the state for a Conways game of life
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.width: usizeThe width of the grid to be created
height: usizeThe height of the grid to be created
cells: Vec<T>The state of the grid in terms of what cells are alive and dead in automaton
dead_glyph: charWhat character glyph should be used to display a dead population
alive_glyph: charWhat character glyph should be used to display an alive population
population: usizePopulation of the grid i.e number of alive cells
Implementations§
Source§impl Grid<CellState>
impl Grid<CellState>
Sourcepub fn new_empty(width: usize, height: usize) -> Self
pub fn new_empty(width: usize, height: usize) -> Self
Create a new Grid of a given width and height.
It will default to X for alive glyph and for dead glyph
use gridlife::Grid;
let grid = Grid::new_empty(3, 3);Sourcepub fn new_random(width: usize, height: usize) -> Self
pub fn new_random(width: usize, height: usize) -> Self
Generate a new Grid of a given width and height
It will be populated with a random distribution of Alive/Dead cells
The default glyphs of X for alive and for dead.
use gridlife::Grid;
let grid = Grid::new_random(3, 3);Sourcepub fn new_random_custom_glyphs(
width: usize,
height: usize,
alive_glyph: char,
dead_glyph: char,
) -> Self
pub fn new_random_custom_glyphs( width: usize, height: usize, alive_glyph: char, dead_glyph: char, ) -> Self
Generate a new Grid of a given width and height
It will be populated with a random distribution of Alive/Dead cells
The glyphs can be overriddne with alive_glyph and dead_glyph
use gridlife::Grid;
let grid = Grid::new_random_custom_glyphs(3, 3, '1', '0');Sourcepub fn update_states(&mut self) -> &[CellState]
pub fn update_states(&mut self) -> &[CellState]
Re-generates the state of the Grid cells based on the rules of Conways game of life