1 $(document
).ready(function(){
17 var canvas
= $('#1d-automaton')[0];
18 var c
= canvas
.getContext('2d');
20 var cellWidth
= canvas
.width
/ cells
;
21 var cellHeight
= 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() {
48 for (var i
= 0; i
< cells
; i
++) {
49 world
.push(new cell(x
, y
, cellWidth
, cellHeight
));
51 Math
.random() > .5 ? world
[i
].revive() : world
[i
].kill();
59 var y
= generation
* cellHeight
;
60 var s
= '0' + world
.map(function(c
) { return c
.state
}).join('') + '0';
62 for (var i
= 0; i
< cells
; i
++) {
63 world
.push(new cell(x
, y
, cellWidth
, cellHeight
));
65 state
[s
.substr(i
, 3)] == 1 ? world
[i
].revive() : world
[i
].kill();
67 //if (generation == generations) { clearInterval(tick_id) }
70 var world
= populate_world();
71 while (generations
- generation
) { generate();}
72 //var tick_id = setInterval(generate, 100);
74 $('#controls #regenerate-automaton').click(function(e
){
75 c
.clearRect(0,0,canvas
.width
,canvas
.height
);
76 world
= populate_world();
77 while (generations
- generation
) { generate(); }