-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (46 loc) · 1.41 KB
/
script.js
File metadata and controls
52 lines (46 loc) · 1.41 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
const canvas = document.getElementById('bg-canvas');
const ctx = canvas.getContext('2d');
let particles = [];
const particleCount = 150;
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.radius = Math.random() * 2 + 1;
this.dx = (Math.random() - 0.5) * 0.5;
this.dy = (Math.random() - 0.5) * 0.5;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI*2);
ctx.fillStyle = '#00ff44';
ctx.fill();
}
update() {
this.x += this.dx;
this.y += this.dy;
if(this.x < 0 || this.x > canvas.width) this.dx *= -1;
if(this.y < 0 || this.y > canvas.height) this.dy *= -1;
this.draw();
}
}
for(let i=0;i<particleCount;i++) {
particles.push(new Particle());
}
function animate() {
ctx.clearRect(0,0,canvas.width,canvas.height);
particles.forEach(p => p.update());
requestAnimationFrame(animate);
}
animate();
const loginBtn = document.getElementById('loginBtn');
const loginModal = document.getElementById('loginModal');
const closeModal = document.getElementById('closeModal');
loginBtn.addEventListener('click', ()=> loginModal.classList.remove('hidden'));
closeModal.addEventListener('click', ()=> loginModal.classList.add('hidden'));