141 lines
No EOL
4.7 KiB
HTML
141 lines
No EOL
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Neurameba Motd Social</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: #555;
|
|
font-size: 11px;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="c"></canvas>
|
|
<div id="attribution">neurameba · motd.social</div>
|
|
<script>
|
|
const canvas = document.getElementById('c');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Set canvas to full window size
|
|
function resize() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resize);
|
|
resize();
|
|
|
|
// Reaction-diffusion parameters
|
|
const params = {
|
|
feedRate: 0.055,
|
|
killRate: 0.062,
|
|
diffusionRateA: 1.0,
|
|
diffusionRateB: 0.5,
|
|
timeStep: 1.0,
|
|
gridScale: 1,
|
|
decay: 0.98,
|
|
};
|
|
|
|
// Initialize grids
|
|
const size = Math.floor(Math.min(canvas.width, canvas.height) / params.gridScale);
|
|
const width = size;
|
|
const height = size;
|
|
|
|
let prevGrid = new Array(width * height).fill(0);
|
|
let nextGrid = new Array(width * height).fill(0);
|
|
let displayGrid = new Array(width * height).fill(0);
|
|
|
|
// Initialize with randomness based on density
|
|
for (let i = 0; i < prevGrid.length; i++) {
|
|
prevGrid[i] = Math.random() * 0.1;
|
|
}
|
|
|
|
// Simulation function
|
|
function simulate() {
|
|
const { feedRate, killRate, diffusionRateA, diffusionRateB, timeStep } = params;
|
|
|
|
for (let y = 1; y < height - 1; y++) {
|
|
for (let x = 1; x < width - 1; x++) {
|
|
const idx = y * width + x;
|
|
const a = prevGrid[idx];
|
|
const tl = prevGrid[(y - 1) * width + (x - 1)];
|
|
const t = prevGrid[(y - 1) * width + x];
|
|
const tr = prevGrid[(y - 1) * width + (x + 1)];
|
|
const l = prevGrid[y * width + (x - 1)];
|
|
const r = prevGrid[y * width + (x + 1)];
|
|
const bl = prevGrid[(y + 1) * width + (x - 1)];
|
|
const b = prevGrid[(y + 1) * width + x];
|
|
const br = prevGrid[(y + 1) * width + (x + 1)];
|
|
|
|
const laplacianA = (tl + t + tr + l + r + bl + b + br) / 8.0 - a;
|
|
const laplacianB = (tl + t + tr + l + r + bl + b + br) / 8.0 - prevGrid[idx + width * height/2];
|
|
|
|
// Turing reaction-diffusion equations
|
|
const reaction = a * b * b;
|
|
const newA = a + (diffusionRateA * laplacianA - reaction + feedRate * (1 - a)) * timeStep;
|
|
const newB = prevGrid[idx + width * height/2] + (diffusionRateB * laplacianB + reaction - (killRate + feedRate) * prevGrid[idx + width * height/2]) * timeStep;
|
|
|
|
nextGrid[idx] = newA;
|
|
nextGrid[idx + width * height/2] = newB;
|
|
|
|
// Update display grid (B component)
|
|
displayGrid[idx] = newB;
|
|
}
|
|
}
|
|
|
|
// Swap grids
|
|
[prevGrid, nextGrid] = [nextGrid, prevGrid];
|
|
}
|
|
|
|
// Render function
|
|
function render() {
|
|
const imageData = ctx.createImageData(width, height);
|
|
const data = imageData.data;
|
|
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const idx = y * width + x;
|
|
const val = displayGrid[idx];
|
|
|
|
// Map value to grayscale with dryness tone
|
|
const c = Math.floor(val * 255);
|
|
const i = idx * 4;
|
|
|
|
data[i] = c; // R
|
|
data[i + 1] = c; // G
|
|
data[i + 2] = c; // B
|
|
data[i + 3] = 255; // Alpha
|
|
}
|
|
}
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
for (let i = 0; i < 4; i++) {
|
|
simulate();
|
|
}
|
|
render();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
// Start animation
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |