-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.html
More file actions
68 lines (61 loc) · 1.93 KB
/
basic.html
File metadata and controls
68 lines (61 loc) · 1.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confetti Burst</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="confettiCanvas"></canvas>
<script>
const canvas = document.getElementById("confettiCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const colors = ["#ff6384", "#36a2eb", "#cc65fe", "#ffce56"];
const particles = [];
function createParticle() {
const x = Math.random() * canvas.width;
const y = canvas.height;
const size = Math.random() * 10 + 5;
const speed = Math.random() * 3 + 2;
const color = colors[Math.floor(Math.random() * colors.length)];
const angle = Math.random() * Math.PI * 2;
particles.push({ x, y, size, speed, color, angle });
}
function updateParticles() {
particles.forEach((p, index) => {
p.y -= p.speed;
p.x += Math.sin(p.angle);
p.size *= 0.99;
if (p.size < 1) particles.splice(index, 1);
});
}
function drawParticles() {
particles.forEach(p => {
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fill();
});
}
function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (particles.length < 300) createParticle();
updateParticles();
drawParticles();
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>