script.js
changeset 83 228adcfd8f23
parent 82 cb8897d7f508
child 84 b7834ce141c4
     1.1 --- a/script.js	Thu Jan 05 23:29:27 2012 +0100
     1.2 +++ b/script.js	Fri Jan 06 00:02:26 2012 +0100
     1.3 @@ -299,7 +299,7 @@
     1.4  function init_gameoflife() {
     1.5      var canvas = document.getElementById("gameoflife");
     1.6      if (canvas) {
     1.7 -        gameoflife = new Simulation(canvas, 670, 670, 8,
     1.8 +        gameoflife = new Simulation(canvas, 670, 670, 16,
     1.9                                      green, black);
    1.10          $("#gameoflife").mousemove(function(event) { 
    1.11              gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); 
    1.12 @@ -615,9 +615,7 @@
    1.13          if (this.y + 1 < this.grid.height) {
    1.14              this._neighbours.push(this.grid.cell(this.x-1, this.y+1));
    1.15          }
    1.16 -    } else {
    1.17 -        this._neighbours.push(this.grid.cell(this.grid.width-1, this.y));
    1.18 -    }
    1.19 +    }   
    1.20      if (this.x + 1 < this.grid.width) {
    1.21          this._neighbours.push(this.grid.cell(this.x+1, this.y));
    1.22          if (this.y + 1 < this.grid.height) {
    1.23 @@ -627,8 +625,6 @@
    1.24          if (this.y > 0) {
    1.25              this._neighbours.push(this.grid.cell(this.x+1, this.y-1));
    1.26          }
    1.27 -    } else {
    1.28 -        this._neighbours.push(this.grid.cell(0, this.y));
    1.29      }
    1.30      return this._neighbours;
    1.31  }
    1.32 @@ -661,7 +657,8 @@
    1.33  Simulation.prototype.draw = function() {
    1.34      var now = $.now();
    1.35      if (this.redraw.length) {
    1.36 -        var cell = this.redraw.pop();
    1.37 +        var cell = this.redraw[0];
    1.38 +        this.redraw.shift();
    1.39          this.context.fillStyle = cell.value == 1 ? 
    1.40              this.life_colour.str() : this.dead_colour.str();
    1.41          this.context.fillRect(cell.canvas_x, cell.canvas_y, 
    1.42 @@ -672,14 +669,14 @@
    1.43  Simulation.prototype.update = function() {
    1.44      var now = $.now();
    1.45      if (this.pos_queue.length) {
    1.46 -        var pos = this.pos_queue.pop();
    1.47 +        var pos = this.pos_queue.pop();       
    1.48          if (pos[0] < this.canvas.width
    1.49              && pos[1] < this.canvas.height) {
    1.50              var cell = this.grid.pick_cell(pos[0], pos[1]);
    1.51              cell.set_value(1);
    1.52              this.cell_queue.push(cell);
    1.53              this.cell_queue.concat(cell.neighbours()); 
    1.54 -            this.redraw.push(cell);          
    1.55 +            this.redraw.unshift(cell);          
    1.56          }
    1.57      }
    1.58      if (this.last_update + 1000 > now) {
    1.59 @@ -688,7 +685,7 @@
    1.60      var changed = new Array();
    1.61      var next_cell_queue = new Array();
    1.62      while (this.cell_queue.length) {
    1.63 -        var cell = this.cell_queue.pop();
    1.64 +        var cell = this.cell_queue.pop();       
    1.65          if (changed[cell.hash()]) {           
    1.66              continue;
    1.67          }
    1.68 @@ -708,7 +705,7 @@
    1.69          cell.set_value(1 - cell.value);
    1.70          this.redraw.push(cell);
    1.71      }
    1.72 -    this.cell_queue = this.cell_queue.concat(next_cell_queue);
    1.73 +    this.cell_queue = next_cell_queue;
    1.74      this.last_update = now;  
    1.75  }
    1.76  Simulation.prototype.mouse_moved = function(pos) {