-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (53 loc) · 2.1 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', () => {
const canvas = document.getElementById('backgroundCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let angleOffset = 0;
function drawBinaryTree(x, y, size, angle, depth) {
if (depth === 0) return;
const x1 = x + size * Math.cos(angle);
const y1 = y + size * Math.sin(angle);
ctx.strokeStyle = '#0ff';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x1, y1);
ctx.stroke();
const newSize = size * (0.7 + 0.05 * Math.sin(angleOffset));
drawBinaryTree(x1, y1, newSize, angle - Math.PI / 6, depth - 1);
drawBinaryTree(x1, y1, newSize, angle + Math.PI / 6, depth - 1);
}
function drawParticles() {
const particles = [];
for (let i = 0; i < 100; i++) {
particles.push({
x: Math.random() * canvas.width,
y: canvas.height + Math.random() * 50, // Start from just below the canvas
radius: Math.random() * 2,
speed: Math.random() * 0.5 + 0.5
});
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBinaryTree(canvas.width / 2, canvas.height, canvas.height / 4, -Math.PI / 2, 10);
particles.forEach(particle => {
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2, false);
ctx.fillStyle = '#0ff';
ctx.fill();
particle.y -= particle.speed;
if (particle.y < 0) particle.y = canvas.height; // Reset to bottom if it goes above the canvas
});
angleOffset += 0.03;
requestAnimationFrame(animateParticles);
}
animateParticles();
}
drawParticles();
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
drawParticles();
});
});