From e6c6ce3a333bdac0925e35e7fe4ccfb60a7fab56 Mon Sep 17 00:00:00 2001 From: Riley Shaw Date: Mon, 25 Aug 2014 10:29:29 -0700 Subject: [PATCH] Update dist with e20c16c1 --- dist/terra.js | 3 ++- dist/terra.min.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/terra.js b/dist/terra.js index c66108c..19440bf 100755 --- a/dist/terra.js +++ b/dist/terra.js @@ -265,9 +265,10 @@ var dom = require('./dom.js'); * @param {string} insertAfter id of the element to insert the canvas after */ function Terrarium(width, height, id, cellSize, insertAfter) { + cellSize = cellSize || 10; this.width = width; this.height = height; - this.cellSize = cellSize || 10; + this.cellSize = cellSize; this.grid = []; this.canvas = dom.createCanvasElement(width * cellSize, height * cellSize, id, insertAfter); this.nextFrame = false; diff --git a/dist/terra.min.js b/dist/terra.min.js index 19800d1..6a88d65 100755 --- a/dist/terra.min.js +++ b/dist/terra.min.js @@ -1 +1 @@ -!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(u,a){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;uthis.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,u=r.make(this.type),a=function(){return this.energy-=this.initialEnergy,!0}.bind(this),c=this.wait;return{x:i.x,y:i.y,creature:u,successFn:a,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}):!1};var e={};return{make:function(t,n){var r=e[t];return r?new r(n):!1},register:function(r,o){var i=r.type;if("string"==typeof i&&"undefined"==typeof e[i]){e[i]="function"==typeof o?function(){this.energy=this.initialEnergy,o.call(this)}:function(){this.energy=this.initialEnergy};var u=r.color;return("object"!=typeof u||3!==u.length)&&(r.color=[n.random(255),n.random(255),n.random(255)]),e[i].prototype=new t,e[i].prototype.constructor=e[i],n.each(r,function(t,n){e[i].prototype[n]=t}),e[i].prototype.successFn=e[i].wait,e[i].prototype.failureFn=e[i].wait,e[i].prototype.energy=r.initialEnergy,!0}return!1}}}();e.exports=r},{"./util.js":6}],3:[function(t,e){var n=t("./util.js");e.exports=function(t,e,r){var o=t.getContext("2d");o.font="bold "+r+"px Arial",o.clearRect(0,0,t.width,t.height),n.each(e,function(t,e){n.each(t,function(t,n){if(t){var i=t.colorFn?t.colorFn():t.color+","+t.energy/t.maxEnergy;o.fillStyle="rgba("+i+")",t.character?o.fillText(t.character,e*r,n*r+r):o.fillRect(e*r,n*r,r,r)}})})}},{"./util.js":6}],4:[function(t,e){var n=function(t,e,n,r){function o(r){var o=document.createElement("canvas");return r=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}(),o.width=t*r,o.height=e*r,o.style.width=t+"px",o.style.height=e+"px",o.getContext("2d").setTransform(r,0,0,r,0,0),n&&(o.id=n),o}var i=o();return r?r.parentNode.insertBefore(i,r.nextSibling):document.body.appendChild(i),i};e.exports={createCanvasElement:n}},{}],5:[function(t,e){function n(t,e,n,r,o){this.width=t,this.height=e,this.cellSize=r||10,this.grid=[],this.canvas=u.createCanvasElement(t*r,e*r,n,o),this.nextFrame=!1}var r=t("./util"),o=t("./creature.js"),i=t("./display.js"),u=t("./dom.js");n.prototype.populate=function(t,e){function n(t,e){var n=t+e[1];return!i&&n>u&&(i=o.make(e[0])),n}var i,u=0;e||(e=this.grid);for(var a=this.width;a--;)if(e[a]=[],t)for(var c=this.height;c--;)i=!1,u=r.random(100,!0),r.reduce(t,n,0),e[a].push(i)},n.prototype.step=function(t){function e(t){if(t){var e=r.assign(new t.constructor,t);return e.isDead()?!1:e}return!1}function n(t){return r.map(t,e)}function o(t){return{coords:t,creature:h[t.x][t.y]}}function i(t){var e=t.creature;e?(e.failureFn(),e.boundEnergy()):(t.wait(),t.boundEnergy())}function u(t,e,n){if(t){var u=r.map(r.getNeighborCoords(e,n,p-1,y-1,t.actionRadius),o),a=t.queue(u);if(a){var c=l[a.x];c[a.y]||(c[a.y]=[]),c[a.y].push({x:e,y:n,creature:a.creature})}else i(t)}}function a(t,e){r.each(t,function(t,n){u(t,e,n)})}function c(t,e,n){if(t){var o=t.splice(r.random(t.length-1),1)[0],u=o.creature;u.successFn()===!1&&(s[o.x][o.y]=!1),u.boundEnergy(),s[e][n]=u,r.each(t,i)}}function f(t,e){r.each(t,function(t,n){c(t,e,n)})}var s,l,p=this.width,y=this.height,h=this.grid;for("number"!=typeof t&&(t=1);t--;)h=s?r.clone(s):this.grid,s=r.map(h,n),l=[],this.populate(!1,l),r.each(s,a),r.each(l,f);return s},n.prototype.draw=function(){i(this.canvas,this.grid,this.cellSize)},n.prototype.animate=function(t,e){function n(){o.grid=o.step(),o.draw(),r++!==t?o.nextFrame=requestAnimationFrame(n):(o.nextFrame=!1,e())}if(!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,u,a,c,f=[];("number"!=typeof o||1>o)&&(o=1),i=Math.max(0,t-o),a=Math.max(0,e-o),u=Math.min(t+o,n),c=Math.min(e+o,r);for(var s=i;u>=s;s++)for(var l=a;c>=l;l++)(s!==t||l!==e)&&f.push({x:s,y:l});return f},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,u,a,c){function f(t){var e,n=t.length,o=this,i=0,u=o.i=o.j=0,a=o.S=[];for(n||(t=[n++]);r>i;)a[i]=i++;for(i=0;r>i;i++)a[i]=a[u=v&u+t[i%n]+(e=a[i])],a[u]=e;(o.g=function(t){for(var e,n=0,i=o.i,u=o.j,a=o.S;t--;)e=a[i=v&i+1],n=n*r+a[v&(a[i]=a[u=v&u+e])+(a[u]=e)];return o.i=i,o.j=u,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),u&&u.exports?u.exports=m:a&&a.amd&&a(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,P,d,we,b,H.f,ne,Q,be,G,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)==z||!1}function v(t){return"function"==typeof t}function m(t){return!(!t||!Q[typeof t])}function b(t){return"string"==typeof t||t&&"object"==typeof t&&oe.call(t)==G||!1}function x(t,e,n){var r=[];if(e=u.createCallback(e,n,3),we(t)){n=-1;for(var o=t.length;++narguments.length;if(e=u.createCallback(e,r,4),we(t)){var i=-1,a=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]"}),Ce=h(Z,_e,{j:!1}),ke=h(Z,_e);v(/x/)&&(v=function(t){return"function"==typeof t&&"[object Function]"==oe.call(t)}),u.assign=Oe,u.bind=_,u.createCallback=function(t,e,n){var r=typeof t;if(null==t||"function"==r)return s(t,e,n);if("object"!=r)return C(t);var o=Fe(t),i=o[0],u=t[i];return 1!=o.length||u!==u||m(u)?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],u===t&&(0!==u||1/u==1/t)}},u.filter=x,u.forEach=j,u.forIn=Ce,u.forOwn=ke,u.keys=Fe,u.map=w,u.property=C,u.collect=w,u.each=j,u.extend=Oe,u.select=x,u.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))},u.identity=S,u.isArguments=d,u.isArray=we,u.isFunction=v,u.isObject=m,u.isString=b,u.noop=O,u.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+ue(ve()*(e-t+1))},u.reduce=E,u.some=F,u.any=F,u.foldl=E,u.inject=E,u.VERSION="2.4.1",X&&Y&&(X._=u)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)}); \ No newline at end of file +!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(u,a){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;uthis.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,u=r.make(this.type),a=function(){return this.energy-=this.initialEnergy,!0}.bind(this),c=this.wait;return{x:i.x,y:i.y,creature:u,successFn:a,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}):!1};var e={};return{make:function(t,n){var r=e[t];return r?new r(n):!1},register:function(r,o){var i=r.type;if("string"==typeof i&&"undefined"==typeof e[i]){e[i]="function"==typeof o?function(){this.energy=this.initialEnergy,o.call(this)}:function(){this.energy=this.initialEnergy};var u=r.color;return("object"!=typeof u||3!==u.length)&&(r.color=[n.random(255),n.random(255),n.random(255)]),e[i].prototype=new t,e[i].prototype.constructor=e[i],n.each(r,function(t,n){e[i].prototype[n]=t}),e[i].prototype.successFn=e[i].wait,e[i].prototype.failureFn=e[i].wait,e[i].prototype.energy=r.initialEnergy,!0}return!1}}}();e.exports=r},{"./util.js":6}],3:[function(t,e){var n=t("./util.js");e.exports=function(t,e,r){var o=t.getContext("2d");o.font="bold "+r+"px Arial",o.clearRect(0,0,t.width,t.height),n.each(e,function(t,e){n.each(t,function(t,n){if(t){var i=t.colorFn?t.colorFn():t.color+","+t.energy/t.maxEnergy;o.fillStyle="rgba("+i+")",t.character?o.fillText(t.character,e*r,n*r+r):o.fillRect(e*r,n*r,r,r)}})})}},{"./util.js":6}],4:[function(t,e){var n=function(t,e,n,r){function o(r){var o=document.createElement("canvas");return r=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}(),o.width=t*r,o.height=e*r,o.style.width=t+"px",o.style.height=e+"px",o.getContext("2d").setTransform(r,0,0,r,0,0),n&&(o.id=n),o}var i=o();return r?r.parentNode.insertBefore(i,r.nextSibling):document.body.appendChild(i),i};e.exports={createCanvasElement:n}},{}],5:[function(t,e){function n(t,e,n,r,o){r=r||10,this.width=t,this.height=e,this.cellSize=r,this.grid=[],this.canvas=u.createCanvasElement(t*r,e*r,n,o),this.nextFrame=!1}var r=t("./util"),o=t("./creature.js"),i=t("./display.js"),u=t("./dom.js");n.prototype.populate=function(t,e){function n(t,e){var n=t+e[1];return!i&&n>u&&(i=o.make(e[0])),n}var i,u=0;e||(e=this.grid);for(var a=this.width;a--;)if(e[a]=[],t)for(var c=this.height;c--;)i=!1,u=r.random(100,!0),r.reduce(t,n,0),e[a].push(i)},n.prototype.step=function(t){function e(t){if(t){var e=r.assign(new t.constructor,t);return e.isDead()?!1:e}return!1}function n(t){return r.map(t,e)}function o(t){return{coords:t,creature:h[t.x][t.y]}}function i(t){var e=t.creature;e?(e.failureFn(),e.boundEnergy()):(t.wait(),t.boundEnergy())}function u(t,e,n){if(t){var u=r.map(r.getNeighborCoords(e,n,p-1,y-1,t.actionRadius),o),a=t.queue(u);if(a){var c=l[a.x];c[a.y]||(c[a.y]=[]),c[a.y].push({x:e,y:n,creature:a.creature})}else i(t)}}function a(t,e){r.each(t,function(t,n){u(t,e,n)})}function c(t,e,n){if(t){var o=t.splice(r.random(t.length-1),1)[0],u=o.creature;u.successFn()===!1&&(s[o.x][o.y]=!1),u.boundEnergy(),s[e][n]=u,r.each(t,i)}}function f(t,e){r.each(t,function(t,n){c(t,e,n)})}var s,l,p=this.width,y=this.height,h=this.grid;for("number"!=typeof t&&(t=1);t--;)h=s?r.clone(s):this.grid,s=r.map(h,n),l=[],this.populate(!1,l),r.each(s,a),r.each(l,f);return s},n.prototype.draw=function(){i(this.canvas,this.grid,this.cellSize)},n.prototype.animate=function(t,e){function n(){o.grid=o.step(),o.draw(),r++!==t?o.nextFrame=requestAnimationFrame(n):(o.nextFrame=!1,e())}if(!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,u,a,c,f=[];("number"!=typeof o||1>o)&&(o=1),i=Math.max(0,t-o),a=Math.max(0,e-o),u=Math.min(t+o,n),c=Math.min(e+o,r);for(var s=i;u>=s;s++)for(var l=a;c>=l;l++)(s!==t||l!==e)&&f.push({x:s,y:l});return f},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,u,a,c){function f(t){var e,n=t.length,o=this,i=0,u=o.i=o.j=0,a=o.S=[];for(n||(t=[n++]);r>i;)a[i]=i++;for(i=0;r>i;i++)a[i]=a[u=v&u+t[i%n]+(e=a[i])],a[u]=e;(o.g=function(t){for(var e,n=0,i=o.i,u=o.j,a=o.S;t--;)e=a[i=v&i+1],n=n*r+a[v&(a[i]=a[u=v&u+e])+(a[u]=e)];return o.i=i,o.j=u,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),u&&u.exports?u.exports=m:a&&a.amd&&a(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,P,d,we,b,H.f,ne,Q,be,G,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)==z||!1}function v(t){return"function"==typeof t}function m(t){return!(!t||!Q[typeof t])}function b(t){return"string"==typeof t||t&&"object"==typeof t&&oe.call(t)==G||!1}function x(t,e,n){var r=[];if(e=u.createCallback(e,n,3),we(t)){n=-1;for(var o=t.length;++narguments.length;if(e=u.createCallback(e,r,4),we(t)){var i=-1,a=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]"}),Ce=h(Z,_e,{j:!1}),ke=h(Z,_e);v(/x/)&&(v=function(t){return"function"==typeof t&&"[object Function]"==oe.call(t)}),u.assign=Oe,u.bind=_,u.createCallback=function(t,e,n){var r=typeof t;if(null==t||"function"==r)return s(t,e,n);if("object"!=r)return C(t);var o=Fe(t),i=o[0],u=t[i];return 1!=o.length||u!==u||m(u)?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],u===t&&(0!==u||1/u==1/t)}},u.filter=x,u.forEach=j,u.forIn=Ce,u.forOwn=ke,u.keys=Fe,u.map=w,u.property=C,u.collect=w,u.each=j,u.extend=Oe,u.select=x,u.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))},u.identity=S,u.isArguments=d,u.isArray=we,u.isFunction=v,u.isObject=m,u.isString=b,u.noop=O,u.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+ue(ve()*(e-t+1))},u.reduce=E,u.some=F,u.any=F,u.foldl=E,u.inject=E,u.VERSION="2.4.1",X&&Y&&(X._=u)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)}); \ No newline at end of file