179 lines
No EOL
6.3 KiB
HTML
179 lines
No EOL
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Chemical Bloom</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #000;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100vh;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
.attribution {
|
|
position: absolute;
|
|
bottom: 20px;
|
|
left: 0;
|
|
right: 0;
|
|
text-align: center;
|
|
color: #666;
|
|
font-family: monospace;
|
|
pointer-events: none;
|
|
}
|
|
</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');
|
|
|
|
// Set canvas to full window size
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
// Reaction-diffusion parameters derived from your metrics
|
|
const params = {
|
|
feedRate: 0.055,
|
|
killRate: 0.062,
|
|
diffusionRateA: 0.197,
|
|
diffusionRateB: 0.051,
|
|
timeStep: 1.0,
|
|
decay: 0.001,
|
|
complexity: 0.467 * 2.5 + 0.5,
|
|
motion: 0.493 * 3.0 + 0.5,
|
|
density: 0.522 * 0.8 + 0.2,
|
|
connectedness: 0.486 * 1.5 + 0.5,
|
|
pulseRange: [0.30, 1.65]
|
|
};
|
|
|
|
// Simulation grid
|
|
const size = Math.floor(Math.min(canvas.width, canvas.height) * params.density);
|
|
const grid = {
|
|
a: new Float64Array(size * size),
|
|
b: new Float64Array(size * size),
|
|
tempA: new Float64Array(size * size),
|
|
tempB: new Float64Array(size * size)
|
|
};
|
|
|
|
// Initialize with some randomness and central point
|
|
const centerX = size / 2;
|
|
const centerY = size / 2;
|
|
|
|
for (let i = 0; i < size; i++) {
|
|
for (let j = 0; j < size; j++) {
|
|
const x = i - centerX;
|
|
const y = j - centerY;
|
|
const dist = Math.sqrt(x * x + y * y) / size;
|
|
const val = Math.exp(-dist * dist * 20) * 0.5;
|
|
grid.a[i + j * size] = val;
|
|
grid.b[i + j * size] = 0.1 + val * 0.5;
|
|
}
|
|
}
|
|
|
|
// Color palette (dryness: monochrome with slight variation)
|
|
const palette = [
|
|
'#f5f5f5', '#e0e0e0', '#cccccc',
|
|
'#b8b8b8', '#a3a3a3', '#8f8f8f'
|
|
];
|
|
|
|
function update() {
|
|
// Calculate pulse effect
|
|
const pulse = params.pulseRange[0] +
|
|
(params.pulseRange[1] - params.pulseRange[0]) *
|
|
(Math.sin(Date.now() * 0.001 * params.motion) * 0.5 + 0.5);
|
|
|
|
// Reaction-diffusion update
|
|
for (let i = 0; i < size; i++) {
|
|
for (let j = 0; j < size; j++) {
|
|
const idx = i + j * size;
|
|
const a = grid.a[idx];
|
|
const b = grid.b[idx];
|
|
|
|
// Laplacian approximation (Moore neighborhood)
|
|
let laplacianA = 0;
|
|
let laplacianB = 0;
|
|
let neighbors = 0;
|
|
|
|
for (let di = -1; di <= 1; di++) {
|
|
for (let dj = -1; dj <= 1; dj++) {
|
|
if (di === 0 && dj === 0) continue;
|
|
const ni = i + di;
|
|
const nj = j + dj;
|
|
if (ni >= 0 && ni < size && nj >= 0 && nj < size) {
|
|
const nidx = ni + nj * size;
|
|
laplacianA += grid.a[nidx];
|
|
laplacianB += grid.b[nidx];
|
|
neighbors++;
|
|
}
|
|
}
|
|
}
|
|
|
|
laplacianA = (laplacianA / neighbors - a) * params.diffusionRateA;
|
|
laplacianB = (laplacianB / neighbors - b) * params.diffusionRateB;
|
|
|
|
// Gray-Scott reaction
|
|
const reaction = a * b * b;
|
|
const newA = a + params.timeStep * (
|
|
laplacianA - reaction + params.feedRate * (1 - a)
|
|
);
|
|
const newB = b + params.timeStep * (
|
|
laplacianB + reaction - (params.killRate + params.feedRate) * b
|
|
);
|
|
|
|
grid.tempA[idx] = Math.max(0, Math.min(1, newA));
|
|
grid.tempB[idx] = Math.max(0, Math.min(1, newB));
|
|
}
|
|
}
|
|
|
|
// Swap buffers
|
|
[grid.a, grid.tempA] = [grid.tempA, grid.a];
|
|
[grid.b, grid.tempB] = [grid.tempB, grid.b];
|
|
|
|
// Clear canvas with slight transparency for trailing effect
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw the pattern with complex variations
|
|
const cellSize = Math.max(1, Math.floor((canvas.width / size) * params.complexity));
|
|
|
|
for (let i = 0; i < size; i++) {
|
|
for (let j = 0; j < size; j++) {
|
|
const idx = i + j * size;
|
|
const val = grid.a[idx] - grid.b[idx];
|
|
if (val > 0.1) {
|
|
const intensity = Math.min(1, val * pulse * 1.5);
|
|
const gray = Math.floor(255 * intensity);
|
|
const color = palette[Math.floor(intensity * (palette.length - 1))];
|
|
|
|
ctx.fillStyle = color;
|
|
ctx.fillRect(
|
|
i * cellSize + (Math.random() - 0.5) * cellSize * 0.1,
|
|
j * cellSize + (Math.random() - 0.5) * cellSize * 0.1,
|
|
cellSize + (Math.random() - 0.5) * cellSize * 0.2,
|
|
cellSize + (Math.random() - 0.5) * cellSize * 0.2
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
requestAnimationFrame(update);
|
|
}
|
|
|
|
update();
|
|
</script>
|
|
</body>
|
|
</html> |