gol-lib

Crates.iogol-lib
lib.rsgol-lib
version0.1.3
sourcesrc
created_at2021-09-30 16:08:43.030849
updated_at2021-09-30 19:10:41.923581
descriptionA nice game of life package
homepage
repositoryhttps://github.com/Dalejosne/Automata/tree/main/game_of_life
max_upload_size
id458782
size8,256
(Dalejosne)

documentation

https://docs.rs/gol-lib/0.1.3

README

Game of life crate

This crate allow you tu create an play the famous "game of life" of John Conway.

Presentation

But what is the game of life ?
It is an automata invented by John Conway in the 70s.
It is composed of an infinite grid (in practice it is finite), of which cell can be in two state : dead or alive.
The neigbourhood of a cell is the 8 cells which around it (e.g bottom, top, left, right and diagonals).
If an alive cell has two or three neighboors who are alive, it becomes alive. Else, it dies.
If a dead cell has three neighboors who are alive, it becomes alive. Else, it stays dead.
So what you have to do is just create an automata, set some cells (to meke them alive) and to see how it evoluates !
For more information about conway game of life, have a look to this Have fun !

Quickstart

To install, see installation instructions.
Then, try this code :

use std::time::Duration;
use std::thread::sleep;
use gol_lib::*;

fn main(){
	let mut g = GameOfLife::new(45, 25);
	g.set_element(5, 5);
	g.set_element(6, 5);
	g.set_element(7, 5);
	g.set_element(6, 6);
	clear();
	reverse();
	loop {
		g.show();
		g.update();
		refresh();
		clear();
		sleep(Duration::from_millis(500));
	}
}

Install

To install it as a dependency, just add this line to your Cargo.toml :

[dependencies]
gol-lib = "0.1.0"

If you want to install it locally, do :

git clone https://github.com/Dalejosne/Automata

And every files you need will be on the subdirectory Automata/game_of_life.

Doc

After having installed it, do :

cargo doc

And then open the file index.html on the directory target/doc/game_of_life

Examples

See the "examples" repository. To run them, do :

cargo run --example basic
Commit count: 0

cargo fmt