mirror of
https://github.com/rileyjshaw/terra.git
synced 2024-11-21 04:54:23 +00:00
Add age count, x and y in process(), and :s/framework/library
This commit is contained in:
parent
d394f3caa3
commit
5f659888a3
@ -1,7 +1,7 @@
|
||||
terra
|
||||
=====
|
||||
|
||||
JS framework for cellular automata and simple biological simulations. Documentation and examples live [here](http://rileyjshaw.com/terra/).
|
||||
JS library for cellular automata and simple biological simulations. Documentation and examples live [here](http://rileyjshaw.com/terra/).
|
||||
|
||||
## Hacking this library
|
||||
To build terra on your machine you'll need [Node.js](http://nodejs.org/), [Bower](http://bower.io/), and [gulp](http://gulpjs.com/) installed. Then...
|
||||
|
@ -5,7 +5,9 @@ var factory = (function () {
|
||||
function baseCreature() {
|
||||
this.age = 0;
|
||||
}
|
||||
function baseCA() {}
|
||||
function baseCA() {
|
||||
this.age = 0;
|
||||
}
|
||||
|
||||
baseCreature.prototype.initialEnergy = 50;
|
||||
baseCreature.prototype.maxEnergy = 100;
|
||||
@ -96,7 +98,7 @@ var factory = (function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
baseCreature.prototype.process = function (neighbors) {
|
||||
baseCreature.prototype.process = function (neighbors, x, y) {
|
||||
var step = {};
|
||||
var maxEnergy = this.maxEnergy;
|
||||
|
||||
@ -122,7 +124,7 @@ var factory = (function () {
|
||||
|
||||
baseCA.prototype.boundEnergy = function () {};
|
||||
baseCA.prototype.isDead = function () { return false; };
|
||||
baseCA.prototype.process = function (neighbors) {};
|
||||
baseCA.prototype.process = function (neighbors, x, y) {};
|
||||
baseCA.prototype.wait = function () {};
|
||||
|
||||
// Storage for our creature types
|
||||
|
@ -67,6 +67,7 @@ Terrarium.prototype.step = function (steps) {
|
||||
function copyAndRemoveInner (origCreature) {
|
||||
if (origCreature) {
|
||||
var copy = _.assign(new (origCreature.constructor)(), origCreature);
|
||||
copy.age++;
|
||||
return copy && !copy.isDead() ? copy : false;
|
||||
} else return false;
|
||||
}
|
||||
@ -99,7 +100,7 @@ Terrarium.prototype.step = function (steps) {
|
||||
_.getNeighborCoords(x, y, gridWidth - 1, gridHeight - 1, creature.actionRadius),
|
||||
zipCoordsWithNeighbors
|
||||
);
|
||||
var result = creature.process(neighbors);
|
||||
var result = creature.process(neighbors, x, y);
|
||||
if (result) {
|
||||
var eigenColumn = eigenGrid[result.x];
|
||||
if (!eigenColumn[result.y]) eigenColumn[result.y] = [];
|
||||
|
@ -5,7 +5,7 @@
|
||||
"authors": [
|
||||
"rileyjshaw <i@rileyjshaw.com>"
|
||||
],
|
||||
"description": "A JavaScript framework for simple biological simulations and cellular automata.",
|
||||
"description": "A JavaScript library for simple biological simulations and cellular automata.",
|
||||
"main": "dist/terra.min.js",
|
||||
"moduleType": [
|
||||
"node"
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "terra",
|
||||
"version": "1.0.0-beta",
|
||||
"description": "A JavaScript framework for simple biological simulations and cellular automata.",
|
||||
"description": "A JavaScript library for simple biological simulations and cellular automata.",
|
||||
"main": "dist/terra.min.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
Loading…
Reference in New Issue
Block a user