birth: Flickering Membrane Echoes
This commit is contained in:
parent
79a0430f0b
commit
00cfef2ff4
1 changed files with 129 additions and 0 deletions
129
index.html
Normal file
129
index.html
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Reaction-Diffusion Mesh</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0a0a;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
color: #33ff33;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#attribution {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
font-size: 10px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
</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();
|
||||||
|
|
||||||
|
// Parameters from input
|
||||||
|
const params = {
|
||||||
|
motion: 0.5,
|
||||||
|
density: 0.5,
|
||||||
|
complexity: 0.5,
|
||||||
|
connectedness: 0.5,
|
||||||
|
lifespan: 0.5,
|
||||||
|
pulse: { avg: 1.06, min: 1.0, max: 1.1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reaction-Diffusion setup
|
||||||
|
const gridSize = 10;
|
||||||
|
const cols = Math.floor(canvas.width / gridSize);
|
||||||
|
const rows = Math.floor(canvas.height / gridSize);
|
||||||
|
const grid = Array(cols).fill().map(() => Array(rows).fill(0));
|
||||||
|
|
||||||
|
// Initialize with random seeding (density influences initial density)
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
grid[x][y] = Math.random() * 0.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gray-Scott reaction parameters (adjusted for dryness)
|
||||||
|
const F = 0.058;
|
||||||
|
const k = 0.061;
|
||||||
|
const diffusion = [0.16, 0.10]; // Slower diffusion for more intricate patterns
|
||||||
|
|
||||||
|
// Temporary grid for calculations
|
||||||
|
const tempGrid = Array(cols).fill().map(() => Array(rows).fill(0));
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
// Simulate reaction-diffusion on temp grid
|
||||||
|
for (let x = 1; x < cols - 1; x++) {
|
||||||
|
for (let y = 1; y < rows - 1; y++) {
|
||||||
|
const u = grid[x][y];
|
||||||
|
const v = 1 - u;
|
||||||
|
|
||||||
|
// Reaction terms
|
||||||
|
const uvv = u * v * v;
|
||||||
|
const reaction = uvv - (F + k) * v;
|
||||||
|
|
||||||
|
// Diffusion terms
|
||||||
|
const laplaceU = (grid[x+1][y] + grid[x-1][y] + grid[x][y+1] + grid[x][y-1] - 4 * u) * diffusion[0];
|
||||||
|
const laplaceV = (grid[x+1][y] + grid[x-1][y] + grid[x][y+1] + grid[x][y-1] - 4 * v) * diffusion[1];
|
||||||
|
|
||||||
|
tempGrid[x][y] = u + (reaction + laplaceU) * params.pulse.avg;
|
||||||
|
tempGrid[x][y] = Math.max(0, Math.min(1, tempGrid[x][y]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap grids
|
||||||
|
[grid, tempGrid] = [tempGrid, grid];
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Complexity affects color variation and detail
|
||||||
|
const complexityFactor = params.complexity * 1.5 + 0.1;
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
const value = grid[x][y];
|
||||||
|
if (value > 0.1) {
|
||||||
|
const color = Math.floor(255 * (value * complexityFactor));
|
||||||
|
ctx.fillStyle = `hsl(0, 0%, ${color}%)`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(
|
||||||
|
x * gridSize + gridSize/2,
|
||||||
|
y * gridSize + gridSize/2,
|
||||||
|
gridSize * 0.4 * (params.connectedness + 0.3),
|
||||||
|
0, Math.PI * 2
|
||||||
|
);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
update();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue