167 lines
No EOL
5.4 KiB
HTML
167 lines
No EOL
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Microbial Echoes</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 20px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
color: #444;
|
|
font-size: 12px;
|
|
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');
|
|
|
|
// Set canvas to full window size
|
|
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.07, min: 1.0, max: 1.1 },
|
|
tone: { dryness: 0.9 }
|
|
};
|
|
|
|
// Reaction-diffusion parameters (Gray-Scott model)
|
|
const D_U = 0.16; // Diffusion rate for U
|
|
const D_V = 0.08; // Diffusion rate for V
|
|
const feed = 0.055 + params.density * 0.02; // Feed rate
|
|
const kill = 0.062 + params.complexity * 0.02; // Kill rate
|
|
const dt = 1.0;
|
|
|
|
// Grid setup
|
|
const gridSize = 4;
|
|
const cols = Math.floor(canvas.width / gridSize);
|
|
const rows = Math.floor(canvas.height / gridSize);
|
|
const totalCells = cols * rows;
|
|
|
|
// Create grids
|
|
let u = new Array(totalCells).fill(0);
|
|
let v = new Array(totalCells).fill(0);
|
|
let nextU = new Array(totalCells).fill(0);
|
|
let nextV = new Array(totalCells).fill(0);
|
|
|
|
// Initialize
|
|
function init() {
|
|
for (let i = 0; i < totalCells; i++) {
|
|
// Sparse random initialization
|
|
u[i] = 1.0;
|
|
v[i] = 0.0;
|
|
if (Math.random() > 0.9) {
|
|
u[i] = 0.0;
|
|
v[i] = 1.0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Gray-Scott reaction-diffusion step
|
|
function update() {
|
|
// Adjust feed/kill based on pulse
|
|
const pulseFactor = params.pulse.avg;
|
|
const adjustedFeed = feed * pulseFactor;
|
|
const adjustedKill = kill * pulseFactor;
|
|
|
|
for (let i = 0; i < cols; i++) {
|
|
for (let j = 0; j < rows; j++) {
|
|
const idx = i + j * cols;
|
|
|
|
// Get neighbors (toroidal boundary)
|
|
const idxL = ((i - 1 + cols) % cols) + j * cols;
|
|
const idxR = ((i + 1) % cols) + j * cols;
|
|
const idxT = i + ((j - 1 + rows) % rows) * cols;
|
|
const idxB = i + ((j + 1) % rows) * cols;
|
|
|
|
// Compute Laplacian (5-point stencil)
|
|
const lapU = u[idxL] + u[idxR] + u[idxT] + u[idxB] - 4 * u[idx];
|
|
const lapV = v[idxL] + v[idxR] + v[idxT] + v[idxB] - 4 * v[idx];
|
|
|
|
// Reaction terms
|
|
const du = adjustedFeed * u[idx] * v[idx] * v[idx] - adjustedKill * u[idx] + D_U * lapU;
|
|
const dv = -adjustedFeed * u[idx] * v[idx] * v[idx] + adjustedKill * u[idx] + D_V * lapV;
|
|
|
|
// Update with clamping
|
|
nextU[idx] = Math.max(0, Math.min(1, u[idx] + dt * du));
|
|
nextV[idx] = Math.max(0, Math.min(1, v[idx] + dt * dv));
|
|
}
|
|
}
|
|
|
|
// Swap buffers
|
|
[u, nextU] = [nextU, u];
|
|
[v, nextV] = [nextV, v];
|
|
}
|
|
|
|
// Drawing
|
|
function draw() {
|
|
const imgData = ctx.createImageData(canvas.width, canvas.height);
|
|
const data = imgData.data;
|
|
|
|
for (let y = 0; y < canvas.height; y++) {
|
|
for (let x = 0; x < canvas.width; x++) {
|
|
const i = Math.floor(x / gridSize);
|
|
const j = Math.floor(y / gridSize);
|
|
const idx = i + j * cols;
|
|
|
|
// Get V value (reaction product) as intensity
|
|
const intensity = v[idx] * 255;
|
|
const pixelIdx = (y * canvas.width + x) * 4;
|
|
|
|
// Monochrome with dryness
|
|
const dryFactor = params.tone.dryness * 0.8 + 0.2;
|
|
const val = Math.floor(intensity * dryFactor);
|
|
|
|
data[pixelIdx] = val; // R
|
|
data[pixelIdx + 1] = val; // G
|
|
data[pixelIdx + 2] = val; // B
|
|
data[pixelIdx + 3] = 255; // A
|
|
}
|
|
}
|
|
|
|
ctx.putImageData(imgData, 0, 0);
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
update();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
// Start
|
|
init();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |