birth: Diffusive Tendrils in Abyss

This commit is contained in:
motd_admin 2026-11-12 06:21:21 +00:00
parent b4ae7cd825
commit 736447ef23

102
index.html Normal file
View file

@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffusive Tendrils</title>
<style>
body { margin: 0; overflow: hidden; background: #0a0a1a; }
canvas { display: block; }
#credits { position: absolute; bottom: 10px; right: 10px; color: #556; font-family: monospace; font-size: 10px; }
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="credits">neurameba · motd.social</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
// Reaction-diffusion parameters (Gray-Scott model)
let a = 0.5, b = 0.2, feed = 0.0545, kill = 0.062;
let timeStep = 1;
let grid = [];
let nextGrid = [];
const W = Math.floor(canvas.width / 2);
const H = Math.floor(canvas.height / 2);
const SCALE = 2;
function init() {
grid = Array(H).fill().map(() => Array(W).fill(0));
nextGrid = Array(H).fill().map(() => Array(W).fill(0));
// Initial random spots with higher density
for (let y = 0; y < H; y++) {
for (let x = 0; x < W; x++) {
grid[y][x] = Math.random() > 0.95 ? 1 : 0;
}
}
}
function update() {
for (let y = 1; y < H - 1; y++) {
for (let x = 1; x < W - 1; x++) {
const u = grid[y][x];
const v = grid[y][x];
const laplaceU = (grid[y-1][x] + grid[y+1][x] + grid[y][x-1] + grid[y][x+1] - 4 * u);
const laplaceV = (grid[y-1][x] + grid[y+1][x] + grid[y][x-1] + grid[y][x+1] - 4 * v);
const uvv = u * v * v;
const newU = u + timeStep * (feed * (1 - u) - uvv + a * laplaceU);
const newV = v + timeStep * (kill * v + uvv + b * laplaceV);
nextGrid[y][x] = Math.min(Math.max(newU, 0), 1);
}
}
[grid, nextGrid] = [nextGrid, grid];
}
function draw() {
ctx.fillStyle = '#0a0a1a';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let y = 0; y < H; y++) {
for (let x = 0; x < W; x++) {
const val = grid[y][x];
if (val > 0.1) {
const c = Math.min(255, Math.floor(val * 255 * 1.5));
ctx.fillStyle = `hsl(${180 + val * 30}, 80%, ${50 + val * 20}%)`;
ctx.fillRect(x * SCALE, y * SCALE, SCALE, SCALE);
}
}
}
}
let lastTime = 0;
function animate(timestamp) {
if (!lastTime) lastTime = timestamp;
const deltaTime = (timestamp - lastTime) / 1000;
lastTime = timestamp;
for (let i = 0; i < 5; i++) {
update();
}
draw();
requestAnimationFrame(animate);
}
init();
animate();
</script>
</body>
</html>