HelioAI's picture
LFM3-1.7B inference modules: experimental release
67ebcef verified
Raw History Blame Contribute Delete
1.78 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fractal tree</title>
<style>html,body{margin:0;height:100%;overflow:hidden} body{background:linear-gradient(#e8f1f8,#f7f3e8)} canvas{display:block}</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
const W = canvas.width = innerWidth, H = canvas.height = innerHeight;
const DEPTH = 11;
// deterministic pseudo-random so the tree looks the same on every load
let seed = 7;
const rand = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
function lerp(a, b, t) { return a + (b - a) * t; }
function colour(level) { // brown trunk -> green tips
const t = level / DEPTH;
return `rgb(${Math.round(lerp(92, 70, t))}, ${Math.round(lerp(58, 160, t))}, ${Math.round(lerp(30, 60, t))})`;
}
function branch(x, y, len, angle, level) {
const x2 = x + Math.cos(angle) * len, y2 = y + Math.sin(angle) * len;
ctx.strokeStyle = colour(level);
ctx.lineWidth = Math.max(0.6, (DEPTH - level + 1) ** 1.45 * 0.55);
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x2, y2);
ctx.stroke();
if (level === DEPTH) {
ctx.fillStyle = `rgba(${90 + rand() * 60}, ${170 + rand() * 50}, 80, 0.55)`;
ctx.beginPath();
ctx.arc(x2, y2, 2.5 + rand() * 2.5, 0, Math.PI * 2);
ctx.fill();
return;
}
const spread = 0.32 + rand() * 0.18;
branch(x2, y2, len * (0.72 + rand() * 0.08), angle - spread, level + 1);
branch(x2, y2, len * (0.72 + rand() * 0.08), angle + spread, level + 1);
}
ctx.lineCap = 'round';
ctx.fillStyle = 'rgba(90,70,40,0.25)';
ctx.beginPath();
ctx.ellipse(W / 2, H - 24, 160, 14, 0, 0, Math.PI * 2);
ctx.fill();
branch(W / 2, H - 24, H * 0.2, -Math.PI / 2, 0);
</script>
</body>
</html>