140 lines
No EOL
4.7 KiB
HTML
140 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 Pattern</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #000;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
# attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: rgba(255, 255, 255, 0.3);
|
|
font-family: monospace;
|
|
font-size: 10px;
|
|
}
|
|
</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();
|
|
|
|
// Reaction-diffusion parameters
|
|
const params = {
|
|
feed: 0.055,
|
|
kill: 0.062,
|
|
diffusionA: 1.0,
|
|
diffusionB: 0.5,
|
|
timeStep: 1.0,
|
|
gridSize: 4,
|
|
pulse: 1.1
|
|
};
|
|
|
|
// Create grids
|
|
const size = Math.floor(Math.min(canvas.width, canvas.height) / params.gridSize);
|
|
const width = Math.ceil(canvas.width / params.gridSize);
|
|
const height = Math.ceil(canvas.height / params.gridSize);
|
|
|
|
let currentGrid = new Array(width * height).fill(0);
|
|
let nextGrid = new Array(width * height).fill(0);
|
|
|
|
// Initialize with sparse noise
|
|
for (let i = 0; i < currentGrid.length; i++) {
|
|
currentGrid[i] = (Math.random() < 0.15) ? 1 : 0;
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
// Apply pulse variation
|
|
params.feed = 0.05 + 0.005 * (Math.sin(Date.now() * 0.001) * 0.5 + 0.5);
|
|
|
|
// Update grid
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const i = y * width + x;
|
|
|
|
// Skip if cell is on edge
|
|
if (x === 0 || y === 0 || x === width - 1 || y === height - 1) {
|
|
nextGrid[i] = 0;
|
|
continue;
|
|
}
|
|
|
|
// Get neighbors
|
|
const neighbors = [
|
|
currentGrid[(y-1) * width + (x-1)], currentGrid[(y-1) * width + x], currentGrid[(y-1) * width + (x+1)],
|
|
currentGrid[y * width + (x-1)], currentGrid[y * width + (x+1)],
|
|
currentGrid[(y+1) * width + (x-1)], currentGrid[(y+1) * width + x], currentGrid[(y+1) * width + (x+1)]
|
|
];
|
|
|
|
const sumNeighbors = neighbors.reduce((a, b) => a + b, 0);
|
|
const cell = currentGrid[i];
|
|
|
|
// Reaction-diffusion formula
|
|
nextGrid[i] = cell +
|
|
params.timeStep * (
|
|
(params.diffusionA * (currentGrid[(y-1)*width+x] + currentGrid[(y+1)*width+x] + currentGrid[y*width+(x-1)] + currentGrid[y*width+(x+1)] - 4*cell))
|
|
-
|
|
(cell * sumNeighbors * params.feed)
|
|
+
|
|
(sumNeighbors * (params.kill * (1 - cell)))
|
|
);
|
|
|
|
// Clamp values
|
|
nextGrid[i] = Math.max(0, Math.min(1, nextGrid[i]));
|
|
}
|
|
}
|
|
|
|
// Swap grids
|
|
[currentGrid, nextGrid] = [nextGrid, currentGrid];
|
|
|
|
// Draw
|
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.02)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
ctx.fillStyle = 'white';
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const i = y * width + x;
|
|
if (currentGrid[i] > 0.1) {
|
|
const intensity = currentGrid[i] * 255;
|
|
ctx.fillStyle = `rgba(255, 255, 255, ${intensity / 255})`;
|
|
ctx.fillRect(
|
|
x * params.gridSize,
|
|
y * params.gridSize,
|
|
params.gridSize,
|
|
params.gridSize
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |