bff03cba741ae0718c079b2eec230ffd1f2a047e
1 $(document
).ready(function(){
17 var canvas
= document
.getElementById('canvas')
18 var c
= canvas
.getContext('2d');
20 var cellWidth
= Math
.floor(canvas
.width
/ cells
);
21 var cellHeight
= Math
.floor(canvas
.height
/ generations
);
24 function cell(x
, y
, h
, l
) {
30 this.kill = function() {
31 c
.fillStyle
= "rgb(200,0,0)";
32 c
.fillRect(this.x
, this.y
, this.h
, this.l
);
35 this.revive = function() {
36 c
.fillStyle
= "rgb(0,0,0)";
37 c
.fillRect(this.x
, this.y
, this.h
, this.l
);
42 function populate_world() {
46 for (var i
= 0; i
< cells
; i
++) {
47 world
.push(new cell(x
, y
, cellWidth
, cellHeight
));
49 Math
.random() > .5 ? world
[i
].revive() : world
[i
].kill();
57 var y
= generation
* cellHeight
;
58 var s
= '0' + world
.map(function(c
) { return c
.state
}).join('') + '0';
60 for (var i
= 0; i
< cells
; i
++) {
61 world
.push(new cell(x
, y
, cellWidth
, cellHeight
));
63 state
[s
.substr(i
, 3)] == 1 ? world
[i
].revive() : world
[i
].kill();
65 //if (generation == generations) { clearInterval(tick_id) }
68 var world
= populate_world();
69 while (generations
) { generate(); generations
-- }
70 //var tick_id = setInterval(generate, 100);