MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / update

Method update

assets/js/bubbleParticle.js:76–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74
75}
76update(){
77 let dx=mouse.x-this.x;
78 let dy=mouse.y-this.y;
79 let distance=Math.sqrt(dx*dx +dy*dy);
80 this.distance=distance;
81 let forceDirectionX=dx/distance;
82 let forceDirectionY=dy/distance;
83 let maxDistance=mouse.radius;
84 let force=(maxDistance-distance)/maxDistance;
85 let directionX=forceDirectionX * force * this.density;
86 let directionY=forceDirectionY * force * this.density;
87
88 if(distance<mouse.radius){
89 this.x-=directionX;
90 this.y-=directionY;
91
92 }
93 else{
94 if(this.x!==this.baseX){
95 let dx=this.x-this.baseX;
96 this.x-=dx/10;
97 }
98 if(this.y!==this.baseY){
99 let dy=this.y-this.baseY;
100 this.y-=dy/10;
101 }
102 }
103}
104
105}
106

Callers 1

animateFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected