birth: Fading Echoes in Chemical Veins

This commit is contained in:
motd_admin 2026-10-24 18:21:25 +00:00
parent 356aac3982
commit 0836bb4f29

144
index.html Normal file
View file

@ -0,0 +1,144 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chemical Dreams</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #555;
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');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Reaction-diffusion parameters
const params = {
diffusionRateA: 1.0,
diffusionRateB: 0.5,
feedRate: 0.055,
killRate: 0.062,
timeStep: 1.0,
gridScale: 2,
colorA: '#f0f0f0',
colorB: '#555555'
};
const cols = Math.floor(canvas.width / params.gridScale);
const rows = Math.floor(canvas.height / params.gridScale);
const grid = new Array(cols).fill().map(() => new Array(rows).fill(0));
// Initialize with random patterns
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
grid[x][y] = Math.random() * 0.1;
}
}
// Reaction-diffusion kernel (discrete 3x3 Laplacian)
function laplacian(x, y) {
const xPrev = (x + cols - 1) % cols;
const xNext = (x + 1) % cols;
const yPrev = (y + rows - 1) % rows;
const yNext = (y + 1) % rows;
let sum = 0;
sum += grid[x][y] * -1;
sum += grid[xPrev][y] * 0.2;
sum += grid[xNext][y] * 0.2;
sum += grid[x][yPrev] * 0.2;
sum += grid[x][yNext] * 0.2;
sum += grid[xPrev][yPrev] * 0.05;
sum += grid[xNext][yNext] * 0.05;
sum += grid[xPrev][yNext] * 0.05;
sum += grid[xNext][yPrev] * 0.05;
return sum;
}
function update() {
const newGrid = new Array(cols).fill().map(() => new Array(rows).fill(0));
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const a = grid[x][y];
if (a <= 0) continue;
const laplacianA = laplacian(x, y);
const reaction = a * (params.feedRate - (params.killRate + 1) * a) + a * a * b * params.timeStep;
newGrid[x][y] = a + (params.diffusionRateA * laplacianA + reaction);
// Prevent values from going negative
if (newGrid[x][y] < 0) newGrid[x][y] = 0;
}
}
grid.length = 0;
for (let x = 0; x < cols; x++) {
grid[x] = newGrid[x].slice();
}
}
function draw() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const value = Math.min(1, Math.max(0, grid[x][y]));
if (value > 0.01) {
ctx.fillStyle = `rgba(240, 240, 240, ${value})`;
ctx.fillRect(x * params.gridScale, y * params.gridScale, params.gridScale, params.gridScale);
}
}
}
}
let lastTime = 0;
function animate(time) {
const deltaTime = time - lastTime;
lastTime = time;
// Adjust speed based on pulse
const pulseSpeed = 1.0 + (Math.sin(time * 0.001) * 0.2);
if (deltaTime > 16) { // Throttle if lagging
update();
}
draw();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>