UNPKG

game-of-life-d3-boots

Version:

conway's game of life with a small bit of interactivity. an observer can click on a square to "infect" it (turn its living color to red). then, whenever that cell is live, it will "infect" its living neighbors

30 lines (22 loc) 662 B
var d3 = require("d3"), Simulation = require("./simulation"), Game = require("./game"), Grid = require("./grid"), Vector = require("./vector"); var w = window.innerWidth, h = window.innerHeight; var gridWidth = 50, gridHeight = 50; global.svg = d3.select("body") .append("svg").attr({ width: w, height: h, }); map = new Array(gridHeight); for (var y = 0; y < gridHeight; y++) { map[y] = new Array(gridWidth); for (var x = 0; x < gridWidth; x++) { map[y][x] = !!Math.floor(Math.random()*2); } } global.sim = (new Simulation(svg, map, 1000)).run(250, 450);