HelioAI's picture
LFM3-1.7B inference modules: experimental release
67ebcef verified
Raw History Blame Contribute Delete
1.89 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bouncing balls</title>
<style>html,body{margin:0;height:100%;overflow:hidden;background:#0f1222} canvas{display:block}</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
let W, H;
function resize() { W = canvas.width = innerWidth; H = canvas.height = innerHeight; }
addEventListener('resize', resize);
resize();
const G = 900, RESTITUTION = 0.86, FRICTION = 0.995;
const balls = Array.from({ length: 20 }, (_, i) => {
const r = 12 + Math.random() * 22;
return { x: r + Math.random() * (W - 2 * r), y: r + Math.random() * H * 0.5, r,
vx: (Math.random() - 0.5) * 500, vy: (Math.random() - 0.5) * 300,
hue: Math.round(i * 360 / 20) };
});
let last = performance.now();
function step(now) {
const dt = Math.min(0.033, (now - last) / 1000);
last = now;
ctx.fillStyle = 'rgba(15,18,34,0.35)';
ctx.fillRect(0, 0, W, H);
for (const b of balls) {
b.vy += G * dt;
b.vx *= FRICTION;
b.x += b.vx * dt;
b.y += b.vy * dt;
if (b.x - b.r < 0) { b.x = b.r; b.vx = -b.vx * RESTITUTION; }
if (b.x + b.r > W) { b.x = W - b.r; b.vx = -b.vx * RESTITUTION; }
if (b.y - b.r < 0) { b.y = b.r; b.vy = -b.vy * RESTITUTION; }
if (b.y + b.r > H) {
b.y = H - b.r; b.vy = -b.vy * RESTITUTION;
if (Math.abs(b.vy) < 60) b.vy = -(500 + Math.random() * 400); // keep the scene alive
}
const g = ctx.createRadialGradient(b.x - b.r * 0.35, b.y - b.r * 0.35, b.r * 0.1, b.x, b.y, b.r);
g.addColorStop(0, `hsl(${b.hue} 90% 80%)`);
g.addColorStop(1, `hsl(${b.hue} 80% 50%)`);
ctx.beginPath();
ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
ctx.fillStyle = g;
ctx.fill();
}
requestAnimationFrame(step);
}
requestAnimationFrame(step);
</script>
</body>
</html>