rileyjshaw/terra — pull request #8 by johnhenry (2014-08-24 05:57:43+00:00)
Title: Added "render" method

The render method is similar to the to the animate method, except is has two callbacks -- one that's executed after each iteration in addition to the one executed at the end.
In addition, on each iteration, the method is passed an object representing the simulation at that stage, with "canvas" and "grid" properties, so the simulations don't have to be in real time and you can look at the data later or all at once rather than in individual frames.
At the end of the iteration, the final callback is passed an array of all objects representing all stages.
My motivation behind this to study 1-dimensional cellular automata (Wolfram) which is generally done by running the simulation over multiple steps and looking at them all at once.
The following code, based on the Game Of Life demo, works in the way I had have intended (that is, _if_ my update is merged).

```js
Math.seedrandom();
var CellularAutomata = new terra.Terrarium(100, 1, undefined, undefined, undefined, true);
terra.creatureFactory.register({
type: 'CA',
colorFn: function () { return this.alive ? this.color + ',1' : '0,0,0,0'; },
wait: function () {},
isDead: function () { return false; },
queue: function (neighbors) {
var surrounding = _.filter(neighbors, function (spot) {
return spot.creature.alive;
}).length;
this.alive = surrounding > 1 && this.alive;
return false;
}
}, function () {
this.alive = Math.random() < 0.80;
});
CellularAutomata.populate([['CA', 100]]);
CellularAutomata.render(25,
function(frame){
document.body.appendChild(frame.canvas);//Attach Iteration to DOM
document.body.appendChild(document.createElement("br"));
},function(){
alert("Simulation Complete!")
});
```