This is a basic implementation of Conway's Game of Life that is a representation of cell automation.
(function(window, document) {
var canvas = document.body.children[0], context = canvas.getContext('2d'), map = [], size = 1e4, i = size, scale = 4, hundred = 1e2, side = canvas.height = canvas.width = scale * hundred, x, j, next;
while (i--) { map.push(Math.random() > .8 ? 1 : 0); }
function check(cell) {
return map[cell] | 0;
}
setInterval(function() {
next = map.slice(), i = j = size;
while (i--) {
next[x = check(i -101) + check(i -hundred) + check(i -99) + check(i -1) + check(i +1) + check(i +99) + check(i +hundred) + check(i +101),i] = x == 3 || (map[i] & 1 && x == 2) ? 1 : 0;
}
map = next;
context.clearRect(0, 0, side, side);
while (j--) {
map[j] & 1 && context.fillRect(j / hundred *scale, (j % hundred) *scale, scale, scale);
}
}, 1e3);
})(this, document);
KGZ1bmN0aW9uKHdpbmRvdywgZG9jdW1lbnQpIHsNCgl2YXIgY2FudmFzID0gZG9jdW1lbnQuYm9keS5jaGlsZHJlblswXSwgY29udGV4dCA9IGNhbnZhcy5nZXRDb250ZXh0KCcyZCcpLCBtYXAgPSBbXSwgc2l6ZSA9IDFlNCwgaSA9IHNpemUsIHNjYWxlID0gNCwgaHVuZHJlZCA9IDFlMiwgc2lkZSA9IGNhbnZhcy5oZWlnaHQgPSBjYW52YXMud2lkdGggPSBzY2FsZSAqIGh1bmRyZWQsIHgsIGosIG5leHQ7DQoJDQoJd2hpbGUgKGktLSkgeyBtYXAucHVzaChNYXRoLnJhbmRvbSgpID4gLjggPyAxIDogMCk7IH0NCg0KCWZ1bmN0aW9uIGNoZWNrKGNlbGwpIHsNCgkJcmV0dXJuIG1hcFtjZWxsXSB8IDA7DQoJfQ0KCQ0KCXNldEludGVydmFsKGZ1bmN0aW9uKCkgew0KCQluZXh0ID0gbWFwLnNsaWNlKCksIGkgPSBqID0gc2l6ZTsNCgkJd2hpbGUgKGktLSkgew0KCQkJbmV4dFt4ID0gY2hlY2soaSAtMTAxKSArIGNoZWNrKGkgLWh1bmRyZWQpICsgY2hlY2soaSAtOTkpICs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