-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (70 loc) · 2.3 KB
/
Copy pathscript.js
File metadata and controls
82 lines (70 loc) · 2.3 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const canvas = document.getElementById('luxury-particles');
const ctx = canvas.getContext('2d');
let particlesArray;
// Set canvas size to full screen
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
// Very slow, subtle movement
this.directionX = (Math.random() * 0.4) - 0.2;
this.directionY = (Math.random() * 0.4) - 0.2;
// Small, varied sizes
this.size = (Math.random() * 2) + 0.1;
// Gold/Amber luxury colors with varying opacity
const colors = ['rgba(253, 216, 53, ', 'rgba(255, 193, 7, ', 'rgba(255, 255, 255, '];
const randomColorStr = colors[Math.floor(Math.random() * colors.length)];
this.color = randomColorStr + (Math.random() * 0.4 + 0.1) + ')';
}
// Method to draw individual particle
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
ctx.fillStyle = this.color;
ctx.fill();
}
// Method to check particle position, move the particle, draw the particle
update() {
// Check if particle is still within canvas
if (this.x > canvas.width || this.x < 0) {
this.directionX = -this.directionX;
}
if (this.y > canvas.height || this.y < 0) {
this.directionY = -this.directionY;
}
// Move particle
this.x += this.directionX;
this.y += this.directionY;
// Draw particle
this.draw();
}
}
// Create particle array
function init() {
particlesArray = [];
// Adjust number of particles based on screen size for performance
let numberOfParticles = (canvas.height * canvas.width) / 15000;
for (let i = 0; i < numberOfParticles; i++) {
particlesArray.push(new Particle());
}
}
// Animation loop
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, innerWidth, innerHeight);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
}
}
// Resize event
window.addEventListener('resize',
function() {
canvas.width = innerWidth;
canvas.height = innerHeight;
init();
}
);
init();
animate();