diff --git a/build/_snowpack/optimize-manifest.json b/build/_snowpack/optimize-manifest.json index d5df8c9..59e709b 100644 --- a/build/_snowpack/optimize-manifest.json +++ b/build/_snowpack/optimize-manifest.json @@ -9,7 +9,7 @@ ], "js": [ "/basic/main.js", - "/src/Particles.js" + "/basic/Particles.js" ] }, "/index.html": { diff --git a/build/basic/Particles.js b/build/basic/Particles.js new file mode 100644 index 0000000..4c41688 --- /dev/null +++ b/build/basic/Particles.js @@ -0,0 +1 @@ +var d=class{constructor(t=0,i=0){this.x=t,this.y=i}static fromVector(t){return new d(t.x,t.y)}static fromArray(t){return new d(t[0],t[1])}set(t,i=t){return this.x=t,this.y=i,this}setToPolar(t,i=1){return this.x=Math.cos(t)*i,this.y=Math.sin(t)*i,this}equals(t){return this.x===t.x&&this.y===t.y}angle(){let t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t}setAngle(t){return this.setToPolar(t,this.length())}add(t){return this.x+=t.x,this.y+=t.y,this}subtract(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}divide(t){return this.x/=t.x,this.y/=t.y,this}scale(t){return isFinite(t)?(this.x*=t,this.y*=t):(this.x=0,this.y=0),this}negate(){return this.x=-this.x,this.y=-this.y,this}distance(t){let i=t.x-this.x,e=t.y-this.y;return Math.sqrt(i*i+e*e)}distanceSq(t){let i=t.x-this.x,e=t.y-this.y;return i*i+e*e}length(){let t=this.x,i=this.y;return Math.sqrt(t*t+i*i)}setLength(t){return this.normalize().scale(t)}lengthSq(){let t=this.x,i=this.y;return t*t+i*i}normalize(){let t=this.x,i=this.y,e=t*t+i*i;return e>0&&(e=1/Math.sqrt(e),this.x=t*e,this.y=i*e),this}normalizeRightHand(){let t=this.x;return this.x=this.y*-1,this.y=t,this}normalizeLeftHand(){let t=this.x;return this.x=this.y,this.y=t*-1,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lerp(t,i=0){let e=this.x,s=this.y;return this.x=e+i*(t.x-e),this.y=s+i*(t.y-s),this}reset(){return this.x=0,this.y=0,this}limit(t){let i=this.length();return i&&i>t&&this.scale(t/i),this}reflect(t){return t=d.fromVector(t).normalize(),this.subtract(t.scale(2*this.dot(t)))}mirror(t){return this.reflect(t).negate()}rotate(t){let i=Math.cos(t),e=Math.sin(t);return this.set(i*this.x-e*this.y,e*this.x+i*this.y)}toPolar(){return{p:Math.sqrt(this.x*this.x+this.y*this.y),q:Math.atan2(this.y,this.x)}}},n=d,y=class{constructor(t=new n,i=new n){this.a=t,this.b=i}length(){return Math.sqrt((this.b.x-this.a.x)*(this.b.x-this.a.x)+(this.b.y-this.a.y)*(this.b.y-this.a.y))}},_=y,g=class{static intBetween(t,i){return i||(i=t,t=0),Math.floor(Math.random()*(i-t)+t)}static floatBetween(t,i){return i||(i=t,t=0),Math.random()*(i-t)+t}static fromArray(t){return t[Math.floor(Math.random()*t.length)]}static indexFromArray(t){return Math.floor(Math.random()*t.length)}},l=g,x=class{constructor(){this.position=new n,this.velocity=new n,this.active=!0,this.letter,this.radius=1}},f=class{constructor(t){this.particles=new Array(t),this.init(0,t)}createParticle(){let t=new x;return this.particles.push(t),t}init(t,i){for(let e=t;eBoolean(e.letter)),i=this.particles.filter(e=>!Boolean(e.letter));this._ctx.fillStyle="rgba(255,255,255,0.7)",this._ctx.font="30px monospace";for(let e of t)this._ctx.fillText(e.letter,e.position.x-8,e.position.y+10);this._ctx.fillStyle="rgba(255,255,255,0.5)",this._ctx.beginPath();for(let e of i)this._ctx.moveTo(e.position.x,e.position.y),this._ctx.arc(e.position.x,e.position.y,e.radius,0,Math.PI*2);this._ctx.fill();for(let e of this.lines)this._ctx.beginPath(),this._ctx.strokeStyle=`rgba(255,255,255,${e.alpha})`,this._ctx.moveTo(e.a.x,e.a.y),this._ctx.lineTo(e.b.x,e.b.y),this._ctx.stroke();this._debug&&this.drawPerformanceGraphic()}drawCircle(t,i,e,s,r){t.fillStyle=r,t.beginPath(),t.arc(i,e,s,0,Math.PI*2),t.fill()}drawPerformanceGraphic(){var t;let i=this.deltas.filter(o=>Boolean(o)),e=Math.min(...i),s=Math.max(...i);this._ctx.font="16px monospace",this._ctx.strokeStyle="#fff",this._ctx.beginPath();let r=0,h=70;this._ctx.moveTo(r,h-this.deltas[0]);for(let o of this.deltas){let u=h-o/s*50;this._ctx.lineTo(r,u),r++}this._ctx.moveTo(0,h),this._ctx.lineTo(this.deltas.length,h),this._ctx.fillText("0",this.deltas.length,h+4),this._ctx.moveTo(0,h-50),this._ctx.lineTo(this.deltas.length,h-50),this._ctx.fillText(s,this.deltas.length,h-50+4),this._ctx.closePath(),this._ctx.stroke(),this._ctx.fillStyle="#fff",this._ctx.fillText(`${(t=this.deltas[this.deltas.length-1])==null?void 0:t.toString()} ms (${e}-${s})`,100,15),this._ctx.fillText(`${this.particles.length.toString()} part`,0,15)}},m=w,b=class{constructor(t=0,i=0,e=0,s=0){this.position=new n(t,i),this.size=new n(e,s)}get left(){return this.position.x}set left(t){t>=this.right?this.size.x=0:this.size.x=this.right-t,this.position.x=t}get right(){return this.position.x+this.size.x}set right(t){t<=this.position.x?this.size.x=0:this.size.x=t-this.position.x}get top(){return this.position.y}set top(t){t>=this.bottom?this.size.y=0:this.size.y=this.bottom-t,this.position.y=t}get bottom(){return this.position.y+this.size.y}set bottom(t){t<=this.position.y?this.size.y=0:this.size.y=t-this.position.y}get center(){return new n(this.position.x+this.size.x/2,this.position.y+this.size.y/2)}set center({x:t,y:i}){this.x=t-this.size.x/2,this.y=i-this.size.y/2}set(t,i,e,s){this.position.set(t,i),this.size.set(e,s)}contains(t){return t.x>=this.left&&t.x<=this.right&&t.y>=this.top&&t.y<=this.bottom}intersectsCircle(t){return!(t.position.x+t.radius<=this.left&&t.position.x+t.radius>=this.right&&t.position.y+t.radius<=this.top&&t.position.y+t.radius>=this.bottom)}},a=b,c=class{constructor(t,i){this.rectangle=t,this.capacity=i,this.points=[],this.divided=!1,this.northEast,this.northWest,this.southEast,this.southWest}subdivide(){let t=this.rectangle.position.x,i=this.rectangle.position.y,e=this.rectangle.size.x,s=this.rectangle.size.y,r=this.capacity;this.northEast=new c(new a(t,i,e/2,s/2),r),this.northWest=new c(new a(t+e/2,i,e/2,s/2),r),this.southEast=new c(new a(t,i+s/2,e/2,s/2),r),this.southWest=new c(new a(t+e/2,i+s/2,e/2,s/2),r),this.divided=!0}insert(t){var i;return this.rectangle.contains(t.position)?this.points.lengththis.setSize(window.innerWidth,window.innerHeight),100)}start(){this._isRunning=!0,window.requestAnimationFrame(this._boundUpdate)}stop(){this._isRunning=!1}update(){let t=Date.now();this._quadtree=new p(this._boundary,4);let i=this._particleManager.particles.filter(h=>h.active);for(let h of i)h.position.x+=h.velocity.x,h.position.y+=h.velocity.y,this.checkBoundary(h,this._boundary),this._quadtree.insert(h);let e;this._linkedParticles&&(e=this.linkPartiles(this._particleManager.particles,this._distanceToLink)),this._renderer.particles=this._particleManager.particles,this._renderer.lines=e,this._renderer.deltas=this._deltas,this._renderer.render(),this._isRunning&&window.requestAnimationFrame(this._boundUpdate),this._ticks++;let s=Date.now()-t;this._deltas.push(s),this._deltas.length>this._deltas.length-1&&this._deltas.shift();let r=this._deltas.filter(h=>h!==void 0)}linkPartiles(t,i){let e=[];for(let s=0;si.right&&(t.position.x=i.left),t.position.yi.bottom&&(t.position.y=i.top)}},v=z;export{v as default}; diff --git a/build/basic/index.html b/build/basic/index.html index db0b341..7c01b12 100644 --- a/build/basic/index.html +++ b/build/basic/index.html @@ -1 +1 @@ -Basic \ No newline at end of file +Basic \ No newline at end of file diff --git a/build/basic/main.js b/build/basic/main.js index b2bcf73..933d70c 100644 --- a/build/basic/main.js +++ b/build/basic/main.js @@ -1 +1 @@ -import e from"../src/Particles.js";const r=document.getElementById("particles"),t=new e(r,{debug:!0,resize:!0,particles:{amount:250,color:"#fff",createStrategy:"random",distanceToLink:150,linkedParticles:!0,maxVelocity:.8,maxRadius:4},staticParticles:[],renderer:{transparentBackground:!1,backgroundColor:"#186cb6",linearGradient:{x1:0,y1:0,x2:1,y2:1,color1:"#327fc2",color2:"#014987"},width:window.innerWidth,height:window.innerHeight}});window.particles=t; +import e from"./Particles.js";const r=document.getElementById("particles"),t=new e(r,{debug:!0,resize:!0,particles:{amount:250,color:"#fff",createStrategy:"random",distanceToLink:150,linkedParticles:!0,maxVelocity:.8,maxRadius:4},renderer:{transparentBackground:!1,backgroundColor:"#186cb6",linearGradient:{x1:0,y1:0,x2:1,y2:1,color1:"#327fc2",color2:"#014987"},width:window.innerWidth,height:window.innerHeight}});window.particles=t; diff --git a/build/src/README.md b/build/src/README.md index 92fb0be..3bcf00e 100644 --- a/build/src/README.md +++ b/build/src/README.md @@ -1,16 +1,20 @@ # Spark Particles -![version](https://img.shields.io/npm/v/spark-particles) -![license](https://img.shields.io/npm/l/spark-particles) -![language](https://img.shields.io/github/languages/top/gelltorn/particles) -![issues](https://img.shields.io/github/issues/gelltorn/particles) -![npm downloads](https://img.shields.io/npm/dt/spark-particles) +![version](https://img.shields.io/npm/v/spark-particles?style=for-the-badge) +![license](https://img.shields.io/npm/l/spark-particles?style=for-the-badge) +![language](https://img.shields.io/github/languages/top/gelltorn/particles?style=for-the-badge) +![issues](https://img.shields.io/github/issues/gelltorn/particles?style=for-the-badge) +![npm downloads](https://img.shields.io/npm/dt/spark-particles?style=for-the-badge) +![npm min bundle size](https://img.shields.io/bundlephobia/min/spark-particles?style=for-the-badge) +![npm minzip bundle size](https://img.shields.io/bundlephobia/minzip/spark-particles?style=for-the-badge) Lightweight and fast Particle library written in JavaScript +Zero Dependencies! + [Examples](https://gelltorn.github.io/particles/examples/) ## Installation -1. `npm i spark-particles` +1. `npm i spark-particles --save` 2. Done! ## Usage See Basic example @@ -31,12 +35,6 @@ const particles = new Particles(node, { maxVelocity: 0.8, // number maxRadius: 4 // number }, - staticParticles: [ - [0.4, 0.4], - [0.6, 0.4], - [0.4, 0.6], - [0.6, 0.6], - ], renderer: { transparentBackground: false, // boolean backgroundColor: "#186cb6", // color diff --git a/build/src/package.json b/build/src/package.json index e42b8d1..af7d6fa 100644 --- a/build/src/package.json +++ b/build/src/package.json @@ -1,6 +1,6 @@ { "name": "spark-particles", - "version": "0.2.0", + "version": "0.2.1", "description": "Lightweight and fast Particle library written in JavaScript", "main": "./Particles.js", "scripts": {