birth: Teal echoes in thin soup
This commit is contained in:
parent
3d0e5df723
commit
00f35fb597
1 changed files with 172 additions and 0 deletions
172
index.html
Normal file
172
index.html
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
<!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, html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #000;
|
||||||
|
height: 100%;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#info {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 10px;
|
||||||
|
text-shadow: 0 0 5px rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
</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');
|
||||||
|
|
||||||
|
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: 2,
|
||||||
|
hueBase: 180,
|
||||||
|
hueVariation: 30,
|
||||||
|
saturation: 70,
|
||||||
|
luminosity: 50,
|
||||||
|
trails: true,
|
||||||
|
trailDecay: 0.95
|
||||||
|
};
|
||||||
|
|
||||||
|
const cols = Math.floor(canvas.width / params.gridSize);
|
||||||
|
const rows = Math.floor(canvas.height / params.gridSize);
|
||||||
|
const grid = new Array(cols).fill().map(() => new Array(rows).fill(0));
|
||||||
|
const next = new Array(cols).fill().map(() => new Array(rows).fill(0));
|
||||||
|
const trails = new Array(cols).fill().map(() => new Array(rows).fill(0));
|
||||||
|
|
||||||
|
// Initialize with random values
|
||||||
|
function init() {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
grid[x][y] = Math.random() < 0.5 ? 0 : Math.random();
|
||||||
|
next[x][y] = grid[x][y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add some initial patterns
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const x = Math.floor(Math.random() * cols);
|
||||||
|
const y = Math.floor(Math.random() * rows);
|
||||||
|
const size = Math.floor(Math.random() * 10 + 5);
|
||||||
|
for (let dx = -size; dx <= size; dx++) {
|
||||||
|
for (let dy = -size; dy <= dy <= size; dy++) {
|
||||||
|
if (dx*dx + dy*dy <= size*size) {
|
||||||
|
const nx = (x + dx + cols) % cols;
|
||||||
|
const ny = (y + dy + rows) % rows;
|
||||||
|
grid[nx][ny] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reaction-diffusion step
|
||||||
|
function step() {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
const a = grid[x][y];
|
||||||
|
const b = next[x][y];
|
||||||
|
|
||||||
|
// Compute Laplacian
|
||||||
|
let sumA = 0, sumB = 0;
|
||||||
|
let count = 0;
|
||||||
|
for (let dx = -1; dx <= 1; dx++) {
|
||||||
|
for (let dy = -1; dy <= 1; dy++) {
|
||||||
|
if (dx === 0 && dy === 0) continue;
|
||||||
|
const nx = (x + dx + cols) % cols;
|
||||||
|
const ny = (y + dy + rows) % rows;
|
||||||
|
sumA += grid[nx][ny];
|
||||||
|
sumB += next[nx][ny];
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const laplacianA = (sumA / count - a) * params.diffusionA;
|
||||||
|
const laplacianB = (sumB / count - b) * params.diffusionB;
|
||||||
|
|
||||||
|
// Update equations
|
||||||
|
next[x][y] = a + params.timeStep * (
|
||||||
|
a * (params.feed - (a + 1) * b) + laplacianA
|
||||||
|
);
|
||||||
|
next[x][y] = Math.max(0, Math.min(next[x][y], 1));
|
||||||
|
|
||||||
|
next[x][y] = b + params.timeStep * (
|
||||||
|
b * (params.kill - b) * a + laplacianB + params.feed * (1 - b)
|
||||||
|
);
|
||||||
|
next[x][y] = Math.max(0, Math.min(next[x][y], 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap grids
|
||||||
|
[grid, next] = [next, grid];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw with trails
|
||||||
|
function draw() {
|
||||||
|
if (params.trails) {
|
||||||
|
ctx.fillStyle = `rgba(0, 0, 0, ${params.trailDecay})`;
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
const val = grid[x][y];
|
||||||
|
if (val > 0.1) {
|
||||||
|
const hue = params.hueBase + (val * params.hueVariation);
|
||||||
|
const saturation = params.saturation + (val * 20);
|
||||||
|
const luminosity = params.luminosity + (val * 10);
|
||||||
|
ctx.fillStyle = `hsl(${hue}, ${saturation}%, ${luminosity}%)`;
|
||||||
|
ctx.fillRect(x * params.gridSize, y * params.gridSize,
|
||||||
|
params.gridSize, params.gridSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fade trails
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
trails[x][y] *= params.trailDecay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animation loop
|
||||||
|
function animate() {
|
||||||
|
step();
|
||||||
|
draw();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue