diff -r cb8897d7f508 -r 228adcfd8f23 script.js --- a/script.js Thu Jan 05 23:29:27 2012 +0100 +++ b/script.js Fri Jan 06 00:02:26 2012 +0100 @@ -299,7 +299,7 @@ function init_gameoflife() { var canvas = document.getElementById("gameoflife"); if (canvas) { - gameoflife = new Simulation(canvas, 670, 670, 8, + gameoflife = new Simulation(canvas, 670, 670, 16, green, black); $("#gameoflife").mousemove(function(event) { gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); @@ -615,9 +615,7 @@ if (this.y + 1 < this.grid.height) { this._neighbours.push(this.grid.cell(this.x-1, this.y+1)); } - } else { - this._neighbours.push(this.grid.cell(this.grid.width-1, this.y)); - } + } if (this.x + 1 < this.grid.width) { this._neighbours.push(this.grid.cell(this.x+1, this.y)); if (this.y + 1 < this.grid.height) { @@ -627,8 +625,6 @@ if (this.y > 0) { this._neighbours.push(this.grid.cell(this.x+1, this.y-1)); } - } else { - this._neighbours.push(this.grid.cell(0, this.y)); } return this._neighbours; } @@ -661,7 +657,8 @@ Simulation.prototype.draw = function() { var now = $.now(); if (this.redraw.length) { - var cell = this.redraw.pop(); + var cell = this.redraw[0]; + this.redraw.shift(); this.context.fillStyle = cell.value == 1 ? this.life_colour.str() : this.dead_colour.str(); this.context.fillRect(cell.canvas_x, cell.canvas_y, @@ -672,14 +669,14 @@ Simulation.prototype.update = function() { var now = $.now(); if (this.pos_queue.length) { - var pos = this.pos_queue.pop(); + var pos = this.pos_queue.pop(); if (pos[0] < this.canvas.width && pos[1] < this.canvas.height) { var cell = this.grid.pick_cell(pos[0], pos[1]); cell.set_value(1); this.cell_queue.push(cell); this.cell_queue.concat(cell.neighbours()); - this.redraw.push(cell); + this.redraw.unshift(cell); } } if (this.last_update + 1000 > now) { @@ -688,7 +685,7 @@ var changed = new Array(); var next_cell_queue = new Array(); while (this.cell_queue.length) { - var cell = this.cell_queue.pop(); + var cell = this.cell_queue.pop(); if (changed[cell.hash()]) { continue; } @@ -708,7 +705,7 @@ cell.set_value(1 - cell.value); this.redraw.push(cell); } - this.cell_queue = this.cell_queue.concat(next_cell_queue); + this.cell_queue = next_cell_queue; this.last_update = now; } Simulation.prototype.mouse_moved = function(pos) {