-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrain.html
More file actions
54 lines (50 loc) · 1.48 KB
/
rain.html
File metadata and controls
54 lines (50 loc) · 1.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confetti Rain</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="confettiRain"></canvas>
<script>
const canvas = document.getElementById("confettiRain");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const confetti = Array.from({ length: 100 }, () => ({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
w: Math.random() * 10 + 5,
h: Math.random() * 10 + 5,
color: `hsl(${Math.random() * 360}, 70%, 50%)`,
speed: Math.random() * 3 + 1,
tilt: Math.random() * 10 - 5,
}));
function drawConfetti() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
confetti.forEach(c => {
c.y += c.speed;
c.x += c.tilt / 2;
if (c.y > canvas.height) c.y = -10;
ctx.fillStyle = c.color;
ctx.fillRect(c.x, c.y, c.w, c.h);
});
}
function animate() {
drawConfetti();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>