!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.terra=t()}}(function(){var t;return function e(t,n,r){function o(a,u){if(!n[a]){if(!t[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(i)return i(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[a]={exports:{}};t[a][0].call(s.exports,function(e){var n=t[a][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;athis.maxEnergy&&(this.energy=this.maxEnergy)},t.prototype.isDead=function(){return this.energy<=0},t.prototype.reproduce=function(t){var e=n.filter(t,function(t){return!t.creature});if(e.length){var o=e[n.random(e.length-1)],i=o.coords,a=r.make(this.type),u=function(){return this.energy-=this.initialEnergy,!0}.bind(this),c=this.wait;return{x:i.x,y:i.y,creature:a,successFn:u,failureFn:c}}return!1},t.prototype.move=function(t){var e=this,r=n.filter(t,function(t){return t.creature.sizen*this.reproduceLv&&this.reproduce?e=this.reproduce(t):this.energy>n*this.moveLv&&this.move&&(e=this.move(t));var r=e.creature;return r?(r.successFn=e.successFn||r.wait,r.failureFn=e.failureFn||r.wait,{x:e.x,y:e.y,creature:r,observed:!0}):this.energy!==this.maxEnergy},e.prototype.boundEnergy=function(){},e.prototype.isDead=function(){return!1},e.prototype.process=function(){},e.prototype.wait=function(){};var o={};return{make:function(t,e){var n=o[t];return n?new n(e):!1},registerCreature:function(e,r){var i=e.type;if("string"==typeof i&&"undefined"==typeof o[i]){o[i]="function"==typeof r?function(){this.energy=this.initialEnergy,r.call(this)}:function(){this.energy=this.initialEnergy};var a=e.color;return("object"!=typeof a||3!==a.length)&&(e.color=[n.random(255),n.random(255),n.random(255)]),o[i].prototype=new t,o[i].prototype.constructor=o[i],n.each(e,function(t,e){o[i].prototype[e]=t}),o[i].prototype.successFn=o[i].wait,o[i].prototype.failureFn=o[i].wait,o[i].prototype.energy=e.initialEnergy,!0}return!1},registerCA:function(t,r){var i=t.type;if("string"==typeof i&&"undefined"==typeof o[i]){o[i]="function"==typeof r?function(){r.call(this)}:function(){};var a=t.color;return("object"!=typeof a||3!==a.length)&&(t.color=[n.random(255),n.random(255),n.random(255)]),o[i].prototype=new e,o[i].prototype.constructor=o[i],n.each(t,function(t,e){o[i].prototype[e]=t}),!0}return!1}}}();e.exports=r},{"./util.js":6}],3:[function(t,e){var n=t("./util.js");e.exports=function(t,e,r,o,i){var a=t.getContext("2d");if(o&&i)a.fillStyle="rgba("+i+","+(1-o)+")",a.fillRect(0,0,t.width,t.height);else{if(o)throw"Background must also be set for trails";a.clearRect(0,0,t.width,t.height)}n.each(e,function(t,e){n.each(t,function(t,n){if(t){var o=t.colorFn?t.colorFn():t.color+","+t.energy/t.maxEnergy;a.fillStyle="rgba("+o+")",t.character?a.fillText(t.character,e*r,n*r+r):a.fillRect(e*r,n*r,r,r)}})})}},{"./util.js":6}],4:[function(t,e){var n=function(t,e,n,r,o,i){function a(o){var a=document.createElement("canvas"),u=a.getContext("2d");return o=function(){var t=document.createElement("canvas").getContext("2d"),e=window.devicePixelRatio||1,n=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/n}(),a.width=t*o,a.height=e*o,a.style.width=t+"px",a.style.height=e+"px",u.setTransform(o,0,0,o,0,0),u.font="bold "+n+"px Arial",r&&(a.id=r),i&&(a.style.background="rgb("+i+")"),a}t*=n,e*=n;var u=a();return o?o.parentNode.insertBefore(u,o.nextSibling):document.body.appendChild(u),u};e.exports={createCanvasElement:n}},{}],5:[function(t,e){function n(t,e,n){var r=n.cellSize||10;this.width=t,this.height=e,this.cellSize=r,this.trails=n.trails,this.background=n.background,this.canvas=a.createCanvasElement(t,e,r,n.id,n.insertAfter,this.background),this.grid=[],this.nextFrame=!1,this.hasChanged=!1}var r=t("./util"),o=t("./creature.js"),i=t("./display.js"),a=t("./dom.js");n.prototype.makeGrid=function(t){for(var e=[],n=typeof t,r=0,i=this.width;i>r;r++){e.push([]);for(var a=0,u=this.height;u>a;a++)e[r].push(o.make("function"===n?t(r,a):"object"===n&&t.length?(t[a]||[])[r]:"string"===n?t:void 0))}return e},n.prototype.makeGridWithDistribution=function(t){for(var e=[],n=0,i=this.width;i>n;n++){e.push([]);for(var a=0,u=this.height;u>a;a++)e[n].push(o.make(r.pickRandomWeighted(t)))}return e},n.prototype.step=function(t){function e(t){if(t){var e=r.assign(new t.constructor,t),n=e&&e.isDead();return n&&!p.hasChanged&&(p.hasChanged=!0),e.age++,n?!1:e}return!1}function n(t){return r.map(t,e)}function o(t){return{coords:t,creature:g[t.x][t.y]}}function i(t){var e=t.creature;e?(e.failureFn(),e.boundEnergy()):(t.wait(),t.boundEnergy())}function a(t,e,n){if(t){var a=r.map(r.getNeighborCoords(e,n,h-1,y-1,t.actionRadius),o),u=t.process(a,e,n);if("object"==typeof u){var c=l[u.x],f=u.creature,s=u.y;c[s]||(c[s]=[]),c[s].push({x:e,y:n,creature:f}),!p.hasChanged&&f.observed&&(p.hasChanged=!0)}else u&&!p.hasChanged&&(p.hasChanged=!0),i(t)}}function u(t,e){r.each(t,function(t,n){a(t,e,n)})}function c(t,e,n){if(t){var o=t.splice(r.random(t.length-1),1)[0],a=o.creature;a.successFn()||(s[o.x][o.y]=!1),a.boundEnergy(),s[e][n]=a,r.each(t,i)}}function f(t,e){r.each(t,function(t,n){c(t,e,n)})}var s,l,p=this,h=this.width,y=this.height,g=this.grid;for("number"!=typeof t&&(t=1);t--;)if(this.hasChanged=!1,g=s?r.clone(s):this.grid,s=r.map(g,n),l=this.makeGrid(),r.each(s,u),r.each(l,f),!this.hasChanged)return!1;return s},n.prototype.draw=function(){i(this.canvas,this.grid,this.cellSize,this.trails,this.background)},n.prototype.animate=function(t,e){function n(){var i=o.step();return i&&(o.grid=i,o.draw(),++r!==t)?o.nextFrame=requestAnimationFrame(n):(o.nextFrame=!1,void(e&&e()))}if("function"==typeof t&&(e=t,t=null),!this.nextFrame){var r=0,o=this;o.nextFrame=requestAnimationFrame(n)}},n.prototype.stop=function(){cancelAnimationFrame(this.nextFrame),this.nextFrame=!1},e.exports=n},{"./creature.js":2,"./display.js":3,"./dom.js":4,"./util":6}],6:[function(t,e){t("../bower_components/seedrandom/seedrandom.js")("terra :)",{global:!0});var n=t("../lodash_custom/lodash.custom.min.js")._;n.getNeighborCoords=function(t,e,n,r,o){var i,a,u,c,f=[];("number"!=typeof o||1>o)&&(o=1),i=Math.max(0,t-o),u=Math.max(0,e-o),a=Math.min(t+o,n),c=Math.min(e+o,r);for(var s=i;a>=s;s++)for(var l=u;c>=l;l++)(s!==t||l!==e)&&f.push({x:s,y:l});return f},n.pickRandomWeighted=function(t){var e,r,o=0,i=n.random(100,!0);for(r=0,_len=t.length;_len>r;r++)if(e=t[r],o+=e[1],o>i)return e[0];return!1},e.exports=n},{"../bower_components/seedrandom/seedrandom.js":7,"../lodash_custom/lodash.custom.min.js":8}],7:[function(e,n){!function(t,e,n,r,o,i,a,u,c){function f(t){var e,n=t.length,o=this,i=0,a=o.i=o.j=0,u=o.S=[];for(n||(t=[n++]);r>i;)u[i]=i++;for(i=0;r>i;i++)u[i]=u[a=v&a+t[i%n]+(e=u[i])],u[a]=e;(o.g=function(t){for(var e,n=0,i=o.i,a=o.j,u=o.S;t--;)e=u[i=v&i+1],n=n*r+u[v&(u[i]=u[a=v&a+e])+(u[a]=e)];return o.i=i,o.j=a,n})(r)}function s(t,e){var n,r=[],o=typeof t;if(e&&"object"==o)for(n in t)try{r.push(s(t[n],e-1))}catch(i){}return r.length?r:"string"==o?t:t+"\x00"}function l(t,e){for(var n,r=t+"",o=0;ot;)t=(t+n)*r,e*=r,n=m.g(1);for(;t>=d;)t/=2,e/=2,n>>>=1;return(t+n)/e},v,"global"in i?i.global:this==n)};l(n[c](),e),a&&a.exports?a.exports=m:u&&u.amd&&u(function(){return m})}(this,[],Math,256,6,52,"object"==typeof n&&n,"function"==typeof t&&t,"random")},{}],8:[function(t,e,n){(function(t){(function(){function r(t){return"function"!=typeof t.toString&&"string"==typeof(t+"")}function o(t){t.length=0,A.lengthn?0:n);++rk;k++)r+="n='"+n.h[k]+"';if((!(r&&x[n])&&m.call(t,n))",n.j||(r+="||(!x[n]&&t[n]!==A[n])"),r+="){"+n.g+"}";r+="}"}return(n.b||xe.nonEnumArgs)&&(r+="}"),r+=n.c+";return E",t("d,j,k,m,o,p,q,s,v,A,B,y,I,J,L",e+r+"}")(s,T,ee,ce,D,d,we,b,V.f,ne,H,be,U,re,oe)}function g(t){return"function"==typeof t&&ie.test(t)}function d(t){return t&&"object"==typeof t&&"number"==typeof t.length&&oe.call(t)==L||!1}function v(t){return"function"==typeof t}function m(t){return!(!t||!H[typeof t])}function b(t){return"string"==typeof t||t&&"object"==typeof t&&oe.call(t)==U||!1}function x(t,e,n){var r=[];if(e=a.createCallback(e,n,3),we(t)){n=-1;for(var o=t.length;++narguments.length;if(e=a.createCallback(e,r,4),we(t)){var i=-1,u=t.length;for(o&&(n=t[++i]);++i3&&typeof a[c-2]=='function'){var e=d(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){e=a[--c]}"),g:"E[n]=e?e(E[n],t[n]):t[n]"}),Se=y(Z,_e,{j:!1}),Oe=y(Z,_e);v(/x/)&&(v=function(t){return"function"==typeof t&&"[object Function]"==oe.call(t)}),a.assign=Fe,a.bind=_,a.createCallback=function(t,e,n){var r=typeof t;if(null==t||"function"==r)return s(t,e,n);if("object"!=r)return O(t);var o=Ce(t),i=o[0],a=t[i];return 1!=o.length||a!==a||m(a)?function(e){for(var n=o.length,r=!1;n--&&(r=p(e[o[n]],t[o[n]],null,!0)););return r}:function(t){return t=t[i],a===t&&(0!==a||1/a==1/t)}},a.filter=x,a.forEach=j,a.forIn=Se,a.forOwn=Oe,a.keys=Ce,a.map=w,a.property=O,a.collect=w,a.each=j,a.extend=Fe,a.select=x,a.clone=function(t,e,n,r){return"boolean"!=typeof e&&null!=e&&(r=n,n=e,e=!1),c(t,e,"function"==typeof n&&s(n,r,1))},a.identity=F,a.isArguments=d,a.isArray=we,a.isFunction=v,a.isObject=m,a.isString=b,a.noop=S,a.random=function(t,e,n){var r=null==t,o=null==e;return null==n&&("boolean"==typeof t&&o?(n=t,t=1):o||"boolean"!=typeof e||(n=e,o=!0)),r&&o&&(e=1),t=+t||0,o?(e=t,t=0):e=+e||0,n||t%1||e%1?(n=ve(),de(t+n*(e-t+parseFloat("1e-"+((n+"").length-1))),e)):t+ae(ve()*(e-t+1))},a.reduce=E,a.some=C,a.any=C,a.foldl=E,a.inject=E,a.VERSION="2.4.1",X&&Y&&(X._=a)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)});