152 lines
No EOL
5.2 KiB
HTML
152 lines
No EOL
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Diffusion Lab</title>
|
|
<style>
|
|
body, html {
|
|
margin: 0;
|
|
padding: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#credits {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #555;
|
|
font-size: 10px;
|
|
text-shadow: 0 0 5px rgba(0,0,0,0.5);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="canvas"></canvas>
|
|
<div id="credits">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();
|
|
|
|
// System parameters
|
|
const W = canvas.width;
|
|
const H = canvas.height;
|
|
const SIM_RESOLUTION = Math.floor(W * 0.8);
|
|
const CELL_SIZE = 2;
|
|
const DENSITY = 0.5;
|
|
const COMPLEXITY = 0.5;
|
|
|
|
// Reaction-diffusion parameters (Gray-Scott model)
|
|
const params = {
|
|
feed: 0.055 + (COMPLEXITY * 0.045),
|
|
kill: 0.062 + (COMPLEXITY * 0.038),
|
|
dt: 1.0,
|
|
diffusionRateA: 1.0,
|
|
diffusionRateB: 0.5,
|
|
time: 0
|
|
};
|
|
|
|
// Initialize textures
|
|
const textureA = new Float64Array(SIM_RESOLUTION * SIM_RESOLUTION);
|
|
const textureB = new Float64Array(SIM_RESOLUTION * SIM_RESOLUTION);
|
|
const textureDisplay = new Uint8ClampedArray(SIM_RESOLUTION * SIM_RESOLUTION * 4);
|
|
|
|
// Initialize with sparse random points
|
|
for (let i = 0; i < SIM_RESOLUTION * SIM_RESOLUTION; i++) {
|
|
textureA[i] = 1.0;
|
|
textureB[i] = 0.0;
|
|
}
|
|
|
|
// Add perturbations
|
|
const perturbationCount = Math.floor(DENSITY * SIM_RESOLUTION * SIM_RESOLUTION * 0.3);
|
|
for (let i = 0; i < perturbationCount; i++) {
|
|
const idx = Math.floor(Math.random() * SIM_RESOLUTION * SIM_RESOLUTION);
|
|
textureB[idx] = 1.0 + Math.random() * 0.1;
|
|
}
|
|
|
|
// Ping-pong buffers
|
|
let ping = true;
|
|
let textureA0 = textureA;
|
|
let textureA1 = new Float64Array(textureA.length);
|
|
let textureB0 = textureB;
|
|
let textureB1 = new Float64Array(textureB.length);
|
|
|
|
function update() {
|
|
params.time += 0.01;
|
|
|
|
// Update reaction-diffusion
|
|
for (let i = 0; i < SIM_RESOLUTION * SIM_RESOLUTION; i++) {
|
|
const a = textureA0[i];
|
|
const b = textureB0[i];
|
|
|
|
// Reaction terms
|
|
const reaction = a * b * b;
|
|
const newA = a + params.dt * (-reaction + params.feed * (1 - a));
|
|
const newB = b + params.dt * (reaction - (params.kill + params.feed) * b);
|
|
|
|
textureA1[i] = Math.max(0, Math.min(1, newA));
|
|
textureB1[i] = Math.max(0, Math.min(1, newB));
|
|
}
|
|
|
|
// Swap buffers
|
|
[textureA0, textureA1] = [textureA1, textureA0];
|
|
[textureB0, textureB1] = [textureB1, textureB0];
|
|
|
|
// Update display texture
|
|
const displayScale = 0.8;
|
|
const displayWidth = Math.floor(W * displayScale);
|
|
const displayHeight = Math.floor(H * displayScale);
|
|
|
|
for (let y = 0; y < displayHeight; y++) {
|
|
for (let x = 0; x < displayWidth; x++) {
|
|
const idx = (y * displayWidth + x) * 4;
|
|
const simX = Math.floor((x / displayWidth) * SIM_RESOLUTION);
|
|
const simY = Math.floor((y / displayHeight) * SIM_RESOLUTION);
|
|
|
|
const a = textureA0[simY * SIM_RESOLUTION + simX];
|
|
const b = textureB0[simY * SIM_RESOLUTION + simX];
|
|
|
|
// Calculate intensity (monochrome based on dryness)
|
|
const intensity = 1.0 - Math.min(1, (a - b) * 0.5);
|
|
|
|
// Apply pulse modulation
|
|
const pulseFactor = 1.1 + 0.1 * Math.sin(params.time * 2.0);
|
|
const finalIntensity = Math.pow(intensity * pulseFactor, 0.8);
|
|
|
|
// Gray tones with low contrast
|
|
const value = Math.floor(255 * finalIntensity);
|
|
textureDisplay[idx] = value;
|
|
textureDisplay[idx + 1] = value;
|
|
textureDisplay[idx + 2] = value;
|
|
textureDisplay[idx + 3] = 255;
|
|
}
|
|
}
|
|
|
|
// Draw to canvas
|
|
const imageData = new ImageData(textureDisplay, displayWidth, displayHeight);
|
|
ctx.clearRect(0, 0, W, H);
|
|
|
|
// Center the texture
|
|
const offsetX = (W - displayWidth) / 2;
|
|
const offsetY = (H - displayHeight) / 2;
|
|
ctx.putImageData(imageData, offsetX, offsetY);
|
|
|
|
requestAnimationFrame(update);
|
|
}
|
|
|
|
update();
|
|
</script>
|
|
</body>
|
|
</html> |