UNPKG

jparticles

Version:

A succinct, efficient, and lightweight Canvas plugin library for building some cool particle effects.

1 lines 3.98 kB
+function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}(),r=JParticles,n=r.utils,s=r.Base,a=Math.random,f=(Math.abs,Math.PI),l=Math.sin,c=2*f,u=(n.pInt,n.limitRandom),h=(n.calcSpeed,n.scaleValue),p=n.randomColor,y=n.isArray,d=n.isPlainObject,v=n.isUndefined,b=n.resize,m=n.defineReadOnlyProperty,k=function(r){function n(i,o){return e(this,n),t(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,n,i,o))}return i(n,r),o(n,[{key:"version",get:function(){return"2.0.0"}}]),o(n,[{key:"init",value:function(){this.rippleLength=[],this.attrNormalize(),this.createDots(),this.draw()}},{key:"attrNormalize",value:function(){var e=this;["fill","fillColor","line","lineColor","lineWidth","offsetLeft","offsetTop","crestHeight","rippleNum","speed"].forEach(function(t){return e.attrProcessor(t)})}},{key:"attrProcessor",value:function(e){var t=this.set.num,i=this.set[e],o=i,r="offsetLeft"===e?this.cw:this.ch;for(y(i)||(o=this.set[e]=[]);t--;){var n=y(i)?i[t]:i;o[t]=v(n)?this.generateDefaultValue(e):this.scaleValue(e,n,r),"rippleNum"===e&&(this.rippleLength[t]=this.cw/o[t])}}},{key:"generateDefaultValue",value:function(e){var t=this.cw,i=this.ch;switch(e){case"lineColor":case"fillColor":e=p();break;case"lineWidth":e=u(2,.2);break;case"offsetLeft":e=a()*t;break;case"offsetTop":case"crestHeight":e=a()*i;break;case"rippleNum":e=u(t/2,1);break;case"speed":e=u(.4,.1);break;case"fill":e=!1;break;case"line":e=!0}return e}},{key:"scaleValue",value:function(e,t,i){return"offsetTop"===e||"offsetLeft"===e||"crestHeight"===e?h(t,i):t}},{key:"dynamicProcessor",value:function(e,t){var i=this,o="offsetLeft"===e?this.cw:this.ch,r=y(t);this.set[e].forEach(function(n,s,a){var f=r?t[s]:t;f=i.scaleValue(e,f,o),v(f)&&(f=n),a[s]=f})}},{key:"setOptions",value:function(e){if(this.set&&d(e))for(var t in e)"opacity"===t?this.set.opacity=e[t]:this.dynamicOptions.indexOf(t)!==-1&&this.dynamicProcessor(t,e[t])}},{key:"createDots",value:function(){for(var e=this.cw,t=this.rippleLength,i=this.set.num,o=this.dots=[];i--;)for(var r=o[i]=[],n=c/t[i],s=0;s<=e;s++)r.push({x:s,y:s*n})}},{key:"draw",value:function(){var e=this.cxt,t=this.cw,i=this.ch,o=this.paused,r=this.set,n=r.opacity;e.clearRect(0,0,t,i),e.globalAlpha=n,this.dots.forEach(function(n,s){var a=r.crestHeight[s],f=r.offsetLeft[s],c=r.offsetTop[s],u=r.speed[s];e.save(),e.beginPath(),n.forEach(function(t,i){e[i?"lineTo":"moveTo"](t.x,a*l(t.y+f)+c),!o&&(t.y-=u)}),r.fill[s]&&(e.lineTo(t,i),e.lineTo(0,i),e.closePath(),e.fillStyle=r.fillColor[s],e.fill()),r.line[s]&&(e.lineWidth=r.lineWidth[s],e.strokeStyle=r.lineColor[s],e.stroke()),e.restore()}),this.requestAnimationFrame()}},{key:"resize",value:function(){var e=this;b(this,function(t,i){["offsetLeft","offsetTop","crestHeight"].forEach(function(o){var r="offsetLeft"===o?t:i;e.set[o].forEach(function(e,t,i){i[t]=e*r})}),e.dots.forEach(function(e){e.forEach(function(e){e.x*=t,e.y*=i})})})}}]),n}(s);k.defaultConfig={num:3,fill:!1,fillColor:[],line:!0,lineColor:[],lineWidth:[],offsetLeft:[],offsetTop:[],crestHeight:[],rippleNum:[],speed:[]},k.prototype.dynamicOptions=["fill","fillColor","line","lineColor","lineWidth","offsetLeft","offsetTop","crestHeight","speed"],m(k,"wave")}();