birth: Flowing Patterns in Stillness

This commit is contained in:
motd_admin 2026-08-30 10:21:20 +00:00
parent 81327e8bec
commit 38442ee716

159
index.html Normal file
View file

@ -0,0 +1,159 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffusion Currents</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
color: #444;
font-size: 10px;
pointer-events: none;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="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();
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.07, min: 1.0, max: 1.1 },
tone: { curiosity: 0.7, dryness: 0.8, playfulness: 0.3 }
};
const gridSize = 64;
const cellSize = Math.min(canvas.width, canvas.height) / gridSize;
const cols = Math.ceil(canvas.width / cellSize);
const rows = Math.ceil(canvas.height / cellSize);
let currentGrid = createGrid();
let nextGrid = createGrid();
function createGrid() {
const grid = [];
for (let y = 0; y < rows; y++) {
grid.push([]);
for (let x = 0; x < cols; x++) {
grid[y][x] = {
a: Math.random(),
b: Math.random(),
energy: 0
};
}
}
return grid;
}
function updateGrid() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const cell = currentGrid[y][x];
const neighbors = getNeighbors(x, y);
let sumA = 0, sumB = 0, sumEnergy = 0;
for (const neighbor of neighbors) {
sumA += neighbor.a;
sumB += neighbor.b;
sumEnergy += neighbor.energy;
}
const count = neighbors.length;
const avgA = sumA / count;
const avgB = sumB / count;
// Reaction-diffusion equations (Gray-Scott variant)
const f = 0.055;
const k = 0.062;
const da = 1.0;
const db = 0.5;
cell.a += da * (cell.a * cell.b * cell.b - cell.a - f * (cell.a + cell.b));
cell.b += db * (cell.a * cell.b * cell.b + f * (cell.a + cell.b) - (k + 1) * cell.b);
cell.energy = (cell.a + cell.b) * 0.5;
nextGrid[y][x] = cell;
}
}
[currentGrid, nextGrid] = [nextGrid, currentGrid];
}
function getNeighbors(x, y) {
const neighbors = [];
for (let ny = -1; ny <= 1; ny++) {
for (let nx = -1; nx <= 1; nx++) {
if (nx === 0 && ny === 0) continue;
const nx2 = (x + nx + cols) % cols;
const ny2 = (y + ny + rows) % rows;
neighbors.push(currentGrid[ny2][nx2]);
}
}
return neighbors;
}
function draw() {
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const pulseFactor = params.pulse.avg * (params.motion * 0.5 + 0.5);
const dryness = params.tone.dryness;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const cell = currentGrid[y][x];
const energy = cell.energy * pulseFactor;
const threshold = 0.3;
if (energy > threshold) {
const intensity = Math.min(1, (energy - threshold) / (1 - threshold));
// Monochromatic palette with variable brightness
const value = dryness > 0.7 ? Math.floor(50 + intensity * 50) : 255;
ctx.fillStyle = `rgb(${value}, ${value}, ${value})`;
ctx.fillRect(
x * cellSize,
y * cellSize,
cellSize * 0.9,
cellSize * 0.9
);
}
}
}
updateGrid();
requestAnimationFrame(draw);
}
draw();
</script>
</body>
</html>