teal-pulse-fields-8ygj/index.html

139 lines
No EOL
4.5 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 Reaction Diffusion</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: #444;
font-size: 10px;
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 adjusted from input
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.1, min: 1.0, max: 1.2 }
};
// Reaction-diffusion simulation
const size = 64; // Grid size (tradeoff between performance and detail)
const scale = Math.min(canvas.width, canvas.height) / size;
// Initialize reaction-diffusion grid
let grid = createEmptyGrid(size);
let nextGrid = createEmptyGrid(size);
// Seed with random spots
for (let i = 0; i < size * size * params.density * 1.5; i++) {
const x = Math.floor(Math.random() * size);
const y = Math.floor(Math.random() * size);
grid[y][x] = 1;
}
// Parameters for Gray-Scott model
const f = 0.055 + params.complexity * 0.02;
const k = 0.06 + params.connectedness * 0.04;
const feedRate = params.motion * 0.05 + 0.03;
const killRate = params.complexity * 0.03 + 0.045;
function createEmptyGrid(size) {
return Array(size).fill().map(() => Array(size).fill(0));
}
function updateGrid() {
const pulse = params.pulse.avg + (Math.random() * (params.pulse.max - params.pulse.min) - (params.pulse.max - params.pulse.min)/2);
const timestep = feedRate * pulse;
for (let y = 1; y < size - 1; y++) {
for (let x = 1; x < size - 1; x++) {
const u = grid[y][x];
const v = 1 - u;
const laplacianU = (grid[y-1][x] + grid[y+1][x] + grid[y][x-1] + grid[y][x+1] - 4 * u) * 0.2;
const reaction = u * v * v;
nextGrid[y][x] = u + timestep * (0.01 * laplacianU - reaction);
if (nextGrid[y][x] < 0) nextGrid[y][x] = 0;
if (nextGrid[y][x] > 1) nextGrid[y][x] = 1;
}
}
// Swap grids
[grid, nextGrid] = [nextGrid, grid];
}
function draw() {
ctx.fillStyle = '#0a0a0a';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
const val = grid[y][x];
if (val > 0.1) {
const hue = 120 + (val * 100); // Teals with brightness variation
const saturation = 30 + (val * 70);
const lightness = 20 + (val * 30);
const size = scale * (0.5 + val) * (0.5 + params.density * 0.5);
ctx.fillStyle = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
ctx.beginPath();
ctx.arc(
centerX + (x - size/2) * scale,
centerY + (y - size/2) * scale,
size,
0,
Math.PI * 2
);
ctx.fill();
}
}
}
}
function animate() {
updateGrid();
draw();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>