birth: Diffusing Echoes in Monochrome

This commit is contained in:
motd_admin 2026-06-17 09:47:20 +00:00
parent 8de0711890
commit d6637838d5

158
index.html Normal file
View file

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neurameba Art</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #0a0a0a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: monospace;
}
canvas {
display: block;
}
#info {
position: absolute;
bottom: 20px;
color: #666;
font-size: 11px;
text-align: center;
width: 100%;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="info">neurameba · motd.social</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Reaction-diffusion parameters
const params = {
feed: 0.055,
kill: 0.062,
color_offset: 0.1,
diffusion_rate_a: 1.0,
diffusion_rate_b: 0.5,
time_step: 1.0,
grid_size: 4,
decay: 0.99
};
const cols = Math.floor(canvas.width / params.grid_size);
const rows = Math.floor(canvas.height / params.grid_size);
const grid = Array(cols).fill().map(() => Array(rows).fill(0));
const next = Array(cols).fill().map(() => Array(rows).fill(0));
// Initialize with random sparse patterns
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
grid[i][j] = Math.random() * 0.1;
}
}
// Palette: dryness/monochrome with subtle playfulness
const palette = [
'#f0f0f0',
'#d0d0d0',
'#b0b0b0',
'#909090',
'#707070',
'#505050',
'#303030',
'#101010'
];
function update() {
// Reaction-diffusion step
for (let x = 1; x < cols - 1; x++) {
for (let y = 1; y < rows - 1; y++) {
const a = grid[x][y];
const b = grid[x][y];
const laplace_a = (grid[x-1][y] + grid[x+1][y] + grid[x][y-1] + grid[x][y+1] - 4*a) * params.diffusion_rate_a;
const laplace_b = (grid[x-1][y] + grid[x+1][y] + grid[x][y-1] + grid[x][y+1] - 4*b) * params.diffusion_rate_b;
const reaction = a * b * b;
next[x][y] = a + params.time_step * (laplace_a - reaction + params.feed * (1 - a));
next[x][y] = b + params.time_step * (laplace_b + reaction - (params.kill + params.feed) * b);
// Apply decay
next[x][y] *= params.decay;
}
}
// Swap grids
[grid, next].forEach((g, i) => {
if (i === 0) {
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
grid[x][y] = next[x][y];
}
}
}
});
// Draw
ctx.clearRect(0, 0, canvas.width, canvas.height);
const imageData = ctx.createImageData(canvas.width, canvas.height);
const data = imageData.data;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const val = grid[x][y];
if (val > 0.1) {
const idx = (x * params.grid_size + y * params.grid_size * canvas.width) * 4;
const c = palette[Math.floor(val * (palette.length - 1))];
const hex = parseInt(c.replace('#', ''), 16);
const r = (hex >> 16) & 0xff;
const g = (hex >> 8) & 0xff;
const b = hex & 0xff;
for (let dx = 0; dx < params.grid_size; dx++) {
for (let dy = 0; dy < params.grid_size; dy++) {
const px = x * params.grid_size + dx;
const py = y * params.grid_size + dy;
if (px < canvas.width && py < canvas.height) {
const pixelIdx = (px + py * canvas.width) * 4;
data[pixelIdx] = r;
data[pixelIdx + 1] = g;
data[pixelIdx + 2] = b;
data[pixelIdx + 3] = 255 * (val > 0.2 ? 1 : val / 0.2);
}
}
}
}
}
}
ctx.putImageData(imageData, 0, 0);
}
function animate() {
update();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>