Skip to content

yoannchb-pro/game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game-of-life

Game of life algo

Note: See example here

Import

<script src="https://cdn.jsdelivr.net/gh/yoannchb-pro/game-of-life/index.min.js"></script>

How to use

There are two arguments nbCelssWidth and nbCellsHeight (by default 50 and 50) for the number of cells you want on the width and on the height

const handler = new GameOfLife(3, 3);
console.log(handler.game);
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]

Random generation

There is one argument factor (by default 0.2) between 0 and 1 that determine the probability of a cell to be alive

handler.randomGeneration();
//[[0, 0, 1], [1, 0, 1], [1, 0, 0]]

Evoluate

Evoluate the environment

//[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
handler.evoluate();
//[[0, 0, 0], [1, 1, 1], [0, 0, 0]]

Hydratate

There are two arguments line and column

handler.hydratate(1, 2);
//[[0, 0, 0], [0, 0, 1], [0, 0, 0]]

Deshydratate

There are two arguments line and column

//[[0, 0, 0], [0, 0, 1], [0, 0, 0]]
handler.deshydratate(1, 2);
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]

Clear

Clear the whole environment

//[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
handler.clear();
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]