factory/v2012/script.js
changeset 81 a76b2fb0f21f
parent 80 ba69edadfc4c
child 82 cb8897d7f508
     1.1 --- a/factory/v2012/script.js	Thu Jan 05 17:03:06 2012 +0100
     1.2 +++ b/factory/v2012/script.js	Thu Jan 05 23:04:57 2012 +0100
     1.3 @@ -4,7 +4,7 @@
     1.4  var gameoflife;
     1.5  
     1.6  $(document).ready(function() {   
     1.7 -    simulation = new Simulation(document.getElementById("sim"), 670, 50);  
     1.8 +    simulation = new Simulation(document.getElementById("sim"), 670, 50, 4);  
     1.9      var image = new Image();
    1.10      image.onload = init_logo;
    1.11      image.src = "images/logobase.png";
    1.12 @@ -32,7 +32,14 @@
    1.13          }
    1.14      }    
    1.15      window.onEachFrame = onEachFrame;   
    1.16 -    window.onEachFrame(update);    
    1.17 +    window.onEachFrame(update);  
    1.18 +    var pos = document.location.href.lastIndexOf("/") + 1; 
    1.19 +    var page = document.location.href.substr(pos);
    1.20 +    if (page == "experiments.html") {
    1.21 +        draw(0, 0, 0, 0, 0);
    1.22 +    } else if (page == "gameoflife.html") {
    1.23 +        init_gameoflife();
    1.24 +    }
    1.25  });
    1.26  
    1.27  $(document).keypress(function(event) {
    1.28 @@ -277,13 +284,12 @@
    1.29  }
    1.30  
    1.31  function init_gameoflife() {
    1.32 -    var canvas = document.getElementById("gameoflife"); alert("h");
    1.33 -    if (cavans) {
    1.34 -        gameoflife = new Simulation(canvas, 670, 670);
    1.35 +    var canvas = document.getElementById("gameoflife");
    1.36 +    if (canvas) {
    1.37 +        gameoflife = new Simulation(canvas, 670, 670, 8);
    1.38          $("#gameoflife").mousemove(function(event) { 
    1.39              gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); 
    1.40 -        });
    1.41 -        alert("h");
    1.42 +        });       
    1.43      }
    1.44  }
    1.45  
    1.46 @@ -617,7 +623,7 @@
    1.47      return d;
    1.48  }
    1.49  
    1.50 -function Simulation(canvas, w, h) {
    1.51 +function Simulation(canvas, w, h, cell_size) {
    1.52      this.last_update = 0;
    1.53      this.last_draw = 0;
    1.54      this.last_mouse_moved = 0;
    1.55 @@ -628,7 +634,7 @@
    1.56      this.context = canvas.getContext("2d");    
    1.57      this.pos_queue = new Array();
    1.58      this.cell_queue = new Array();  
    1.59 -    var cell_size = 3;
    1.60 +    this.cell_size = cell_size;
    1.61      this.grid = new Grid(this.canvas.width, this.canvas.height, cell_size);
    1.62      draw_sim_lines();
    1.63  }