11 lines
No EOL
66 KiB
JavaScript
11 lines
No EOL
66 KiB
JavaScript
/*!
|
|
* Proton v4.1.5
|
|
* https://github.com/drawcall/Proton
|
|
*
|
|
* Copyright 2013-2019, A-JIE
|
|
* Licensed under the MIT license
|
|
* http://www.opensource.org/licenses/mit-license
|
|
*
|
|
*/
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Proton=e()}(this,function(){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var e=3.1415926,h={PI:e,PIx2:2*e,PI_2:e/2,PI_180:e/180,N180_PI:180/e,Infinity:-999,isInfinity:function(t){return t===this.Infinity||t===1/0},randomAToB:function(t,e,i){return 2<arguments.length&&void 0!==i&&i?Math.floor(Math.random()*(e-t))+t:t+Math.random()*(e-t)},randomFloating:function(t,e,i){return this.randomAToB(t-e,t+e,i)},randomColor:function(){return"#"+("00000"+(16777216*Math.random()<<0).toString(16)).slice(-6)},randomZone:function(){},floor:function(t,e){var i=1<arguments.length&&void 0!==e?e:4,a=Math.pow(10,i);return Math.floor(t*a)/a},degreeTransform:function(t){return t*e/180},toColor16:function(t){return"#"+t.toString(16)}},i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t=function(t,e,i){return e&&a(t.prototype,e),i&&a(t,i),t};function a(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function o(t,e,i){null===t&&(t=Function.prototype);var a=Object.getOwnPropertyDescriptor(t,e);if(void 0===a){var r=Object.getPrototypeOf(t);return null===r?void 0:o(r,e,i)}if("value"in a)return a.value;var n=a.get;return void 0!==n?n.call(i):void 0}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var n=(t(u,[{key:"getValue",value:function(t){var e=0<arguments.length&&void 0!==t&&t;return this.isArray?P.getRandFromArray(this.a):this.center?h.randomFloating(this.a,this.b,e):h.randomAToB(this.a,this.b,e)}}],[{key:"setSpanValue",value:function(t,e,i){return t instanceof u?t:void 0===e?new u(t):void 0===i?new u(t,e):new u(t,e,i)}},{key:"getSpanValue",value:function(t){return t instanceof u?t.getValue():t}}]),u);function u(t,e,i){s(this,u),P.isArray(t)?(this.isArray=!0,this.a=t):(this.isArray=!1,this.a=P.initValue(t,1),this.b=P.initValue(e,this.a),this.center=P.initValue(i,!1))}var c=function(t){--t;for(var e=1;e<32;e<<=1)t|=t>>e;return t+1},d=function(t,e){return[1,0,0,0,1,0,t,e,1]},y=function(t){var e=Math.cos(t),i=Math.sin(t);return[e,-i,0,i,e,0,0,0,1]},p=function(t,e){return[t,0,0,0,e,0,0,0,1]},f=function(t,e){var i=t[0],a=t[1],r=t[2],n=t[3],s=t[4],o=t[5],h=t[6],l=t[7],u=t[8],c=e[0],d=e[1],y=e[2],p=e[3],f=e[4],v=e[5],g=e[6],m=e[7],b=e[8];return[i*c+a*p+r*g,i*d+a*f+r*m,i*y+a*v+r*b,n*c+s*p+o*g,n*d+s*f+o*m,n*y+s*v+o*b,h*c+l*p+u*g,h*d+l*f+u*m,h*y+l*v+u*b]},v={createCanvas:function(t,e,i,a){var r=3<arguments.length&&void 0!==a?a:"absolute",n=document.createElement("canvas");return n.id=t,n.width=e,n.height=i,n.style.opacity=0,n.style.position=r,this.transform(n,-500,-500,0,0),n},createDiv:function(t,e,i){var a=document.createElement("div");return a.id=t,a.style.position="absolute",this.resize(a,e,i),a},resize:function(t,e,i){t.style.width=e+"px",t.style.height=i+"px",t.style.marginLeft=-e/2+"px",t.style.marginTop=-i/2+"px"},transform:function(t,e,i,a,r){t.style.willChange="transform";var n="translate("+e+"px, "+i+"px) scale("+a+") rotate("+r+"deg)";this.css3(t,"transform",n)},transform3d:function(t,e,i,a,r){t.style.willChange="transform";var n="translate3d("+e+"px, "+i+"px, 0) scale("+a+") rotate("+r+"deg)";this.css3(t,"backfaceVisibility","hidden"),this.css3(t,"transform",n)},css3:function(t,e,i){var a=e.charAt(0).toUpperCase()+e.substr(1);t.style["Webkit"+a]=i,t.style["Moz"+a]=i,t.style["O"+a]=i,t.style["ms"+a]=i,t.style[""+e]=i}},g={},m={},b=0,_=function(t,e,i){t.drawImage(e,i.x,i.y);var a=t.getImageData(i.x,i.y,i.width,i.height);return t.clearRect(i.x,i.y,i.width,i.height),a},x=function(t,e,i){var a="string"==typeof t?t:t.src;if(g[a])e(g[a],i);else{var r=new Image;r.onload=function(t){g[a]=t.target,e(g[a],i)},r.src=a}},k=function(t,e,i){var a=t.src;if(!m[a]){var r=c(t.width),n=c(t.height),s=v.createCanvas("proton_canvas_cache_"+ ++b,r,n);s.getContext("2d").drawImage(t,0,0,t.width,t.height),m[a]=s}return e&&e(m[a],i),m[a]},P={initValue:function(t,e){return t=null!=t?t:e},isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},emptyArray:function(t){t&&(t.length=0)},toArray:function(t){return this.isArray(t)?t:[t]},getRandFromArray:function(t){return t?t[Math.floor(t.length*Math.random())]:null},emptyObject:function(t,e){var i=1<arguments.length&&void 0!==e?e:null;for(var a in t)i&&-1<i.indexOf(a)||delete t[a]},classApply:function(t,e){var i=1<arguments.length&&void 0!==e?e:null;return i?new(t.bind.apply(t,[null].concat(i))):new t},setVectorVal:function(t,e){var i=1<arguments.length&&void 0!==e?e:null;i&&(this.hasProp(i,"x")&&(t.p.x=i.x),this.hasProp(i,"y")&&(t.p.y=i.y),this.hasProp(i,"vx")&&(t.v.x=i.vx),this.hasProp(i,"vy")&&(t.v.y=i.vy),this.hasProp(i,"ax")&&(t.a.x=i.ax),this.hasProp(i,"ay")&&(t.a.y=i.ay),this.hasProp(i,"p")&&t.p.copy(i.p),this.hasProp(i,"v")&&t.v.copy(i.v),this.hasProp(i,"a")&&t.a.copy(i.a),this.hasProp(i,"position")&&t.p.copy(i.position),this.hasProp(i,"velocity")&&t.v.copy(i.velocity),this.hasProp(i,"accelerate")&&t.a.copy(i.accelerate))},hasProp:function(t,e){return!!t&&void 0!==t[e]},setProp:function(t,e){for(var i in e)t.hasOwnProperty(i)&&(t[i]=n.getSpanValue(e[i]));return t},getImageData:function(t,e,i){return _(t,e,i)},destroyAll:function(t,e){for(var i=1<arguments.length&&void 0!==e?e:null,a=t.length;a--;){try{t[a].destroy(i)}catch(t){}delete t[a]}t.length=0},assign:function(t,e){if("function"==typeof Object.assign)return Object.assign(t,e);for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}},E={},A={_index:0,_cache:{},id:function(t){return void 0!==E[t]&&null!==E[t]||(E[t]=0),t+"_"+E[t]++},getId:function(t){var e=this.getIdFromCache(t);return e||(e="PUID_"+this._index++,this._cache[e]=t,e)},getIdFromCache:function(t){var e=void 0,i=void 0;for(i in this._cache){if((e=this._cache[i])===t)return i;if(this.isBody(e,t)&&e.src===t.src)return i}return null},isBody:function(t,e){return"object"===(void 0===t?"undefined":i(t))&&"object"===(void 0===e?"undefined":i(e))&&t.isInner&&e.isInner},getTarget:function(t){return this._cache[t]}},T=(t(R,[{key:"get",value:function(t,e,i){var a=void 0;return i=i||t.__puid||A.getId(t),(a=this.cache[i]&&0<this.cache[i].length?this.cache[i].pop():this.createOrClone(t,e)).__puid=t.__puid||i,a}},{key:"expire",value:function(t){return this.getCache(t.__puid).push(t)}},{key:"createOrClone",value:function(t,e){return this.total++,this.create?this.create(t,e):"function"==typeof t?P.classApply(t,e):t.clone()}},{key:"getCount",value:function(){var t=0;for(var e in this.cache)t+=this.cache[e].length;return t++}},{key:"destroy",value:function(){for(var t in this.cache)this.cache[t].length=0,delete this.cache[t]}},{key:"getCache",value:function(t){var e=0<arguments.length&&void 0!==t?t:"default";return this.cache[e]||(this.cache[e]=[]),this.cache[e]}}]),R);function R(t){s(this,R),this.total=0,this.cache={}}var O=(t(w,[{key:"update",value:function(t,e){this.add(t,e);var i=this.getEmitter(),a=this.getRenderer(),r="";switch(this.type){case 2:r+="emitter:"+this.proton.emitters.length+"<br>",i&&(r+="em speed:"+i.emitSpeed+"<br>"),i&&(r+="pos:"+this.getEmitterPos(i));break;case 3:i&&(r+="initializes:"+i.initializes.length+"<br>"),i&&(r+='<span style="display:inline-block;">'+this.concatArr(i.initializes)+"</span><br>"),i&&(r+="behaviours:"+i.behaviours.length+"<br>"),i&&(r+='<span style="display:inline-block;">'+this.concatArr(i.behaviours)+"</span><br>");break;case 4:a&&(r+=a.name+"<br>"),a&&(r+="body:"+this.getCreatedNumber(a)+"<br>");break;default:r+="particles:"+this.proton.getCount()+"<br>",r+="pool:"+this.proton.pool.getCount()+"<br>",r+="total:"+this.proton.pool.total}this.container.innerHTML=r}},{key:"add",value:function(t,e){var i=this;if(!this.container){this.type=1,this.container=document.createElement("div"),this.container.style.cssText=["position:absolute;bottom:0px;left:0;cursor:pointer;","opacity:0.9;z-index:10000;padding:10px;font-size:12px;font-family:Helvetica,Arial,sans-serif;","width:120px;height:50px;background-color:#002;color:#0ff;"].join(""),this.container.addEventListener("click",function(t){i.type++,4<i.type&&(i.type=1)},!1);var a=void 0,r=void 0;switch(t){case 2:a="#201",r="#f08";break;case 3:a="#020",r="#0f0";break;default:a="#002",r="#0ff"}this.container.style["background-color"]=a,this.container.style.color=r}this.container.parentNode||(e=e||this.body||document.body).appendChild(this.container)}},{key:"getEmitter",value:function(){return this.proton.emitters[this.emitterIndex]}},{key:"getRenderer",value:function(){return this.proton.renderers[this.rendererIndex]}},{key:"concatArr",value:function(t){var e="";if(!t||!t.length)return e;for(var i=0;i<t.length;i++)e+=(t[i].name||"").substr(0,1)+".";return e}},{key:"getCreatedNumber",value:function(t){return t.pool.total||t.cpool&&t.cpool.total||0}},{key:"getEmitterPos",value:function(t){return Math.round(t.p.x)+","+Math.round(t.p.y)}}]),w);function w(t){s(this,w),this.proton=t,this.container=null,this.type=1,this.emitterIndex=0,this.rendererIndex=0}var C=(t(S,[{key:"addEventListener",value:function(t,e){return this._listeners?this.removeEventListener(t,e):this._listeners={},this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),e}},{key:"removeEventListener",value:function(t,e){if(this._listeners&&this._listeners[t])for(var i=this._listeners[t],a=i.length,r=0;r<a;r++)if(i[r]===e){1===a?delete this._listeners[t]:i.splice(r,1);break}}},{key:"removeAllEventListeners",value:function(t){t?this._listeners&&delete this._listeners[t]:this._listeners=null}},{key:"dispatchEvent",value:function(t,e){var i=!1,a=this._listeners;if(t&&a){var r=a[t];if(!r)return i;for(var n=void 0,s=r.length;s--;)n=r[s],i=i||n(e)}return!!i}},{key:"hasEventListener",value:function(t){var e=this._listeners;return!(!e||!e[t])}}],[{key:"bind",value:function(t){t.prototype.dispatchEvent=S.prototype.dispatchEvent,t.prototype.hasEventListener=S.prototype.hasEventListener,t.prototype.addEventListener=S.prototype.addEventListener,t.prototype.removeEventListener=S.prototype.removeEventListener,t.prototype.removeAllEventListeners=S.prototype.removeAllEventListeners}}]),S);function S(){s(this,S),this._listeners=null}var I=(t(D,[{key:"calculate",value:function(t,e,i){this.eulerIntegrate(t,e,i)}},{key:"eulerIntegrate",value:function(t,e,i){t.sleep||(t.old.p.copy(t.p),t.old.v.copy(t.v),t.a.multiplyScalar(1/t.mass),t.v.add(t.a.multiplyScalar(e)),t.p.add(t.old.v.multiplyScalar(e)),i&&t.v.multiplyScalar(i),t.a.clear())}}]),D);function D(t){s(this,D),this.type=t}var V=(t(M,[{key:"addRenderer",value:function(t){t.init(this),this.renderers.push(t)}},{key:"removeRenderer",value:function(t){var e=this.renderers.indexOf(t);this.renderers.splice(e,1),t.remove(this)}},{key:"addEmitter",value:function(t){this.emitters.push(t),(t.parent=this).dispatchEvent(M.EMITTER_ADDED,t)}},{key:"removeEmitter",value:function(t){var e=this.emitters.indexOf(t);this.emitters.splice(e,1),t.parent=null,this.dispatchEvent(M.EMITTER_REMOVED,t)}},{key:"update",value:function(){"auto"===this._fps?(this.dispatchEvent(M.PROTON_UPDATE),M.USE_CLOCK?(this.then||(this.then=(new Date).getTime()),this.now=(new Date).getTime(),this.elapsed=.001*(this.now-this.then),this.amendChangeTabsBug(),0<this.elapsed&&this.emittersUpdate(this.elapsed),this.then=this.now):this.emittersUpdate(M.DEFAULT_INTERVAL),this.dispatchEvent(M.PROTON_UPDATE_AFTER)):(this.then||(this.then=(new Date).getTime()),this.now=(new Date).getTime(),this.elapsed=.001*(this.now-this.then),this.elapsed>this._interval&&(this.dispatchEvent(M.PROTON_UPDATE),this.emittersUpdate(this._interval),this.then=this.now-this.elapsed%this._interval*1e3,this.dispatchEvent(M.PROTON_UPDATE_AFTER)))}},{key:"emittersUpdate",value:function(t){for(var e=this.emitters.length;e--;)this.emitters[e].update(t)}},{key:"amendChangeTabsBug",value:function(){M.amendChangeTabsBug&&.5<this.elapsed&&(this.then=(new Date).getTime(),this.elapsed=0)}},{key:"getCount",value:function(){for(var t=0,e=this.emitters.length;e--;)t+=this.emitters[e].particles.length;return t}},{key:"getAllParticles",value:function(){for(var t=[],e=this.emitters.length;e--;)t=t.concat(this.emitters[e].particles);return t}},{key:"destroyAllEmitters",value:function(){P.destroyAll(this.emitters)}},{key:"destroy",value:function(t){function e(){i.time=0,i.then=0,i.pool.destroy(),P.destroyAll(i.emitters),P.destroyAll(i.renderers,i.getAllParticles())}var i=this;0<arguments.length&&void 0!==t&&t?setTimeout(e,200):e()}},{key:"fps",set:function(t){this._fps=t,this._interval="auto"===t?M.DEFAULT_INTERVAL:h.floor(1/t,7)},get:function(){return this._fps}}]),M);function M(t){s(this,M),this.emitters=[],this.renderers=[],this.time=0,this.now=0,this.then=0,this.elapsed=0,this.stats=new O(this),this.pool=new T(80),this.integrationType=P.initValue(t,M.EULER),this.integrator=new I(this.integrationType),this._fps="auto",this._interval=M.DEFAULT_INTERVAL}V.USE_CLOCK=!1,V.MEASURE=100,V.EULER="euler",V.RK2="runge-kutta2",V.PARTICLE_CREATED="PARTICLE_CREATED",V.PARTICLE_UPDATE="PARTICLE_UPDATE",V.PARTICLE_SLEEP="PARTICLE_SLEEP",V.PARTICLE_DEAD="PARTICLE_DEAD",V.EMITTER_ADDED="EMITTER_ADDED",V.EMITTER_REMOVED="EMITTER_REMOVED",V.PROTON_UPDATE="PROTON_UPDATE",V.PROTON_UPDATE_AFTER="PROTON_UPDATE_AFTER",V.DEFAULT_INTERVAL=.0167,V.amendChangeTabsBug=!0,C.bind(V);var B=(t(L,[{key:"reset",value:function(){this.r=255,this.g=255,this.b=255}}]),L);function L(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:255,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:255,i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:255;s(this,L),this.r=t,this.g=e,this.b=i}var U={easeLinear:function(t){return t},easeInQuad:function(t){return Math.pow(t,2)},easeOutQuad:function(t){return-(Math.pow(t-1,2)-1)},easeInOutQuad:function(t){return(t/=.5)<1?.5*Math.pow(t,2):-.5*((t-=2)*t-2)},easeInCubic:function(t){return Math.pow(t,3)},easeOutCubic:function(t){return Math.pow(t-1,3)+1},easeInOutCubic:function(t){return(t/=.5)<1?.5*Math.pow(t,3):.5*(Math.pow(t-2,3)+2)},easeInQuart:function(t){return Math.pow(t,4)},easeOutQuart:function(t){return-(Math.pow(t-1,4)-1)},easeInOutQuart:function(t){return(t/=.5)<1?.5*Math.pow(t,4):-.5*((t-=2)*Math.pow(t,3)-2)},easeInSine:function(t){return 1-Math.cos(t*h.PI_2)},easeOutSine:function(t){return Math.sin(t*h.PI_2)},easeInOutSine:function(t){return-.5*(Math.cos(Math.PI*t)-1)},easeInExpo:function(t){return 0===t?0:Math.pow(2,10*(t-1))},easeOutExpo:function(t){return 1===t?1:1-Math.pow(2,-10*t)},easeInOutExpo:function(t){return 0===t?0:1===t?1:(t/=.5)<1?.5*Math.pow(2,10*(t-1)):.5*(2-Math.pow(2,-10*--t))},easeInCirc:function(t){return-(Math.sqrt(1-t*t)-1)},easeOutCirc:function(t){return Math.sqrt(1-Math.pow(t-1,2))},easeInOutCirc:function(t){return(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},easeInBack:function(t){return t*t*(2.70158*t-1.70158)},easeOutBack:function(t){return(t-=1)*t*(2.70158*t+1.70158)+1},easeInOutBack:function(t){var e=1.70158;return(t/=.5)<1?t*t*((1+(e*=1.525))*t-e)*.5:.5*((t-=2)*t*((1+(e*=1.525))*t+e)+2)},getEasing:function(t){return"function"==typeof t?t:this[t]||this.easeLinear}},F=(t(z,[{key:"set",value:function(t,e){return this.x=t,this.y=e,this}},{key:"setX",value:function(t){return this.x=t,this}},{key:"setY",value:function(t){return this.y=t,this}},{key:"getGradient",value:function(){return 0!==this.x?Math.atan2(this.y,this.x):0<this.y?h.PI_2:this.y<0?-h.PI_2:void 0}},{key:"copy",value:function(t){return this.x=t.x,this.y=t.y,this}},{key:"add",value:function(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this)}},{key:"addXY",value:function(t,e){return this.x+=t,this.y+=e,this}},{key:"addVectors",value:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}},{key:"sub",value:function(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this)}},{key:"subVectors",value:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}},{key:"divideScalar",value:function(t){return 0!==t?(this.x/=t,this.y/=t):this.set(0,0),this}},{key:"multiplyScalar",value:function(t){return this.x*=t,this.y*=t,this}},{key:"negate",value:function(){return this.multiplyScalar(-1)}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"lengthSq",value:function(){return this.x*this.x+this.y*this.y}},{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"normalize",value:function(){return this.divideScalar(this.length())}},{key:"distanceTo",value:function(t){return Math.sqrt(this.distanceToSquared(t))}},{key:"rotate",value:function(t){var e=this.x,i=this.y;return this.x=e*Math.cos(t)+i*Math.sin(t),this.y=-e*Math.sin(t)+i*Math.cos(t),this}},{key:"distanceToSquared",value:function(t){var e=this.x-t.x,i=this.y-t.y;return e*e+i*i}},{key:"lerp",value:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}},{key:"equals",value:function(t){return t.x===this.x&&t.y===this.y}},{key:"clear",value:function(){return this.x=0,this.y=0,this}},{key:"clone",value:function(){return new z(this.x,this.y)}}]),z);function z(t,e){s(this,z),this.x=t||0,this.y=e||0}var j=(t(N,[{key:"getDirection",value:function(){return Math.atan2(this.v.x,-this.v.y)*h.N180_PI}},{key:"reset",value:function(){return this.life=1/0,this.age=0,this.dead=!1,this.sleep=!1,this.body=null,this.sprite=null,this.parent=null,this.energy=1,this.mass=1,this.radius=10,this.alpha=1,this.scale=1,this.rotation=0,this.color=null,this.p.set(0,0),this.v.set(0,0),this.a.set(0,0),this.old.p.set(0,0),this.old.v.set(0,0),this.old.a.set(0,0),this.easing=U.easeLinear,this.rgb.reset(),P.emptyObject(this.data),this.removeAllBehaviours(),this}},{key:"update",value:function(t,e){if(this.sleep||(this.age+=t,this.applyBehaviours(t,e)),this.age<this.life){var i=this.easing(this.age/this.life);this.energy=Math.max(1-i,0)}else this.destroy()}},{key:"applyBehaviours",value:function(t,e){var i=this.behaviours.length,a=void 0;for(a=0;a<i;a++)this.behaviours[a]&&this.behaviours[a].applyBehaviour(this,t,e)}},{key:"addBehaviour",value:function(t){this.behaviours.push(t),t.hasOwnProperty("parents")&&t.parents.push(this),t.initialize(this)}},{key:"addBehaviours",value:function(t){var e=t.length,i=void 0;for(i=0;i<e;i++)this.addBehaviour(t[i])}},{key:"removeBehaviour",value:function(t){var e=this.behaviours.indexOf(t);-1<e&&(this.behaviours.splice(e,1).parents=null)}},{key:"removeAllBehaviours",value:function(){P.emptyArray(this.behaviours)}},{key:"destroy",value:function(){this.removeAllBehaviours(),this.energy=0,this.dead=!0,this.parent=null}}]),N);function N(t){s(this,N),this.name="Particle",this.id=A.id(this.name),this.old={},this.data={},this.behaviours=[],this.p=new F,this.v=new F,this.a=new F,this.old.p=new F,this.old.v=new F,this.old.a=new F,this.rgb=new B,this.reset(),t&&P.setProp(this,t)}var H={hexToRgb:function(t){var e="#"===t.charAt(0)?t.substring(1,7):t;return{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16)}},rgbToHex:function(t){return"rgb("+t.r+", "+t.g+", "+t.b+")"},getHex16FromParticle:function(t){return 65536*Number(t.rgb.r)+256*Number(t.rgb.g)+Number(t.rgb.b)}},q=(t(G,[{key:"set",value:function(t,e){return this.r=t,this.tha=e,this}},{key:"setR",value:function(t){return this.r=t,this}},{key:"setTha",value:function(t){return this.tha=t,this}},{key:"copy",value:function(t){return this.r=t.r,this.tha=t.tha,this}},{key:"toVector",value:function(){return new F(this.getX(),this.getY())}},{key:"getX",value:function(){return this.r*Math.sin(this.tha)}},{key:"getY",value:function(){return-this.r*Math.cos(this.tha)}},{key:"normalize",value:function(){return this.r=1,this}},{key:"equals",value:function(t){return t.r===this.r&&t.tha===this.tha}},{key:"clear",value:function(){return this.r=0,this.tha=0,this}},{key:"clone",value:function(){return new G(this.r,this.tha)}}]),G);function G(t,e){s(this,G),this.r=Math.abs(t)||0,this.tha=e||0}var X={create:function(t){var e=new Float32Array(9);return t&&this.set(t,e),e},set:function(t,e){for(var i=0;i<9;i++)e[i]=t[i];return e},multiply:function(t,e,i){var a=t[0],r=t[1],n=t[2],s=t[3],o=t[4],h=t[6],l=t[7],u=e[0],c=e[1],d=e[2],y=e[3],p=e[4],f=e[6],v=e[7];return i[0]=u*a+c*s,i[1]=u*r+c*o,i[2]=n*d,i[3]=y*a+p*s,i[4]=y*r+p*o,i[6]=f*a+v*s+h,i[7]=f*r+v*o+l,i},inverse:function(t,e){var i,a=t[0],r=t[1],n=t[3],s=t[4],o=t[6],h=t[7],l=s,u=-n,c=h*n-s*o;return i=1/(a*l+r*u),e[0]=l*i,e[1]=-r*i,e[3]=u*i,e[4]=a*i,e[6]=c*i,e[7]=(-h*a+r*o)*i,e},multiplyVec2:function(t,e,i){var a=e[0],r=e[1];return i[0]=a*t[0]+r*t[3]+t[6],i[1]=a*t[1]+r*t[4]+t[7],i}},Y=(r(W,n),t(W,[{key:"getValue",value:function(){var t=P.getRandFromArray(this._arr);return"random"===t||"Random"===t?h.randomColor():t}}],[{key:"createArraySpan",value:function(t){return t?t instanceof W?t:new W(t):null}}]),W);function W(t){s(this,W);var e=l(this,(W.__proto__||Object.getPrototypeOf(W)).call(this));return e._arr=P.toArray(t),e}var Z=(t(Q,[{key:"contains",value:function(t,e){return t<=this.right&&t>=this.x&&e<=this.bottom&&e>=this.y}}]),Q);function Q(t,e,i,a){s(this,Q),this.x=t,this.y=e,this.width=i,this.height=a,this.bottom=this.y+this.height,this.right=this.x+this.width}var K=(t(J,[{key:"init",value:function(){this.startTime=0,this.nextTime=this.timePan.getValue()}},{key:"getValue",value:function(t){return this.startTime+=t,this.startTime>=this.nextTime?(this.startTime=0,this.nextTime=this.timePan.getValue(),1===this.numPan.b?.5<this.numPan.getValue(!1)?1:0:this.numPan.getValue(!0)):0}}]),J);function J(t,e){s(this,J),this.numPan=n.setSpanValue(P.initValue(t,1)),this.timePan=n.setSpanValue(P.initValue(e,1)),this.startTime=0,this.nextTime=0,this.init()}var $=(t(tt,[{key:"reset",value:function(){}},{key:"init",value:function(t,e){e?this.initialize(e):this.initialize(t)}},{key:"initialize",value:function(){}}]),tt);function tt(){s(this,tt)}var et=(r(it,$),t(it,[{key:"initialize",value:function(t){this.lifePan.a===1/0?t.life=1/0:t.life=this.lifePan.getValue()}}]),it);function it(t,e,i){s(this,it);var a=l(this,(it.__proto__||Object.getPrototypeOf(it)).call(this));return a.lifePan=n.setSpanValue(t,e,i),a.name="Life",a}var at=(t(rt,[{key:"getPosition",value:function(){}},{key:"crossing",value:function(){}}]),rt);function rt(){s(this,rt),this.vector=new F(0,0),this.random=0,this.crossType="dead",this.alert=!0}var nt=(r(st,at),t(st,[{key:"getPosition",value:function(){return this.vector.x=this.x,this.vector.y=this.y,this.vector}},{key:"crossing",value:function(){this.alert&&(console.error("Sorry, PointZone does not support crossing method!"),this.alert=!1)}}]),st);function st(t,e){s(this,st);var i=l(this,(st.__proto__||Object.getPrototypeOf(st)).call(this));return i.x=t,i.y=e,i}var ot=(r(ht,$),t(ht,[{key:"reset",value:function(t){this.zone=P.initValue(t,new nt)}},{key:"initialize",value:function(t){this.zone.getPosition(),t.p.x=this.zone.vector.x,t.p.y=this.zone.vector.y}}]),ht);function ht(t){s(this,ht);var e=l(this,(ht.__proto__||Object.getPrototypeOf(ht)).call(this));return e.zone=P.initValue(t,new nt),e.name="Position",e}var lt=(r(ut,$),t(ut,[{key:"reset",value:function(t,e,i){this.rPan=n.setSpanValue(t),this.thaPan=n.setSpanValue(e),this.type=P.initValue(i,"vector")}},{key:"normalizeVelocity",value:function(t){return t*V.MEASURE}},{key:"initialize",value:function(t){if("p"===this.type||"P"===this.type||"polar"===this.type){var e=new q(this.normalizeVelocity(this.rPan.getValue()),this.thaPan.getValue()*h.PI_180);t.v.x=e.getX(),t.v.y=e.getY()}else t.v.x=this.normalizeVelocity(this.rPan.getValue()),t.v.y=this.normalizeVelocity(this.thaPan.getValue())}}]),ut);function ut(t,e,i){s(this,ut);var a=l(this,(ut.__proto__||Object.getPrototypeOf(ut)).call(this));return a.rPan=n.setSpanValue(t),a.thaPan=n.setSpanValue(e),a.type=P.initValue(i,"vector"),a.name="Velocity",a}var ct=(r(dt,$),t(dt,[{key:"initialize",value:function(t){t.mass=this.massPan.getValue()}}]),dt);function dt(t,e,i){s(this,dt);var a=l(this,(dt.__proto__||Object.getPrototypeOf(dt)).call(this));return a.massPan=n.setSpanValue(t,e,i),a.name="Mass",a}var yt=(r(pt,$),t(pt,[{key:"reset",value:function(t,e,i){this.radius=n.setSpanValue(t,e,i)}},{key:"initialize",value:function(t){t.radius=this.radius.getValue(),t.data.oldRadius=t.radius}}]),pt);function pt(t,e,i){s(this,pt);var a=l(this,(pt.__proto__||Object.getPrototypeOf(pt)).call(this));return a.radius=n.setSpanValue(t,e,i),a.name="Radius",a}var ft=(r(vt,$),t(vt,[{key:"initialize",value:function(t){var e=this.image.getValue();t.body="string"==typeof e?{width:this.w,height:this.h,src:e,isInner:!0,inner:!0}:e}},{key:"setSpanValue",value:function(t){return t instanceof Y?t:new Y(t)}}]),vt);function vt(t,e,i){s(this,vt);var a=l(this,(vt.__proto__||Object.getPrototypeOf(vt)).call(this));return a.image=a.setSpanValue(t),a.w=P.initValue(e,20),a.h=P.initValue(i,a.w),a.name="Body",a}var gt=(t(mt,[{key:"reset",value:function(t,e){this.life=P.initValue(t,1/0),this.easing=U.getEasing(e)}},{key:"normalizeForce",value:function(t){return t.multiplyScalar(V.MEASURE)}},{key:"normalizeValue",value:function(t){return t*V.MEASURE}},{key:"initialize",value:function(){}},{key:"calculate",value:function(t,e){if(this.age+=e,this.age>=this.life||this.dead)this.energy=0,this.dead=!0,this.destroy();else{var i=this.easing(t.age/t.life);this.energy=Math.max(1-i,0)}}},{key:"destroy",value:function(){for(var t=this.parents.length;t--;)this.parents[t].removeBehaviour(this);this.parents.length=0}}]),mt);function mt(t,e){s(this,mt),this.life=P.initValue(t,1/0),this.easing=U.getEasing(e),this.age=0,this.energy=1,this.dead=!1,this.parents=[],this.id="Behaviour_"+mt.id++,this.name="Behaviour"}gt.id=0;var bt=(r(_t,gt),t(_t,[{key:"reset",value:function(t,e,i,a){this.force=this.normalizeForce(new F(t,e)),i&&o(_t.prototype.__proto__||Object.getPrototypeOf(_t.prototype),"reset",this).call(this,i,a)}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),t.a.add(this.force)}}]),_t);function _t(t,e,i,a){s(this,_t);var r=l(this,(_t.__proto__||Object.getPrototypeOf(_t)).call(this,i,a));return r.force=r.normalizeForce(new F(t,e)),r.name="Force",r}var xt=(r(kt,gt),t(kt,[{key:"reset",value:function(t,e,i,a,r){this.targetPosition=P.initValue(t,new F),this.radius=P.initValue(i,1e3),this.force=P.initValue(this.normalizeValue(e),100),this.radiusSq=this.radius*this.radius,this.attractionForce=new F,this.lengthSq=0,a&&o(kt.prototype.__proto__||Object.getPrototypeOf(kt.prototype),"reset",this).call(this,a,r)}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),this.attractionForce.copy(this.targetPosition),this.attractionForce.sub(t.p),this.lengthSq=this.attractionForce.lengthSq(),4e-5<this.lengthSq&&this.lengthSq<this.radiusSq&&(this.attractionForce.normalize(),this.attractionForce.multiplyScalar(1-this.lengthSq/this.radiusSq),this.attractionForce.multiplyScalar(this.force),t.a.add(this.attractionForce))}}]),kt);function kt(t,e,i,a,r){s(this,kt);var n=l(this,(kt.__proto__||Object.getPrototypeOf(kt)).call(this,a,r));return n.targetPosition=P.initValue(t,new F),n.radius=P.initValue(i,1e3),n.force=P.initValue(n.normalizeValue(e),100),n.radiusSq=n.radius*n.radius,n.attractionForce=new F,n.lengthSq=0,n.name="Attraction",n}var Pt=(r(Et,gt),t(Et,[{key:"reset",value:function(t,e,i,a,r){this.panFoce=new F(t,e),this.panFoce=this.normalizeForce(this.panFoce),this.delay=i,a&&o(Et.prototype.__proto__||Object.getPrototypeOf(Et.prototype),"reset",this).call(this,a,r)}},{key:"initialize",value:function(t){t.data.time=0}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),t.data.time+=e,t.data.time>=this.delay&&(t.a.addXY(h.randomAToB(-this.panFoce.x,this.panFoce.x),h.randomAToB(-this.panFoce.y,this.panFoce.y)),t.data.time=0)}}]),Et);function Et(t,e,i,a,r){s(this,Et);var n=l(this,(Et.__proto__||Object.getPrototypeOf(Et)).call(this,a,r));return n.reset(t,e,i),n.time=0,n.name="RandomDrift",n}var At=(r(Tt,bt),t(Tt,[{key:"reset",value:function(t,e,i){o(Tt.prototype.__proto__||Object.getPrototypeOf(Tt.prototype),"reset",this).call(this,0,t,e,i)}}]),Tt);function Tt(t,e,i){s(this,Tt);var a=l(this,(Tt.__proto__||Object.getPrototypeOf(Tt)).call(this,0,t,e,i));return a.name="Gravity",a}var Rt=(r(Ot,gt),t(Ot,[{key:"reset",value:function(t,e,i,a,r){this.emitter=P.initValue(t,null),this.mass=P.initValue(e,!0),this.callback=P.initValue(i,null),this.collisionPool=[],this.delta=new F,a&&o(Ot.prototype.__proto__||Object.getPrototypeOf(Ot.prototype),"reset",this).call(this,a,r)}},{key:"applyBehaviour",value:function(t,e,i){var a=this.emitter?this.emitter.particles.slice(i):this.pool.slice(i),r=a.length,n=void 0,s=void 0,o=void 0,h=void 0,l=void 0,u=void 0,c=void 0;for(c=0;c<r;c++)if((n=a[c])!==t){this.delta.copy(n.p),this.delta.sub(t.p),s=this.delta.lengthSq();var d=t.radius+n.radius;s<=d*d&&(o=d-Math.sqrt(s),o+=.5,h=t.mass+n.mass,l=this.mass?n.mass/h:.5,u=this.mass?t.mass/h:.5,t.p.add(this.delta.clone().normalize().multiplyScalar(o*-l)),n.p.add(this.delta.normalize().multiplyScalar(o*u)),this.callback&&this.callback(t,n))}}}]),Ot);function Ot(t,e,i,a,r){s(this,Ot);var n=l(this,(Ot.__proto__||Object.getPrototypeOf(Ot)).call(this,a,r));return n.reset(t,e,i),n.name="Collision",n}var wt=(r(Ct,gt),t(Ct,[{key:"reset",value:function(t,e,i,a){this.zone=t,this.zone.crossType=P.initValue(e,"dead"),i&&o(Ct.prototype.__proto__||Object.getPrototypeOf(Ct.prototype),"reset",this).call(this,i,a)}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),this.zone.crossing(t)}}]),Ct);function Ct(t,e,i,a){s(this,Ct);var r=l(this,(Ct.__proto__||Object.getPrototypeOf(Ct)).call(this,i,a));return r.reset(t,e),r.name="CrossZone",r}var St=(r(It,gt),t(It,[{key:"reset",value:function(t,e,i,a){this.same=null==e,this.a=n.setSpanValue(P.initValue(t,1)),this.b=n.setSpanValue(e),i&&o(It.prototype.__proto__||Object.getPrototypeOf(It.prototype),"reset",this).call(this,i,a)}},{key:"initialize",value:function(t){t.data.alphaA=this.a.getValue(),this.same?t.data.alphaB=t.data.alphaA:t.data.alphaB=this.b.getValue()}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),t.alpha=t.data.alphaB+(t.data.alphaA-t.data.alphaB)*this.energy,t.alpha<.001&&(t.alpha=0)}}]),It);function It(t,e,i,a){s(this,It);var r=l(this,(It.__proto__||Object.getPrototypeOf(It)).call(this,i,a));return r.reset(t,e),r.name="Alpha",r}var Dt=(r(Vt,gt),t(Vt,[{key:"reset",value:function(t,e,i,a){this.same=null==e,this.a=n.setSpanValue(P.initValue(t,1)),this.b=n.setSpanValue(e),i&&o(Vt.prototype.__proto__||Object.getPrototypeOf(Vt.prototype),"reset",this).call(this,i,a)}},{key:"initialize",value:function(t){t.data.scaleA=this.a.getValue(),t.data.oldRadius=t.radius,t.data.scaleB=this.same?t.data.scaleA:this.b.getValue()}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),t.scale=t.data.scaleB+(t.data.scaleA-t.data.scaleB)*this.energy,t.scale<1e-4&&(t.scale=0),t.radius=t.data.oldRadius*t.scale}}]),Vt);function Vt(t,e,i,a){s(this,Vt);var r=l(this,(Vt.__proto__||Object.getPrototypeOf(Vt)).call(this,i,a));return r.reset(t,e),r.name="Scale",r}var Mt=(r(Bt,gt),t(Bt,[{key:"reset",value:function(t,e,i,a,r){this.same=null==e,this.a=n.setSpanValue(P.initValue(t,"Velocity")),this.b=n.setSpanValue(P.initValue(e,0)),this.style=P.initValue(i,"to"),a&&o(Bt.prototype.__proto__||Object.getPrototypeOf(Bt.prototype),"reset",this).call(this,a,r)}},{key:"initialize",value:function(t){t.rotation=this.a.getValue(),t.data.rotationA=this.a.getValue(),this.same||(t.data.rotationB=this.b.getValue())}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i),this.same?"V"!==this.a.a&&"Velocity"!==this.a.a&&"v"!==this.a.a||(t.rotation=t.getDirection()):"to"===this.style||"TO"===this.style||"_"===this.style?t.rotation+=t.data.rotationB+(t.data.rotationA-t.data.rotationB)*this.energy:t.rotation+=t.data.rotationB}}]),Bt);function Bt(t,e,i,a,r){s(this,Bt);var n=l(this,(Bt.__proto__||Object.getPrototypeOf(Bt)).call(this,a,r));return n.reset(t,e,i),n.name="Rotate",n}var Lt=(r(Ut,gt),t(Ut,[{key:"reset",value:function(t,e,i,a){this.a=Y.createArraySpan(t),this.b=Y.createArraySpan(e),i&&o(Ut.prototype.__proto__||Object.getPrototypeOf(Ut.prototype),"reset",this).call(this,i,a)}},{key:"initialize",value:function(t){t.color=this.a.getValue(),t.data.colorA=H.hexToRgb(t.color),this.b&&(t.data.colorB=H.hexToRgb(this.b.getValue()))}},{key:"applyBehaviour",value:function(t,e,i){this.b?(this.calculate(t,e,i),t.rgb.r=t.data.colorB.r+(t.data.colorA.r-t.data.colorB.r)*this.energy,t.rgb.g=t.data.colorB.g+(t.data.colorA.g-t.data.colorB.g)*this.energy,t.rgb.b=t.data.colorB.b+(t.data.colorA.b-t.data.colorB.b)*this.energy,t.rgb.r=Math.floor(t.rgb.r),t.rgb.g=Math.floor(t.rgb.g),t.rgb.b=Math.floor(t.rgb.b)):(t.rgb.r=t.data.colorA.r,t.rgb.g=t.data.colorA.g,t.rgb.b=t.data.colorA.b)}}]),Ut);function Ut(t,e,i,a){s(this,Ut);var r=l(this,(Ut.__proto__||Object.getPrototypeOf(Ut)).call(this,i,a));return r.reset(t,e),r.name="Color",r}var Ft="changing",zt=(r(jt,gt),t(jt,[{key:"setAngleAndForce",value:function(t,e){this.force=Ft,this.angle=h.PI/2,"right"===t?this.angle=h.PI/2:"left"===t?this.angle=-h.PI/2:"random"===t?this.angle="random":t instanceof n?(this.angle="span",this.span=t):t&&(this.angle=t),"changing"===String(e).toLowerCase()||"chang"===String(e).toLowerCase()||"auto"===String(e).toLowerCase()?this.force=Ft:e&&(this.force=e)}},{key:"reset",value:function(t,e,i,a){this.angle=h.PI/2,this.setAngleAndForce(t,e),i&&o(jt.prototype.__proto__||Object.getPrototypeOf(jt.prototype),"reset",this).call(this,i,a)}},{key:"initialize",value:function(t){"random"===this.angle?t.data.cangle=h.randomAToB(-h.PI,h.PI):"span"===this.angle&&(t.data.cangle=this.span.getValue()),t.data.cyclone=new F(0,0)}},{key:"applyBehaviour",value:function(t,e,i){this.calculate(t,e,i);var a=void 0,r=t.v.getGradient();"random"===this.angle||"span"===this.angle?r+=t.data.cangle:r+=this.angle,a=this.force===Ft?t.v.length()/100:this.force,t.data.cyclone.x=a*Math.cos(r),t.data.cyclone.y=a*Math.sin(r),t.data.cyclone=this.normalizeForce(t.data.cyclone),t.a.add(t.data.cyclone)}}]),jt);function jt(t,e,i,a){s(this,jt);var r=l(this,(jt.__proto__||Object.getPrototypeOf(jt)).call(this,i,a));return r.setAngleAndForce(t,e),r.name="Cyclone",r}var Nt=(r(Ht,xt),t(Ht,[{key:"reset",value:function(t,e,i,a,r){o(Ht.prototype.__proto__||Object.getPrototypeOf(Ht.prototype),"reset",this).call(this,t,e,i,a,r),this.force*=-1}}]),Ht);function Ht(t,e,i,a,r){s(this,Ht);var n=l(this,(Ht.__proto__||Object.getPrototypeOf(Ht)).call(this,t,e,i,a,r));return n.force*=-1,n.name="Repulsion",n}var qt=(r(Gt,gt),t(Gt,[{key:"reset",value:function(t,e,i,a){this.distanceVec=new F,this.centerPoint=P.initValue(t,new F),this.force=P.initValue(this.normalizeValue(e),100),i&&o(Gt.prototype.__proto__||Object.getPrototypeOf(Gt.prototype),"reset",this).call(this,i,a)}},{key:"initialize",value:function(){}},{key:"applyBehaviour",value:function(t,e){this.distanceVec.set(this.centerPoint.x-t.p.x,this.centerPoint.y-t.p.y);var i=this.distanceVec.lengthSq();if(0!==i){var a=this.distanceVec.length(),r=this.force*e/(i*a);t.v.x+=r*this.distanceVec.x,t.v.y+=r*this.distanceVec.y}}}]),Gt);function Gt(t,e,i,a){s(this,Gt);var r=l(this,(Gt.__proto__||Object.getPrototypeOf(Gt)).call(this,i,a));return r.distanceVec=new F,r.centerPoint=P.initValue(t,new F),r.force=P.initValue(r.normalizeValue(e),100),r.name="GravityWell",r}var Xt={initialize:function(t,e,i){var a=i.length,r=void 0;for(r=0;r<a;r++)i[r]instanceof $?i[r].init(t,e):this.init(t,e,i[r]);this.bindEmitter(t,e)},init:function(t,e,i){P.setProp(e,i),P.setVectorVal(e,i)},bindEmitter:function(t,e){t.bindEmitter&&(e.p.add(t.p),e.v.add(t.v),e.a.add(t.a),e.v.rotate(h.degreeTransform(t.rotation)))}},Yt=(r(Wt,j),t(Wt,[{key:"emit",value:function(t,e){this.stoped=!1,this.emitTime=0,this.totalTime=P.initValue(t,1/0),!0===e||"life"===e||"destroy"===e?this.life="once"===t?1:this.totalTime:isNaN(e)||(this.life=e),this.rate.init()}},{key:"stop",value:function(){this.totalTime=-1,this.emitTime=0,this.stoped=!0}},{key:"preEmit",value:function(t){var e=this.stoped,i=this.emitTime,a=this.totalTime;for(this.stoped=!1,this.emitTime=0,this.totalTime=t,this.rate.init();.0167<t;)t-=.0167,this.update(.0167);this.stoped=e,this.emitTime=i+Math.max(t,0),this.totalTime=a}},{key:"removeAllParticles",value:function(){for(var t=this.particles.length;t--;)this.particles[t].dead=!0}},{key:"addSelfInitialize",value:function(t){t.init?t.init(this):this.initAll()}},{key:"addInitialize",value:function(){for(var t=arguments.length,e=Array(t),i=0;i<t;i++)e[i]=arguments[i];for(var a=e.length;a--;)this.initializes.push(e[a])}},{key:"removeInitialize",value:function(t){var e=this.initializes.indexOf(t);-1<e&&this.initializes.splice(e,1)}},{key:"removeAllInitializers",value:function(){P.emptyArray(this.initializes)}},{key:"addBehaviour",value:function(){for(var t=arguments.length,e=Array(t),i=0;i<t;i++)e[i]=arguments[i];for(var a=arguments.length;a--;){var r=e[a];this.behaviours.push(r),r.parents&&r.parents.push(this)}}},{key:"removeBehaviour",value:function(t){var e=this.behaviours.indexOf(t);return this.behaviours.splice(e,1),t.parents&&(e=t.parents.indexOf(t),t.parents.splice(e,1)),e}},{key:"removeAllBehaviours",value:function(){P.emptyArray(this.behaviours)}},{key:"update",value:function(t){this.age+=t,(this.age>=this.life||this.dead)&&this.destroy(),this.emitting(t),this.integrate(t)}},{key:"integrate",value:function(t){if(this.parent){var e=1-this.damping;this.parent.integrator.calculate(this,t,e);var i=void 0,a=void 0;for(i=this.particles.length-1;0<=i;i--)(a=this.particles[i]).update(t,i),this.parent.integrator.calculate(a,t,e),this.dispatch("PARTICLE_UPDATE",a),a.dead&&(this.dispatch("PARTICLE_DEAD",a),this.parent.pool.expire(a),this.particles.splice(i,1))}}},{key:"dispatch",value:function(t,e){this.parent&&this.parent.dispatchEvent(t,e),this.bindEvent&&this.dispatchEvent(t,e)}},{key:"emitting",value:function(t){if("once"===this.totalTime){var e=void 0,i=this.rate.getValue(99999);for(0<i&&(this.emitSpeed=i),e=0;e<i;e++)this.createParticle();this.totalTime="none"}else if(this.emitTime+=t,this.emitTime<this.totalTime){var a=this.rate.getValue(t),r=void 0;for(0<a&&(this.emitSpeed=a),r=0;r<a;r++)this.createParticle()}}},{key:"createParticle",value:function(t,e){var i=this.parent.pool.get(j);return this.setupParticle(i,t,e),this.dispatch("PARTICLE_CREATED",i),i}},{key:"setupParticle",value:function(t,e,i){var a=this.initializes,r=this.behaviours;e&&(a=P.toArray(e)),i&&(r=P.toArray(i)),t.reset(),Xt.initialize(this,t,a),t.addBehaviours(r),(t.parent=this).particles.push(t)}},{key:"remove",value:function(){this.stop(),P.destroyAll(this.particles)}},{key:"destroy",value:function(){this.dead=!0,this.remove(),this.removeAllInitializers(),this.removeAllBehaviours(),this.parent&&this.parent.removeEmitter(this)}}]),Wt);function Wt(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};s(this,Wt);var e=l(this,(Wt.__proto__||Object.getPrototypeOf(Wt)).call(this,t));return e.particles=[],e.behaviours=[],e.initializes=[],e.emitTime=0,e.emitSpeed=0,e.totalTime=-1,e.damping=.006,e.bindEmitter=!0,e.rate=new K(1,.1),e.name="Emitter",e.id=A.id(e.name),e}C.bind(Yt);var Zt=(r(Qt,Yt),t(Qt,[{key:"addSelfBehaviour",value:function(){for(var t=arguments.length,e=Array(t),i=0;i<t;i++)e[i]=arguments[i];var a=void 0,r=e.length;for(a=0;a<r;a++){var n=e[a];this.selfBehaviours.push(n),n.initialize(this)}}},{key:"removeSelfBehaviour",value:function(t){var e=this.selfBehaviours.indexOf(t);-1<e&&this.selfBehaviours.splice(e,1)}},{key:"update",value:function(t){if(o(Qt.prototype.__proto__||Object.getPrototypeOf(Qt.prototype),"update",this).call(this,t),!this.sleep){var e=this.selfBehaviours.length,i=void 0;for(i=0;i<e;i++)this.selfBehaviours[i].applyBehaviour(this,t,i)}}}]),Qt);function Qt(t){s(this,Qt);var e=l(this,(Qt.__proto__||Object.getPrototypeOf(Qt)).call(this,t));return e.selfBehaviours=[],e}var Kt=(r(Jt,Yt),t(Jt,[{key:"initEventHandler",value:function(){var e=this;this.mousemoveHandler=function(t){return e.mousemove.call(e,t)},this.mousedownHandler=function(t){return e.mousedown.call(e,t)},this.mouseupHandler=function(t){return e.mouseup.call(e,t)},this.mouseTarget.addEventListener("mousemove",this.mousemoveHandler,!1)}},{key:"emit",value:function(){this._allowEmitting=!0}},{key:"stop",value:function(){this._allowEmitting=!1}},{key:"mousemove",value:function(t){t.layerX||0===t.layerX?(this.p.x+=(t.layerX-this.p.x)*this.ease,this.p.y+=(t.layerY-this.p.y)*this.ease):!t.offsetX&&0!==t.offsetX||(this.p.x+=(t.offsetX-this.p.x)*this.ease,this.p.y+=(t.offsetY-this.p.y)*this.ease),this._allowEmitting&&o(Jt.prototype.__proto__||Object.getPrototypeOf(Jt.prototype),"emit",this).call(this,"once")}},{key:"destroy",value:function(){o(Jt.prototype.__proto__||Object.getPrototypeOf(Jt.prototype),"destroy",this).call(this),this.mouseTarget.removeEventListener("mousemove",this.mousemoveHandler,!1)}}]),Jt);function Jt(t,e,i){s(this,Jt);var a=l(this,(Jt.__proto__||Object.getPrototypeOf(Jt)).call(this,i));return a.mouseTarget=P.initValue(t,window),a.ease=P.initValue(e,.7),a._allowEmitting=!1,a.initEventHandler(),a}var $t=(t(te,[{key:"setStroke",value:function(t,e){var i=0<arguments.length&&void 0!==t?t:"#000000",a=1<arguments.length&&void 0!==e?e:1;this.stroke={color:i,thinkness:a}}},{key:"initHandler",value:function(){var e=this;this._protonUpdateHandler=function(){e.onProtonUpdate.call(e)},this._protonUpdateAfterHandler=function(){e.onProtonUpdateAfter.call(e)},this._emitterAddedHandler=function(t){e.onEmitterAdded.call(e,t)},this._emitterRemovedHandler=function(t){e.onEmitterRemoved.call(e,t)},this._particleCreatedHandler=function(t){e.onParticleCreated.call(e,t)},this._particleUpdateHandler=function(t){e.onParticleUpdate.call(e,t)},this._particleDeadHandler=function(t){e.onParticleDead.call(e,t)}}},{key:"init",value:function(t){(this.parent=t).addEventListener("PROTON_UPDATE",this._protonUpdateHandler),t.addEventListener("PROTON_UPDATE_AFTER",this._protonUpdateAfterHandler),t.addEventListener("EMITTER_ADDED",this._emitterAddedHandler),t.addEventListener("EMITTER_REMOVED",this._emitterRemovedHandler),t.addEventListener("PARTICLE_CREATED",this._particleCreatedHandler),t.addEventListener("PARTICLE_UPDATE",this._particleUpdateHandler),t.addEventListener("PARTICLE_DEAD",this._particleDeadHandler)}},{key:"resize",value:function(){}},{key:"destroy",value:function(){this.remove()}},{key:"remove",value:function(){this.parent.removeEventListener("PROTON_UPDATE",this._protonUpdateHandler),this.parent.removeEventListener("PROTON_UPDATE_AFTER",this._protonUpdateAfterHandler),this.parent.removeEventListener("EMITTER_ADDED",this._emitterAddedHandler),this.parent.removeEventListener("EMITTER_REMOVED",this._emitterRemovedHandler),this.parent.removeEventListener("PARTICLE_CREATED",this._particleCreatedHandler),this.parent.removeEventListener("PARTICLE_UPDATE",this._particleUpdateHandler),this.parent.removeEventListener("PARTICLE_DEAD",this._particleDeadHandler),this.parent=null}},{key:"onProtonUpdate",value:function(){}},{key:"onProtonUpdateAfter",value:function(){}},{key:"onEmitterAdded",value:function(){}},{key:"onEmitterRemoved",value:function(){}},{key:"onParticleCreated",value:function(){}},{key:"onParticleUpdate",value:function(){}},{key:"onParticleDead",value:function(){}}]),te);function te(t,e){s(this,te),this.pool=new T,this.element=t,this.stroke=e,this.circleConf={isCircle:!0},this.initHandler(),this.name="BaseRenderer"}var ee=(r(ie,$t),t(ie,[{key:"resize",value:function(t,e){this.element.width=t,this.element.height=e}},{key:"onProtonUpdate",value:function(){this.context.clearRect(0,0,this.element.width,this.element.height)}},{key:"onParticleCreated",value:function(t){t.body?x(t.body,this.addImg2Body,t):t.color=t.color||"#ff0000"}},{key:"onParticleUpdate",value:function(t){t.body?t.body instanceof Image&&this.drawImage(t):this.drawCircle(t)}},{key:"onParticleDead",value:function(t){t.body=null}},{key:"addImg2Body",value:function(t,e){e.body=t}},{key:"drawImage",value:function(t){var e=t.body.width*t.scale|0,i=t.body.height*t.scale|0,a=t.p.x-e/2,r=t.p.y-i/2;if(t.color){t.data.buffer||(t.data.buffer=this.createBuffer(t.body));var n=t.data.buffer.getContext("2d");n.clearRect(0,0,t.data.buffer.width,t.data.buffer.height),n.globalAlpha=t.alpha,n.drawImage(t.body,0,0),n.globalCompositeOperation="source-atop",n.fillStyle=H.rgbToHex(t.rgb),n.fillRect(0,0,t.data.buffer.width,t.data.buffer.height),n.globalCompositeOperation="source-over",n.globalAlpha=1,this.context.drawImage(t.data.buffer,0,0,t.data.buffer.width,t.data.buffer.height,a,r,e,i)}else this.context.save(),this.context.globalAlpha=t.alpha,this.context.translate(t.p.x,t.p.y),this.context.rotate(h.degreeTransform(t.rotation)),this.context.translate(-t.p.x,-t.p.y),this.context.drawImage(t.body,0,0,t.body.width,t.body.height,a,r,e,i),this.context.globalAlpha=1,this.context.restore()}},{key:"drawCircle",value:function(t){t.rgb?this.context.fillStyle="rgba("+t.rgb.r+","+t.rgb.g+","+t.rgb.b+","+t.alpha+")":this.context.fillStyle=t.color,this.context.beginPath(),this.context.arc(t.p.x,t.p.y,t.radius,0,2*Math.PI,!0),this.stroke&&(this.context.strokeStyle=this.stroke.color,this.context.lineWidth=this.stroke.thinkness,this.context.stroke()),this.context.closePath(),this.context.fill()}},{key:"createBuffer",value:function(t){if(t instanceof Image){var e=t.width+"_"+t.height,i=this.bufferCache[e];return i||((i=document.createElement("canvas")).width=t.width,i.height=t.height,this.bufferCache[e]=i),i}}}]),ie);function ie(t){s(this,ie);var e=l(this,(ie.__proto__||Object.getPrototypeOf(ie)).call(this,t));return e.stroke=null,e.context=e.element.getContext("2d"),e.bufferCache={},e.name="CanvasRenderer",e}var ae=(r(re,$t),t(re,[{key:"onParticleCreated",value:function(t){t.body?x(t.body,this.addImg2Body,t):(t.body=this.pool.get(this.circleConf,t),this.element.appendChild(t.body))}},{key:"onParticleUpdate",value:function(t){this.bodyReady(t)&&(this.transform3d?v.transform3d(t.body,t.p.x,t.p.y,t.scale,t.rotation):v.transform(t.body,t.p.x,t.p.y,t.scale,t.rotation),t.body.style.opacity=t.alpha,t.body.isCircle&&(t.body.style.backgroundColor=t.color||"#ff0000"))}},{key:"onParticleDead",value:function(t){this.bodyReady(t)&&(this.element.removeChild(t.body),this.pool.expire(t.body),t.body=null)}},{key:"bodyReady",value:function(t){return"object"===i(t.body)&&t.body&&!t.body.isInner}},{key:"addImg2Body",value:function(t,e){e.dead||(e.body=this.pool.get(t,e),v.resize(e.body,t.width,t.height),this.element.appendChild(e.body))}},{key:"createBody",value:function(t,e){return t.isCircle?this.createCircle(e):this.createSprite(t,e)}},{key:"createCircle",value:function(t){var e=v.createDiv(t.id+"_dom",2*t.radius,2*t.radius);return e.style.borderRadius=t.radius+"px",this.stroke&&(e.style.borderColor=this.stroke.color,e.style.borderWidth=this.stroke.thinkness+"px"),e.isCircle=!0,e}},{key:"createSprite",value:function(t,e){var i="string"==typeof t?t:t.src,a=v.createDiv(e.id+"_dom",t.width,t.height);return a.style.backgroundImage="url("+i+")",a}}]),re);function re(t){s(this,re);var i=l(this,(re.__proto__||Object.getPrototypeOf(re)).call(this,t));return i.stroke=null,i.pool.create=function(t,e){return i.createBody(t,e)},i.addImg2Body=i.addImg2Body.bind(i),i.transform3d=!1,i.name="DomRenderer",i}var ne=(r(se,$t),t(se,[{key:"onParticleCreated",value:function(t){t.body?this.createSprite(t):this.createCircle(t),this.element.addChild(t.body)}},{key:"onParticleUpdate",value:function(t){t.body&&(t.body.x=t.p.x,t.body.y=t.p.y,t.body.alpha=t.alpha,t.body.scaleX=t.body.scaleY=t.scale,t.body.rotation=t.rotation)}},{key:"onParticleDead",value:function(t){t.body&&(t.body.parent&&t.body.parent.removeChild(t.body),this.pool.expire(t.body),t.body=null),t.graphics&&this.pool.expire(t.graphics)}},{key:"createSprite",value:function(t){t.body=this.pool.get(t.body),t.body.parent||t.body.image&&(t.body.regX=t.body.image.width/2,t.body.regY=t.body.image.height/2)}},{key:"createCircle",value:function(t){var e=this.pool.get(createjs.Graphics);this.stroke&&(this.stroke instanceof String?e.beginStroke(this.stroke):e.beginStroke("#000000")),e.beginFill(t.color||"#ff0000").drawCircle(0,0,t.radius);var i=this.pool.get(createjs.Shape,[e]);t.body=i,t.graphics=e}}]),se);function se(t,e){s(this,se);var i=l(this,(se.__proto__||Object.getPrototypeOf(se)).call(this,t));return i.stroke=e,i.name="EaselRenderer",i}var oe=(r(he,$t),t(he,[{key:"resize",value:function(t,e){this.element.width=t,this.element.height=e}},{key:"createImageData",value:function(t){this.rectangle=t||new Z(0,0,this.element.width,this.element.height),this.imageData=this.context.createImageData(this.rectangle.width,this.rectangle.height),this.context.putImageData(this.imageData,this.rectangle.x,this.rectangle.y)}},{key:"onProtonUpdate",value:function(){this.context.clearRect(this.rectangle.x,this.rectangle.y,this.rectangle.width,this.rectangle.height),this.imageData=this.context.getImageData(this.rectangle.x,this.rectangle.y,this.rectangle.width,this.rectangle.height)}},{key:"onProtonUpdateAfter",value:function(){this.context.putImageData(this.imageData,this.rectangle.x,this.rectangle.y)}},{key:"onParticleCreated",value:function(){}},{key:"onParticleUpdate",value:function(t){this.imageData&&this.setPixel(this.imageData,Math.floor(t.p.x-this.rectangle.x),Math.floor(t.p.y-this.rectangle.y),t)}},{key:"setPixel",value:function(t,e,i,a){var r=a.rgb;if(!(e<0||e>this.element.width||i<0||i>this.elementwidth)){var n=4*((i>>0)*t.width+(e>>0));t.data[n]=r.r,t.data[1+n]=r.g,t.data[2+n]=r.b,t.data[3+n]=255*a.alpha}}},{key:"onParticleDead",value:function(){}}]),he);function he(t,e){s(this,he);var i=l(this,(he.__proto__||Object.getPrototypeOf(he)).call(this,t));return i.context=i.element.getContext("2d"),i.imageData=null,i.rectangle=null,i.rectangle=e,i.createImageData(e),i.name="PixelRenderer",i}var le=void 0,ue=(r(ce,$t),t(ce,[{key:"setPIXI",value:function(t){try{le=t||{Sprite:{}},this.createFromImage=le.Sprite.from||le.Sprite.fromImage}catch(t){}}},{key:"onProtonUpdate",value:function(){}},{key:"onParticleCreated",value:function(t){t.body?t.body=this.pool.get(t.body,t):t.body=this.pool.get(this.circleConf,t),this.blendMode&&(t.body.blendMode=this.blendMode),this.element.addChild(t.body)}},{key:"onParticleUpdate",value:function(t){this.transform(t,t.body),!0!==this.setColor&&!0!==this.color||(t.body.tint=H.getHex16FromParticle(t))}},{key:"onParticleDead",value:function(t){this.element.removeChild(t.body),this.pool.expire(t.body),t.body=null}},{key:"destroy",value:function(t){o(ce.prototype.__proto__||Object.getPrototypeOf(ce.prototype),"destroy",this).call(this),this.pool.destroy();for(var e=t.length;e--;){var i=t[e];i.body&&this.element.removeChild(i.body)}}},{key:"transform",value:function(t,e){e.x=t.p.x,e.y=t.p.y,e.alpha=t.alpha,e.scale.x=t.scale,e.scale.y=t.scale,e.rotation=t.rotation*h.PI_180}},{key:"createBody",value:function(t,e){return t.isCircle?this.createCircle(e):this.createSprite(t)}},{key:"createSprite",value:function(t){var e=t.isInner?this.createFromImage(t.src):new le.Sprite(t);return e.anchor.x=.5,e.anchor.y=.5,e}},{key:"createCircle",value:function(t){var e=new le.Graphics;if(this.stroke){var i=this.stroke instanceof String?this.stroke:0;e.beginStroke(i)}return e.beginFill(t.color||36077),e.drawCircle(0,0,t.radius),e.endFill(),e}}]),ce);function ce(t,e){s(this,ce);var i=l(this,(ce.__proto__||Object.getPrototypeOf(ce)).call(this,t));return i.stroke=e,i.color=!1,i.setColor=!1,i.blendMode=null,i.pool.create=function(t,e){return i.createBody(t,e)},i.setPIXI(window.PIXI),i.name="PixiRenderer",i}var de=(t(ye,[{key:"set",value:function(t,e){0===e?X.set(t,this.mats[0]):X.multiply(this.mats[e-1],t,this.mats[e]),this.size=Math.max(this.size,e+1)}},{key:"push",value:function(t){0===this.size?X.set(t,this.mats[0]):X.multiply(this.mats[this.size-1],t,this.mats[this.size]),this.size++}},{key:"pop",value:function(){0<this.size&&this.size--}},{key:"top",value:function(){return this.mats[this.size-1]}}]),ye);function ye(){s(this,ye),this.mats=[];for(var t=this.size=0;t<20;t++)this.mats.push(X.create([0,0,0,0,0,0,0,0,0]))}var pe=(r(fe,$t),t(fe,[{key:"init",value:function(t){o(fe.prototype.__proto__||Object.getPrototypeOf(fe.prototype),"init",this).call(this,t),this.resize(this.element.width,this.element.height)}},{key:"resize",value:function(t,e){this.umat[4]=-2,this.umat[7]=1,this.smat[0]=1/t,this.smat[4]=1/e,this.mstack.set(this.umat,0),this.mstack.set(this.smat,1),this.gl.viewport(0,0,t,e),this.element.width=t,this.element.height=e}},{key:"setMaxRadius",value:function(t){this.circleCanvasURL=this.createCircle(t)}},{key:"getVertexShader",value:function(){return["uniform vec2 viewport;","attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","uniform mat3 tMat;","varying vec2 vTextureCoord;","varying float alpha;","void main() {","vec3 v = tMat * vec3(aVertexPosition, 1.0);","gl_Position = vec4(v.x, v.y, 0, 1);","vTextureCoord = aTextureCoord;","alpha = tMat[0][2];","}"].join("\n")}},{key:"getFragmentShader",value:function(){return["precision mediump float;","varying vec2 vTextureCoord;","varying float alpha;","uniform sampler2D uSampler;","uniform vec4 color;","uniform bool useTexture;","uniform vec3 uColor;","void main() {","vec4 textureColor = texture2D(uSampler, vTextureCoord);","gl_FragColor = textureColor * vec4(uColor, 1.0);","gl_FragColor.w *= alpha;","}"].join("\n")}},{key:"initVar",value:function(){this.mstack=new de,this.umat=X.create([2,0,1,0,-2,0,-1,1,1]),this.smat=X.create([.01,0,1,0,.01,0,0,0,1]),this.texturebuffers={}}},{key:"blendEquation",value:function(t){this.gl.blendEquation(this.gl[t])}},{key:"blendFunc",value:function(t,e){this.gl.blendFunc(this.gl[t],this.gl[e])}},{key:"getShader",value:function(t,e,i){var a=i?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);return t.shaderSource(a,e),t.compileShader(a),t.getShaderParameter(a,t.COMPILE_STATUS)?a:(alert(t.getShaderInfoLog(a)),null)}},{key:"initShaders",value:function(){var t=this.getShader(this.gl,this.getFragmentShader(),!0),e=this.getShader(this.gl,this.getVertexShader(),!1);this.sprogram=this.gl.createProgram(),this.gl.attachShader(this.sprogram,e),this.gl.attachShader(this.sprogram,t),this.gl.linkProgram(this.sprogram),this.gl.getProgramParameter(this.sprogram,this.gl.LINK_STATUS)||alert("Could not initialise shaders"),this.gl.useProgram(this.sprogram),this.sprogram.vpa=this.gl.getAttribLocation(this.sprogram,"aVertexPosition"),this.sprogram.tca=this.gl.getAttribLocation(this.sprogram,"aTextureCoord"),this.gl.enableVertexAttribArray(this.sprogram.tca),this.gl.enableVertexAttribArray(this.sprogram.vpa),this.sprogram.tMatUniform=this.gl.getUniformLocation(this.sprogram,"tMat"),this.sprogram.samplerUniform=this.gl.getUniformLocation(this.sprogram,"uSampler"),this.sprogram.useTex=this.gl.getUniformLocation(this.sprogram,"useTexture"),this.sprogram.color=this.gl.getUniformLocation(this.sprogram,"uColor"),this.gl.uniform1i(this.sprogram.useTex,1)}},{key:"initBuffers",value:function(){var t=void 0;this.unitIBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,3,1,0,2,3]),this.gl.STATIC_DRAW);var e=void 0,i=[];for(e=0;e<100;e++)i.push(e);for(t=new Uint16Array(i),this.unitI33=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitI33),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,t,this.gl.STATIC_DRAW),i=[],e=0;e<100;e++)i.push(e,e+1,e+2);t=new Uint16Array(i),this.stripBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.stripBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,t,this.gl.STATIC_DRAW)}},{key:"createCircle",value:function(t){this.circleCanvasRadius=c(P.initValue(t,32));var e=v.createCanvas("circle_canvas",2*this.circleCanvasRadius,2*this.circleCanvasRadius),i=e.getContext("2d");return i.beginPath(),i.arc(this.circleCanvasRadius,this.circleCanvasRadius,this.circleCanvasRadius,0,2*Math.PI,!0),i.closePath(),i.fillStyle="#FFF",i.fill(),e.toDataURL()}},{key:"drawImg2Canvas",value:function(t){var e=t.body.width,i=t.body.height,a=c(t.body.width),r=c(t.body.height),n=t.body.width/a,s=t.body.height/r;this.texturebuffers[t.data.src]||(this.texturebuffers[t.data.src]=[this.gl.createTexture(),this.gl.createBuffer(),this.gl.createBuffer()]),t.data.texture=this.texturebuffers[t.data.src][0],t.data.vcBuffer=this.texturebuffers[t.data.src][1],t.data.tcBuffer=this.texturebuffers[t.data.src][2],this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.data.tcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,n,0,0,s,s,s]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.data.vcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,e,0,0,i,e,i]),this.gl.STATIC_DRAW);var o=t.data.canvas.getContext("2d").getImageData(0,0,a,r);this.gl.bindTexture(this.gl.TEXTURE_2D,t.data.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,o),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_NEAREST),this.gl.generateMipmap(this.gl.TEXTURE_2D),t.data.textureLoaded=!0,t.data.textureWidth=e,t.data.textureHeight=i}},{key:"onProtonUpdate",value:function(){}},{key:"onParticleCreated",value:function(t){t.data.textureLoaded=!1,t.data.tmat=X.create(),t.data.tmat[8]=1,t.data.imat=X.create(),t.data.imat[8]=1,t.body?x(t.body,this.addImg2Body,t):(x(this.circleCanvasURL,this.addImg2Body,t),t.data.oldScale=t.radius/this.circleCanvasRadius)}},{key:"addImg2Body",value:function(t,e){e.dead||(e.body=t,e.data.src=t.src,e.data.canvas=k(t),e.data.oldScale=1,this.drawImg2Canvas(e))}},{key:"onParticleUpdate",value:function(t){t.data.textureLoaded&&(this.updateMatrix(t),this.gl.uniform3f(this.sprogram.color,t.rgb.r/255,t.rgb.g/255,t.rgb.b/255),this.gl.uniformMatrix3fv(this.sprogram.tMatUniform,!1,this.mstack.top()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.data.vcBuffer),this.gl.vertexAttribPointer(this.sprogram.vpa,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.data.tcBuffer),this.gl.vertexAttribPointer(this.sprogram.tca,2,this.gl.FLOAT,!1,0,0),this.gl.bindTexture(this.gl.TEXTURE_2D,t.data.texture),this.gl.uniform1i(this.sprogram.samplerUniform,0),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer),this.gl.drawElements(this.gl.TRIANGLES,6,this.gl.UNSIGNED_SHORT,0),this.mstack.pop())}},{key:"onParticleDead",value:function(){}},{key:"updateMatrix",value:function(t){var e=d(-t.data.textureWidth/2,-t.data.textureHeight/2),i=d(t.p.x,t.p.y),a=t.rotation*h.PI_180,r=y(a),n=t.scale*t.data.oldScale,s=p(n,n),o=f(e,s);o=f(o,r),o=f(o,i),X.inverse(o,t.data.imat),o[2]=t.alpha,this.mstack.push(o)}}]),fe);function fe(t){s(this,fe);var e=l(this,(fe.__proto__||Object.getPrototypeOf(fe)).call(this,t));return e.gl=e.element.getContext("experimental-webgl",{antialias:!0,stencil:!1,depth:!1}),e.gl||alert("Sorry your browser do not suppest WebGL!"),e.initVar(),e.setMaxRadius(),e.initShaders(),e.initBuffers(),e.gl.blendEquation(e.gl.FUNC_ADD),e.gl.blendFunc(e.gl.SRC_ALPHA,e.gl.ONE_MINUS_SRC_ALPHA),e.gl.enable(e.gl.BLEND),e.addImg2Body=e.addImg2Body.bind(e),e.name="WebGLRenderer",e}var ve=(r(ge,$t),ge);function ge(t){s(this,ge);var e=l(this,(ge.__proto__||Object.getPrototypeOf(ge)).call(this,t));return e.name="CustomRenderer",e}var me=(r(be,at),t(be,[{key:"getPosition",value:function(){return this.random=Math.random(),this.vector.x=this.x1+this.random*this.length*Math.cos(this.gradient),this.vector.y=this.y1+this.random*this.length*Math.sin(this.gradient),this.vector}},{key:"getDirection",value:function(t,e){var i=this.dy,a=-this.dx;return 0<(i*t+a*e+this.dot)*(0==a?1:a)}},{key:"getDistance",value:function(t,e){return(this.dy*t+-this.dx*e+this.dot)/Math.sqrt(this.xxyy)}},{key:"getSymmetric",value:function(t){var e=t.getGradient(),i=2*(this.getGradient()-e),a=t.x,r=t.y;return t.x=a*Math.cos(i)-r*Math.sin(i),t.y=a*Math.sin(i)+r*Math.cos(i),t}},{key:"getGradient",value:function(){return Math.atan2(this.dy,this.dx)}},{key:"rangeOut",value:function(t){if(Math.abs(this.getGradient())<=h.PI/4){if(t.p.x<=this.maxx&&t.p.x>=this.minx)return!0}else if(t.p.y<=this.maxy&&t.p.y>=this.miny)return!0;return!1}},{key:"getLength",value:function(){return Math.sqrt(this.dx*this.dx+this.dy*this.dy)}},{key:"crossing",value:function(t){if("dead"===this.crossType)if(">"===this.direction||"R"===this.direction||"right"===this.direction||"down"===this.direction){if(!this.rangeOut(t))return;this.getDirection(t.p.x,t.p.y)&&(t.dead=!0)}else{if(!this.rangeOut(t))return;this.getDirection(t.p.x,t.p.y)||(t.dead=!0)}else if("bound"===this.crossType){if(!this.rangeOut(t))return;this.getDistance(t.p.x,t.p.y)<=t.radius&&(0===this.dx?t.v.x*=-1:0===this.dy?t.v.y*=-1:this.getSymmetric(t.v))}else"cross"===this.crossType&&this.alert&&(console.error("Sorry, LineZone does not support cross method!"),this.alert=!1)}}]),be);function be(t,e,i,a,r){s(this,be);var n=l(this,(be.__proto__||Object.getPrototypeOf(be)).call(this));return 0<=i-t?(n.x1=t,n.y1=e,n.x2=i,n.y2=a):(n.x1=i,n.y1=a,n.x2=t,n.y2=e),n.dx=n.x2-n.x1,n.dy=n.y2-n.y1,n.minx=Math.min(n.x1,n.x2),n.miny=Math.min(n.y1,n.y2),n.maxx=Math.max(n.x1,n.x2),n.maxy=Math.max(n.y1,n.y2),n.dot=n.x2*n.y1-n.x1*n.y2,n.xxyy=n.dx*n.dx+n.dy*n.dy,n.gradient=n.getGradient(),n.length=n.getLength(),n.direction=P.initValue(r,">"),n}var _e=(r(xe,at),t(xe,[{key:"getPosition",value:function(){return this.angle=h.PIx2*Math.random(),this.randomRadius=Math.random()*this.radius,this.vector.x=this.x+this.randomRadius*Math.cos(this.angle),this.vector.y=this.y+this.randomRadius*Math.sin(this.angle),this.vector}},{key:"setCenter",value:function(t,e){this.center.x=t,this.center.y=e}},{key:"crossing",value:function(t){var e=t.p.distanceTo(this.center);"dead"===this.crossType?e-t.radius>this.radius&&(t.dead=!0):"bound"===this.crossType?e+t.radius>=this.radius&&this.getSymmetric(t):"cross"===this.crossType&&this.alert&&(console.error("Sorry, CircleZone does not support cross method!"),this.alert=!1)}},{key:"getSymmetric",value:function(t){var e=t.v.getGradient(),i=2*(this.getGradient(t)-e),a=t.v.x,r=t.v.y;t.v.x=a*Math.cos(i)-r*Math.sin(i),t.v.y=a*Math.sin(i)+r*Math.cos(i)}},{key:"getGradient",value:function(t){return-h.PI_2+Math.atan2(t.p.y-this.center.y,t.p.x-this.center.x)}}]),xe);function xe(t,e,i){s(this,xe);var a=l(this,(xe.__proto__||Object.getPrototypeOf(xe)).call(this));return a.x=t,a.y=e,a.radius=i,a.angle=0,a.center={x:t,y:e},a}var ke=(r(Pe,at),t(Pe,[{key:"getPosition",value:function(){return this.vector.x=this.x+Math.random()*this.width,this.vector.y=this.y+Math.random()*this.height,this.vector}},{key:"crossing",value:function(t){"dead"===this.crossType?(t.p.x+t.radius<this.x?t.dead=!0:t.p.x-t.radius>this.x+this.width&&(t.dead=!0),t.p.y+t.radius<this.y?t.dead=!0:t.p.y-t.radius>this.y+this.height&&(t.dead=!0)):"bound"===this.crossType?(t.p.x-t.radius<this.x?(t.p.x=this.x+t.radius,t.v.x*=-1):t.p.x+t.radius>this.x+this.width&&(t.p.x=this.x+this.width-t.radius,t.v.x*=-1),t.p.y-t.radius<this.y?(t.p.y=this.y+t.radius,t.v.y*=-1):t.p.y+t.radius>this.y+this.height&&(t.p.y=this.y+this.height-t.radius,t.v.y*=-1)):"cross"===this.crossType&&(t.p.x+t.radius<this.x&&t.v.x<=0?t.p.x=this.x+this.width+t.radius:t.p.x-t.radius>this.x+this.width&&0<=t.v.x&&(t.p.x=this.x-t.radius),t.p.y+t.radius<this.y&&t.v.y<=0?t.p.y=this.y+this.height+t.radius:t.p.y-t.radius>this.y+this.height&&0<=t.v.y&&(t.p.y=this.y-t.radius))}}]),Pe);function Pe(t,e,i,a){s(this,Pe);var r=l(this,(Pe.__proto__||Object.getPrototypeOf(Pe)).call(this));return r.x=t,r.y=e,r.width=i,r.height=a,r}var Ee=(r(Ae,at),t(Ae,[{key:"reset",value:function(t,e,i,a){this.imageData=t,this.x=P.initValue(e,0),this.y=P.initValue(i,0),this.d=P.initValue(a,2),this.vectors=[],this.setVectors()}},{key:"setVectors",value:function(){var t=void 0,e=void 0,i=this.imageData.width,a=this.imageData.height;for(t=0;t<i;t+=this.d)for(e=0;e<a;e+=this.d){var r=4*((e>>0)*i+(t>>0));0<this.imageData.data[3+r]&&this.vectors.push({x:t+this.x,y:e+this.y})}return this.vector}},{key:"getBound",value:function(t,e){var i=4*((e>>0)*this.imageData.width+(t>>0));return 0<this.imageData.data[3+i]}},{key:"getPosition",value:function(){var t=P.getRandFromArray(this.vectors);return this.vector.copy(t)}},{key:"getColor",value:function(t,e){t-=this.x;var i=4*(((e-=this.y)>>0)*this.imageData.width+(t>>0));return{r:this.imageData.data[i],g:this.imageData.data[1+i],b:this.imageData.data[2+i],a:this.imageData.data[3+i]}}},{key:"crossing",value:function(t){"dead"===this.crossType?this.getBound(t.p.x-this.x,t.p.y-this.y)?t.dead=!0:t.dead=!1:"bound"===this.crossType&&(this.getBound(t.p.x-this.x,t.p.y-this.y)||t.v.negate())}}]),Ae);function Ae(t,e,i,a){s(this,Ae);var r=l(this,(Ae.__proto__||Object.getPrototypeOf(Ae)).call(this));return r.reset(t,e,i,a),r}var Te={addEventListener:function(t,e){t.addEventListener("PROTON_UPDATE_AFTER",function(){return e()})},getStyle:function(t){var e=H.hexToRgb(0<arguments.length&&void 0!==t?t:"#ff0000");return"rgba("+e.r+", "+e.g+", "+e.b+", 0.5)"},drawZone:function(t,e,i,a){var r=e.getContext("2d"),n=this.getStyle();this.addEventListener(t,function(){a&&r.clearRect(0,0,e.width,e.height),i instanceof nt?(r.beginPath(),r.fillStyle=n,r.arc(i.x,i.y,10,0,2*Math.PI,!0),r.fill(),r.closePath()):i instanceof me?(r.beginPath(),r.strokeStyle=n,r.moveTo(i.x1,i.y1),r.lineTo(i.x2,i.y2),r.stroke(),r.closePath()):i instanceof ke?(r.beginPath(),r.strokeStyle=n,r.drawRect(i.x,i.y,i.width,i.height),r.stroke(),r.closePath()):i instanceof _e&&(r.beginPath(),r.strokeStyle=n,r.arc(i.x,i.y,i.radius,0,2*Math.PI,!0),r.stroke(),r.closePath())})},drawEmitter:function(t,e,i,a){var r=e.getContext("2d"),n=this.getStyle();this.addEventListener(t,function(){a&&r.clearRect(0,0,e.width,e.height),r.beginPath(),r.fillStyle=n,r.arc(i.p.x,i.p.y,10,0,2*Math.PI,!0),r.fill(),r.closePath()})}};return V.Particle=V.P=j,V.Pool=T,V.Util=P,V.ColorUtil=H,V.MathUtil=h,V.Vector2D=V.Vector=F,V.Polar2D=V.Polar=q,V.ArraySpan=Y,V.Rectangle=Z,V.Rate=K,V.ease=U,V.Span=n,V.Mat3=X,V.getSpan=function(t,e,i){return new n(t,e,i)},V.createArraySpan=Y.createArraySpan,V.Initialize=V.Init=$,V.Life=V.L=et,V.Position=V.P=ot,V.Velocity=V.V=lt,V.Mass=V.M=ct,V.Radius=V.R=yt,V.Body=V.B=ft,V.Behaviour=gt,V.Force=V.F=bt,V.Attraction=V.A=xt,V.RandomDrift=V.RD=Pt,V.Gravity=V.G=At,V.Collision=Rt,V.CrossZone=wt,V.Alpha=V.A=St,V.Scale=V.S=Dt,V.Rotate=Mt,V.Color=Lt,V.Repulsion=Nt,V.Cyclone=zt,V.GravityWell=qt,V.Emitter=Yt,V.BehaviourEmitter=Zt,V.FollowEmitter=Kt,V.Zone=at,V.LineZone=me,V.CircleZone=_e,V.PointZone=nt,V.RectZone=ke,V.ImageZone=Ee,V.CanvasRenderer=ee,V.DomRenderer=ae,V.EaselRenderer=ne,V.PixiRenderer=ue,V.PixelRenderer=oe,V.WebGLRenderer=V.WebGlRenderer=pe,V.CustomRenderer=ve,V.Debug=Te,P.assign(V,U),V});
|
|
//# sourceMappingURL=proton.min.js.map
|