[][src]Struct smeagol::Life

pub struct Life { /* fields omitted */ }

Conway's Game of Life.

Methods

impl Life[src]

pub fn save_png<P>(
    &mut self,
    path: P,
    bounding_box: BoundingBox,
    zoom: u8
) -> Result<()> where
    P: AsRef<Path>, 
[src]

Renders the Life grid as a png image.

impl Life[src]

pub fn new() -> Self[src]

Creates a new empty Life grid.

Examples

let mut life = smeagol::Life::new();
assert_eq!(life.population(), 0);

pub fn from_rle_file<P>(path: P) -> Result<Self, Error> where
    P: AsRef<Path>, 
[src]

Creates a Life grid from the given RLE file.

Examples

let mut life = smeagol::Life::from_rle_file("./assets/glider.rle").unwrap();
assert_eq!(life.population(), 5);

pub fn from_rle_file_contents(contents: &[u8]) -> Result<Self, Error>[src]

pub fn from_rle_pattern(pattern: &[u8]) -> Result<Self, Error>[src]

Creates a Life grid from the given RLE pattern.

Examples

// integral sign
let mut life = smeagol::Life::from_rle_pattern(b"3b2o$2bobo$2bo2b$obo2b$2o!").unwrap();
assert_eq!(life.population(), 9);

pub fn from_rle(rle: &Rle) -> Self[src]

Creates a Life grid from the given RLE struct.

pub fn set_cell_alive(&mut self, position: Position)[src]

Sets the cell at the given position in the Life grid to be an alive cell.

Examples

let mut life = smeagol::Life::new();

// create a block
life.set_cell_alive(smeagol::Position::new(0, 0));
life.set_cell_alive(smeagol::Position::new(1, 0));
life.set_cell_alive(smeagol::Position::new(0, 1));
life.set_cell_alive(smeagol::Position::new(1, 1));

assert_eq!(life.population(), 4);

pub fn get_alive_cells(&self) -> Vec<Position>[src]

Returns a list of the positions of the alive cells in the Life grid.

// glider
let life = smeagol::Life::from_rle_pattern(b"bob$2bo$3o!")?;

for pos in life.get_alive_cells() {
    // do something
}

pub fn contains_alive_cells(&self, bounding_box: BoundingBox) -> bool[src]

Returns true if the given bounding box contains any alive cells.

Examples

// glider
let life = smeagol::Life::from_rle_pattern(b"bob$2bo$3o!")?;

assert!(life.contains_alive_cells(life.bounding_box().unwrap()));

pub fn bounding_box(&self) -> Option<BoundingBox>[src]

Returns a bounding box containing all the alive cells in the Life grid.

Returns None if there are no alive cells in the grid.

Examples

let mut life = smeagol::Life::new();
assert!(life.bounding_box().is_none());

life.set_cell_alive(smeagol::Position::new(0, 0));
assert!(life.bounding_box().is_some());

pub fn generation(&self) -> u128[src]

Returns the number of generations that have been advanced in the Life grid.

Examples

let mut life = smeagol::Life::from_rle_pattern(b"bob$2bo$3o!")?;
assert_eq!(life.generation(), 0);

life.step();
assert_eq!(life.generation(), 1);

pub fn population(&self) -> u128[src]

Returns the number of alive cells in the grid.

Examples

let mut life = smeagol::Life::from_rle_pattern(b"bob$2bo$3o!")?;
assert_eq!(life.population(), 5);

pub fn step_size(&self) -> u64[src]

Returns the current step size.

The default step size is 1.

pub fn step_log_2(&self) -> u8[src]

Returns the step size log 2.

pub fn set_step_log_2(&mut self, step_log_2: u8)[src]

Sets the step size to be 2^step_log_2.

This clears the cache of previously computed steps.

pub fn step(&mut self)[src]

Advances the Life grid into the future.

The number of generations advanced is determined by the step size.

Examples

let mut life = smeagol::Life::from_rle_pattern(b"bob$2bo$3o!")?;

// step size of 32
life.set_step_log_2(5);

life.step();
assert_eq!(life.generation(), 32);

Trait Implementations

impl Default for Life[src]

impl Clone for Life[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Life[src]

Auto Trait Implementations

impl Send for Life

impl Sync for Life

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> FromCast for T[src]

impl<T, U> Cast for T where
    U: FromCast<T>, 
[src]