From: Dylan Lloyd Date: Thu, 27 Dec 2012 06:11:41 +0000 (-0500) Subject: created populate function to seed from serialize X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=HEAD;p=cellular-automaton.git created populate function to seed from serialize --- diff --git a/2d.js b/2d.js index c3a4bbe..2e731c9 100644 --- a/2d.js +++ b/2d.js @@ -77,14 +77,25 @@ $(document).ready(function(){ } this.serialize = function() { - var serial = ''; + var serial = []; for (var i = 0; i < this.rows; i++) { + var row = []; for (var ii = 0; ii < this.columns; ii++) { - serial += this.population[i][ii].state; + row[ii] = this.population[i][ii].state; } + serial.push(row); } return serial; } + + this.populate = function(seed) { + for (var i = 0; i < this.rows; i++) { + for (var ii = 0; ii < this.columns; ii++) { + seed[i][ii] ? this.population[i][ii].revive() + : this.population[i][ii].kill(); + } + } + } } function tick(automaton) {