pub struct Grid<T> {
pub width: usize,
pub height: usize,
pub cells: Vec<T>,
pub dead_glyph: char,
pub alive_glyph: char,
}Expand description
Grid holds the state for a Conways game of life
Fields§
§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
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
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.
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
Sourcepub fn update_states(&mut self) -> u32
pub fn update_states(&mut self) -> u32
Re-generates the state of the Grid cells based on the rules of Conways game of life