forked from ShardulS18/FinalVersion-terminal-game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
54 lines (45 loc) · 1.26 KB
/
script2.js
File metadata and controls
54 lines (45 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// from below we have the logic for the cursor effects
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
document.body.appendChild(canvas);
canvas.width = window.innerWidth; // Optional: Resize to fit window
canvas.height = window.innerHeight; // Optional
function Particle(x, y) {
this.x = x;
this.y = y;
this.size = Math.random() * 15 + 1;
this.speedX = Math.random() * 2 - 1.5;
this.speedY = Math.random() * 2 - 1.5;
}
Particle.prototype.update = function () {
this.x += this.speedX;
this.y += this.speedY;
this.size *= 0.983;
};
Particle.prototype.draw = function () {
ctx.fillStyle = "#E5A75E"; // Fixed color
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
};
var particles = [];
canvas.addEventListener("mousemove", function (e) {
var xPos = e.x;
var yPos = e.y;
for (var i = 0; i < 5; i++) {
particles.push(new Particle(xPos, yPos));
}
});
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < particles.length; i++) {
particles[i].update();
particles[i].draw();
if (particles[i].size < 0.3) {
particles.splice(i, 1);
i--;
}
}
requestAnimationFrame(animateParticles);
}
animateParticles();