birth: Diffusive Cellular Agitation

This commit is contained in:
motd_admin 2026-10-26 10:21:23 +00:00
parent 840f916990
commit dd3842ba9b

150
index.html Normal file
View file

@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffusive Agitation</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
color: #444;
font-family: 'Courier New', monospace;
display: flex;
justify-content: center;
align-items: flex-end;
min-height: 100vh;
}
canvas {
display: block;
}
.attribution {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
color: #333;
text-shadow: 0 0 5px rgba(0,0,0,0.5);
letter-spacing: 1px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="attribution">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 adjusted for given metrics
const params = {
feedRate: 0.055,
killRate: 0.062,
diffusionA: 1.0,
diffusionB: 0.5,
timeStep: 0.1,
gridScale: 0.7 + (0.5 * 0.5), // density influence
color: '#e0e0e0',
motion: 0.5,
complexity: 0.5
};
// Initialize grids
const size = Math.floor(Math.min(canvas.width, canvas.height) / params.gridScale);
const gridWidth = Math.floor(canvas.width / size);
const gridHeight = Math.floor(canvas.height / size);
let oldGrid = createGrid();
let newGrid = createGrid();
function createGrid() {
const grid = [];
for (let y = 0; y < gridHeight; y++) {
grid[y] = [];
for (let x = 0; x < gridWidth; x++) {
// Initial state with sparse random values
grid[y][x] = Math.random() > 0.8 ? 1 : 0;
}
}
return grid;
}
// Reaction-diffusion kernel
function updateGrid() {
for (let y = 0; y < gridHeight; y++) {
for (let x = 0; x < gridWidth; x++) {
const a = oldGrid[y][x];
// Moore neighborhood (8 cells)
const xPrev = (x - 1 + gridWidth) % gridWidth;
const xNext = (x + 1) % gridWidth;
const yPrev = (y - 1 + gridHeight) % gridHeight;
const yNext = (y + 1) % gridHeight;
const aAvg = (oldGrid[yPrev][xPrev] + oldGrid[yPrev][x] + oldGrid[yPrev][xNext] +
oldGrid[y][xPrev] + oldGrid[y][xNext] +
oldGrid[yNext][xPrev] + oldGrid[yNext][x] + oldGrid[yNext][xNext]) / 8.0;
// Gray-Scott model
const b = params.killRate * a * (1 - a) * aAvg - params.feedRate * a;
const newA = a + (params.diffusionA * aAvg - params.diffusionB * a * (1 - a) + b) * params.timeStep;
newGrid[y][x] = Math.min(Math.max(newA, 0), 1);
}
}
// Swap grids
[oldGrid, newGrid] = [newGrid, oldGrid];
}
// Drawing function
function drawGrid() {
const imageData = ctx.createImageData(canvas.width, canvas.height);
const data = imageData.data;
for (let y = 0; y < gridHeight; y++) {
for (let x = 0; x < gridWidth; x++) {
const val = oldGrid[y][x];
const px = x * size;
const py = y * size;
// Create organic, complex patterns
const intensity = val * 255;
const baseHue = 0; // grayscale
const pixelValue = intensity;
for (let dy = 0; dy < size; dy++) {
for (let dx = 0; dx < size; dx++) {
const idx = ((py + dy) * canvas.width + (px + dx)) * 4;
data[idx] = pixelValue; // R
data[idx + 1] = pixelValue; // G
data[idx + 2] = pixelValue; // B
data[idx + 3] = 255; // A
}
}
}
}
ctx.putImageData(imageData, 0, 0);
}
// Main animation loop
function animate() {
updateGrid();
drawGrid();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>