59 lines
1.4 KiB
HTML
Executable File
59 lines
1.4 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Boules :o</title>
|
|
<style>
|
|
body { margin: 0; overflow: hidden; background: black; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="canvas"></canvas>
|
|
<script>
|
|
const canvas = document.getElementById('canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
let balls = [];
|
|
|
|
canvas.addEventListener('click', e => {
|
|
balls.push({
|
|
x: e.clientX,
|
|
y: e.clientY,
|
|
vx: (Math.random() - 0.5) * 8,
|
|
vy: (Math.random() - 0.5) * 8,
|
|
radius: Math.random() * 20 + 10,
|
|
color: `hsl(${Math.random()*360}, 100%, 50%)`
|
|
});
|
|
});
|
|
|
|
function animate() {
|
|
ctx.fillStyle = 'rgba(0,0,0,0.3)';
|
|
ctx.fillRect(0,0,canvas.width,canvas.height);
|
|
|
|
balls.forEach(ball => {
|
|
ball.x += ball.vx;
|
|
ball.y += ball.vy;
|
|
|
|
if (ball.x < ball.radius || ball.x > canvas.width - ball.radius) ball.vx *= -1;
|
|
if (ball.y < ball.radius || ball.y > canvas.height - ball.radius) ball.vy *= -1;
|
|
|
|
ctx.beginPath();
|
|
ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI*2);
|
|
ctx.fillStyle = ball.color;
|
|
ctx.fill();
|
|
});
|
|
requestAnimationFrame(animate);
|
|
}
|
|
animate();
|
|
|
|
window.addEventListener('resize', () => {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|