dissolving-patterns-in-flux.../index.html

166 lines
No EOL
6 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;
padding: 0;
overflow: hidden;
background-color: #0a0a0a;
color: #f0f0f0;
font-family: 'Courier New', monospace;
}
#info {
position: absolute;
bottom: 10px;
left: 10px;
font-size: 10px;
opacity: 0.7;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="info">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 = {
feedRate: 0.055,
killRate: 0.062,
diffusionRateA: 1.0,
diffusionRateB: 0.5,
timeStep: 1.0,
gridSize: 4,
complexity: 0.5,
connectedness: 0.5,
motion: 0.5
};
// Initialize grids
const size = Math.floor(canvas.width / params.gridSize);
const centerX = Math.floor(canvas.width / 2);
const centerY = Math.floor(canvas.height / 2);
let grid = new Array(size).fill().map(() =>
new Array(size).fill(0).map(() => ({
a: Math.random() < 0.1 ? 1 : 0,
b: 0,
lifespan: Math.random() > 0.5 ? 255 : 0
}))
);
// Reaction-diffusion function
function updateGrid() {
const nextGrid = new Array(size).fill().map(() =>
new Array(size).fill().map(() => ({ a: 0, b: 0, lifespan: 0 }))
);
for (let y = 1; y < size - 1; y++) {
for (let x = 1; x < size - 1; x++) {
const cell = grid[y][x];
const a = cell.a;
const b = cell.b;
// Reaction
const reaction = a * b * b;
const newA = a + (params.diffusionRateA * laplacian(grid, x, y, 'a') - reaction + params.feedRate * (1 - a));
const newB = b + (params.diffusionRateB * laplacian(grid, x, y, 'b') + reaction - (params.killRate + params.feedRate) * b);
// Update cell
nextGrid[y][x].a = Math.min(Math.max(newA, 0), 1);
nextGrid[y][x].b = Math.min(Math.max(newB, 0), 1);
nextGrid[y][x].lifespan = cell.lifespan > 0 ? cell.lifespan - 0.5 : 0;
// Spawn new patterns in complex areas
if (nextGrid[y][x].a > 0.4 && Math.random() < params.complexity * 0.01) {
nextGrid[y][x].b = 1;
}
}
}
grid = nextGrid;
}
// Laplacian calculation for diffusion
function laplacian(grid, x, y, type) {
return (
grid[y-1][x][type] + grid[y+1][x][type] +
grid[y][x-1][type] + grid[y][x+1][type] -
4 * grid[y][x][type]
);
}
// Render function
function render() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
const cell = grid[y][x];
if (cell.a > 0 || cell.b > 0) {
const posX = x * params.gridSize;
const posY = y * params.gridSize;
// Draw based on concentration
const intensity = Math.min((cell.b * 255), 255);
const size = params.gridSize * 2 * (0.5 + cell.a * 0.5);
const hue = cell.b > 0.5 ? 200 : 0; // Blues for B, reds for A
ctx.fillStyle = `hsla(${hue}, 100%, ${intensity * 0.5}%, ${cell.lifespan / 255})`;
ctx.beginPath();
ctx.arc(posX, posY, size, 0, Math.PI * 2);
ctx.fill();
// Draw connections based on connectedness
if (cell.lifespan > 0 && params.connectedness > 0.3) {
ctx.strokeStyle = `rgba(255, 255, 255, ${cell.lifespan / 255 * params.connectedness})`;
ctx.lineWidth = 1;
// Connect to neighbors
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
if (x + dx >= 0 && x + dx < size && y + dy >= 0 && y + dy < size) {
const neighbor = grid[y + dy][x + dx];
if (neighbor.a > 0.3 || neighbor.b > 0.3) {
ctx.beginPath();
ctx.moveTo(posX, posY);
ctx.lineTo(posX + dx * params.gridSize, posY + dy * params.gridSize);
ctx.stroke();
}
}
}
}
}
}
}
}
}
// Animation loop
function animate() {
updateGrid();
render();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>