X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=2d.js;h=cb48fdfba45969142eef1cbffdcea8f2ae9d71ab;hb=96eed2a09cdd6d2e4796cf232347fd59291b594f;hp=f0e5f1e3ab318cb0106b529029b3d273ebf40e0f;hpb=eb70a4861e1e34d2b30b5e589cc5d4a07c0a18c9;p=cellular-automaton.git diff --git a/2d.js b/2d.js index f0e5f1e..cb48fdf 100644 --- a/2d.js +++ b/2d.js @@ -30,9 +30,10 @@ $(document).ready(function(){ } } - function universe() { + function universe(blank) { this.population = []; this.generation = 0; + var blank = blank || 0; for (var i = 0; i < rows; i++) { var world = []; @@ -41,7 +42,8 @@ $(document).ready(function(){ for (var ii = 0; ii < columns; ii++) { world.push(new cell(x, y, cellWidth, cellHeight)); x += cellWidth; - Math.random() > .5 ? world[ii].revive() : world[ii].kill(); + if (blank) { world[ii].kill(); } + else { Math.random() > .5 ? world[ii].revive() : world[ii].kill(); } } this.population.push(world); } @@ -67,7 +69,7 @@ $(document).ready(function(){ } } - function tick(automaton) { + function tick(automaton, blank) { automaton.generation += 1; var universe = automaton.population; var newUniverse = []; @@ -124,6 +126,22 @@ $(document).ready(function(){ running = 0; }); + $('#controls #reseed-automaton').click(function(e){ + if (running) clearInterval(tickID); + $('#controls #stop-automaton').hide(); + $('#controls #start-automaton').show(); + automaton = new universe(); + running = 0; + }); + + $('#controls #custom-seed-automaton').click(function(e){ + if (running) clearInterval(tickID); + $('#controls #stop-automaton').hide(); + $('#controls #start-automaton').show(); + automaton = new universe(1); + running = 0; + }); + $('#2d-automaton').click(function(e) { if (!running) { var x = e.pageX - $('#2d-automaton').offset().left;