-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.min.js
2 lines (2 loc) · 3.86 KB
/
bundle.min.js
1
2
!function t(i,s,e){function a(r,n){if(!s[r]){if(!i[r]){var o="function"==typeof require&&require;if(!n&&o)return o(r,!0);if(h)return h(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var l=s[r]={exports:{}};i[r][0].call(l.exports,function(t){var s=i[r][1][t];return a(s?s:t)},l,l.exports,t,i,s,e)}return s[r].exports}for(var h="function"==typeof require&&require,r=0;r<e.length;r++)a(e[r]);return a}({"/Users/jonasschmitt/dev/labs/source/scripts/main.js":[function(t,i,s){"use strict";t("./particles")},{"./particles":"/Users/jonasschmitt/dev/labs/source/scripts/particles.js"}],"/Users/jonasschmitt/dev/labs/source/scripts/particles.js":[function(t,i,s){"use strict";function e(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}var a,h=function(){function t(t,i){for(var s=0;s<i.length;s++){var e=i[s];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(i,s,e){return s&&t(i.prototype,s),e&&t(i,e),i}}(),r=function(){function t(){e(this,t),this.opts={width:4e3,height:2600,particleCount:150,sizes:[3,4,6],colors:["#90c53f","#47848f","#920e04","#50e3c2","#F5A623","#b8e986"]},this.active=!0,this.particles=[],this.canvas=document.querySelector(".particles"),this.ctx=this.canvas.getContext("2d"),this.canvas.width=this.opts.width,this.canvas.height=this.opts.height,this.initializeParticles(),this.drawParticles(),requestAnimationFrame(this.animateParticles.bind(this))}return h(t,[{key:"initializeParticles",value:function(){for(var t=this.opts.particleCount-1;t>=0;t--){var i=new n(this.ctx,this.opts);this.particles.push(i)}}},{key:"drawParticles",value:function(){for(var t=this.opts.particleCount-1;t>=0;t--){var i=this.particles[t];i.draw()}}},{key:"updateParticles",value:function(){for(var t=this.particles.length-1;t>=0;t--){var i=this.particles[t];i.move(),i.boundaryCheck()}}},{key:"clearCanvas",value:function(){this.ctx.clearRect(0,0,this.opts.width,this.opts.height)}},{key:"activate",value:function(){this.active=!0,this.animateParticles()}},{key:"deactivate",value:function(){this.active=!1}},{key:"destroy",value:function(){var t=this;this.deactivate(),setTimeout(function(){t.clearCanvas()},100)}},{key:"animateParticles",value:function(){this.clearCanvas(),this.drawParticles(),this.updateParticles(),this.active&&requestAnimationFrame(this.animateParticles.bind(this))}},{key:"updateBoundaries",value:function(){for(var t=0;t<this.particles.length;t++)this.particles[t].opts.width=this.opts.width,this.particles[t].opts.height=this.opts.height}}]),t}(),n=function(){function t(i,s){e(this,t),this.ctx=i,this.opts=s;var a=Math.floor(Math.random()*s.colors.length),h=Math.floor(Math.random()*s.sizes.length);this.color=s.colors[a],this.size=s.sizes[h],console.log(this.color,this.size),this.x=Math.random()*this.opts.width,this.y=Math.random()*this.opts.height,this.vx=.01*(2*Math.random()+4)*this.size,this.vy=.01*(2*Math.random()+4)*this.size,this.direction={x:-1*Math.random()*2,y:-1*Math.random()*2}}return h(t,[{key:"move",value:function(){this.x+=this.vx*this.direction.x,this.y+=this.vy*this.direction.y}},{key:"draw",value:function(){this.ctx.save(),this.ctx.beginPath(),this.ctx.translate(this.x,this.y),this.ctx.fillStyle=this.color,this.ctx.arc(0,0,this.size,0,2*Math.PI,!1),this.ctx.fill(),this.ctx.restore()}},{key:"changeDirection",value:function(t){this.direction[t]*=-1}},{key:"boundaryCheck",value:function(){this.x>=1.2*this.opts.width?(this.x=1.2*this.opts.width,this.changeDirection("x")):this.x<=.2*-this.opts.width&&(this.x=.2*-this.opts.width,this.changeDirection("x")),this.y>=1.2*this.opts.height?(this.y=1.2*this.opts.height,this.changeDirection("y")):this.y<=.2*-this.opts.height&&(this.y=.2*-this.opts.height,this.changeDirection("y"))}}]),t}();a=new r},{}]},{},["/Users/jonasschmitt/dev/labs/source/scripts/main.js"]);
//# sourceMappingURL=bundle.min.js.map