commit 482b666855ed7df2443d1b40c4bb98a429f8d05d
parent 6367428203c65d252fd152862171808e5dd1875b
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date: Mon, 19 Apr 2021 23:25:59 -0700
Cell state.
Diffstat:
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/conway.js b/conway.js
@@ -7,6 +7,33 @@ let fps, fpsInterval, startTime, now, then, elapsed;
let canvas;
let context;
+// Rows and columns of the board.
+let rows = 50;
+let cols = 50;
+
+// Divisor for likelyhood the cell starts out as alive.
+// For example: 4 means 1/4 chance.
+let chance = 4;
+
+// Enum of alive and dead states.
+const lifeState = Object.freeze({"alive":1, "dead":2});
+
+
+// 2D array of cells.
+// TODO presets like Gaspar gun
+let cells = (_ => {
+ let retVal = [[]];
+ for(let i = 0; i < rows; i++) {
+ retVal[i] = [];
+ for(let j = 0; j < cols; j++) {
+ retVal[i][j] = ((Math.floor((Math.random() * chance) + 1) == 1) ? lifeState.alive : lifeState.dead);
+ }
+ }
+
+ return retVal;
+})();
+
+
function init() {
let newCanvas = document.createElement('canvas');
newCanvas.setAttribute("id", 'bkg-canvas');