- var world = populate_world();
- while (generations) { generate(); generations-- }
- //var tick_id = setInterval(generate, 100);
+ var automaton = new universe;
+ var tickID = 0;
+ var running = 0;
+
+ $('#controls #start-automaton').click(function(e){
+ tickID = setInterval(function(){tick(automaton)}, 100);
+ $('#controls #start-automaton').hide();
+ $('#controls #stop-automaton').show();
+ running = 1;
+ });
+
+ $('#controls #stop-automaton').click(function(e){
+ if (running) clearInterval(tickID);
+ $('#controls #stop-automaton').hide();
+ $('#controls #start-automaton').show();
+ running = 0;
+ });
+
+ $('#controls #reseed-automaton').click(function(e){
+ if (running) clearInterval(tickID);
+ $('#controls #stop-automaton').hide();
+ $('#controls #start-automaton').show();
+ running = 0;
+ automaton = new universe;
+ });
+
+ $('#2d-automaton').click(function(e) {
+ if (!running) {
+ var x = e.pageX - $('#2d-automaton').offset().left;
+ var y = e.pageY - $('#2d-automaton').offset().top;
+ var row = Math.floor(y / cellHeight);
+ var column = Math.floor(x / cellWidth);
+ automaton.population[row][column].toggle();
+ }
+ });