birth: Dry Pulse in Static Zen
This commit is contained in:
parent
a6ecbbf973
commit
58b2051fc1
1 changed files with 162 additions and 0 deletions
162
index.html
Normal file
162
index.html
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Neurameba Reaction</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0a0a;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
color: #444;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#info {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 20px;
|
||||||
|
font-size: 11px;
|
||||||
|
text-shadow: 0 0 5px #111;
|
||||||
|
}
|
||||||
|
</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.035,
|
||||||
|
kill: 0.065,
|
||||||
|
diffA: 1.0,
|
||||||
|
diffB: 0.5,
|
||||||
|
gridSize: 100,
|
||||||
|
scale: 5,
|
||||||
|
decay: 0.95,
|
||||||
|
pulse: 1.25
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize grids
|
||||||
|
let gridA = new Array(params.gridSize * params.gridSize).fill(0);
|
||||||
|
let gridB = new Array(params.gridSize * params.gridSize).fill(0);
|
||||||
|
let displayGrid = new Array(params.gridSize * params.gridSize).fill(0);
|
||||||
|
|
||||||
|
// Random seed
|
||||||
|
function initGrid() {
|
||||||
|
for (let i = 0; i < gridA.length; i++) {
|
||||||
|
gridA[i] = (Math.random() * 0.1 > 0.08) ? 0 : 0.5 + Math.random() * 0.5;
|
||||||
|
gridB[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initGrid();
|
||||||
|
|
||||||
|
// Reaction-diffusion kernel
|
||||||
|
function update() {
|
||||||
|
const nextA = new Array(params.gridSize * params.gridSize).fill(0);
|
||||||
|
const nextB = new Array(params.gridSize * params.gridSize).fill(0);
|
||||||
|
|
||||||
|
const size = params.gridSize;
|
||||||
|
const width = params.gridSize;
|
||||||
|
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
for (let y = 0; y < width; y++) {
|
||||||
|
const i = x + y * width;
|
||||||
|
|
||||||
|
const idxL = (x - 1 + width) % width + y * width;
|
||||||
|
const idxR = (x + 1) % width + y * width;
|
||||||
|
const idxU = x + ((y - 1 + width) % width) * width;
|
||||||
|
const idxD = x + ((y + 1) % width) * width;
|
||||||
|
|
||||||
|
const laplacianA = gridA[idxL] + gridA[idxR] + gridA[idxU] + gridA[idxD] - 4 * gridA[i];
|
||||||
|
const laplacianB = gridB[idxL] + gridB[idxR] + gridB[idxU] + gridB[idxD] - 4 * gridB[i];
|
||||||
|
|
||||||
|
const reaction = gridA[i] * gridB[i] * gridB[i];
|
||||||
|
nextA[i] = gridA[i] + (params.diffA * laplacianA - reaction + params.feed * (1 - gridA[i])) * params.pulse;
|
||||||
|
nextB[i] = gridB[i] + (params.diffB * laplacianB + reaction - (params.kill + params.feed) * gridB[i]) * params.pulse;
|
||||||
|
|
||||||
|
// Decay
|
||||||
|
nextA[i] *= params.decay;
|
||||||
|
nextB[i] *= params.decay;
|
||||||
|
|
||||||
|
// Normalize to 0-1
|
||||||
|
nextA[i] = Math.max(0, Math.min(1, nextA[i]));
|
||||||
|
nextB[i] = Math.max(0, Math.min(1, nextB[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap grids
|
||||||
|
[gridA, gridB] = [nextA, nextB];
|
||||||
|
|
||||||
|
// Calculate display grid (simple reaction visualization)
|
||||||
|
for (let i = 0; i < displayGrid.length; i++) {
|
||||||
|
displayGrid[i] = (gridA[i] - gridB[i] + 1) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animation
|
||||||
|
let animationId;
|
||||||
|
let time = 0;
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
time += 0.005;
|
||||||
|
params.pulse = 1.0 + 0.5 * Math.sin(time);
|
||||||
|
|
||||||
|
update();
|
||||||
|
draw();
|
||||||
|
|
||||||
|
animationId = requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
const width = params.gridSize;
|
||||||
|
const scale = params.scale;
|
||||||
|
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Draw reaction-diffusion pattern
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
for (let y = 0; y < width; y++) {
|
||||||
|
const val = displayGrid[x + y * width];
|
||||||
|
if (val > 0.01) {
|
||||||
|
const brightness = Math.pow(val, 0.3);
|
||||||
|
ctx.fillStyle = `hsl(0, 0%, ${30 + 70 * brightness}%)`;
|
||||||
|
ctx.fillRect(
|
||||||
|
x * scale,
|
||||||
|
y * scale,
|
||||||
|
scale,
|
||||||
|
scale
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add some motion trails
|
||||||
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.05)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start animation
|
||||||
|
animate();
|
||||||
|
|
||||||
|
// Cleanup on unload
|
||||||
|
window.addEventListener('beforeunload', () => {
|
||||||
|
cancelAnimationFrame(animationId);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue