birth: Whispering Chemical Shadows
This commit is contained in:
parent
ef704ced48
commit
6bcf0a03d8
1 changed files with 123 additions and 0 deletions
123
index.html
Normal file
123
index.html
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Diffusive Echoes</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
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 = {
|
||||
feed: 0.055,
|
||||
kill: 0.062,
|
||||
deltaTime: 1,
|
||||
diffusionA: 1,
|
||||
diffusionB: 0.5,
|
||||
width: Math.floor(canvas.width / 4),
|
||||
height: Math.floor(canvas.height / 4),
|
||||
scale: 4
|
||||
};
|
||||
|
||||
// Simulation state
|
||||
let grid = createGrid(params.width, params.height);
|
||||
let nextGrid = createGrid(params.width, params.height);
|
||||
|
||||
function createGrid(width, height) {
|
||||
const grid = new Array(width);
|
||||
for (let i = 0; i < width; i++) {
|
||||
grid[i] = new Array(height);
|
||||
for (let j = 0; j < height; j++) {
|
||||
grid[i][j] = Math.random() * 0.1;
|
||||
}
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
function updateGrid() {
|
||||
const { width, height, feed, kill, diffusionA, diffusionB } = params;
|
||||
|
||||
for (let x = 1; x < width - 1; x++) {
|
||||
for (let y = 1; y < height - 1; y++) {
|
||||
const a = grid[x][y];
|
||||
const b = grid[x][y];
|
||||
|
||||
// Compute Laplacian
|
||||
const laplacianA = (grid[x-1][y] + grid[x+1][y] + grid[x][y-1] + grid[x][y+1] - 4 * a) * diffusionA;
|
||||
const laplacianB = (grid[x-1][y] + grid[x+1][y] + grid[x][y-1] + grid[x][y+1] - 4 * b) * diffusionB;
|
||||
|
||||
// Reaction terms
|
||||
const reactionA = a * b * b;
|
||||
const reactionB = a * b * b;
|
||||
|
||||
// Update next state
|
||||
nextGrid[x][y] = a + (laplacianA - reactionA + feed * (1 - a)) * params.deltaTime;
|
||||
nextGrid[x][y] = Math.max(0, Math.min(1, nextGrid[x][y]));
|
||||
|
||||
nextGrid[x][y] = b + (laplacianB + reactionB - kill * b) * params.deltaTime;
|
||||
nextGrid[x][y] = Math.max(0, Math.min(1, nextGrid[x][y]));
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
}
|
||||
|
||||
function draw() {
|
||||
const { width, height, scale } = params;
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let y = 0; y < height; y++) {
|
||||
const val = grid[x][y];
|
||||
if (val > 0.2) {
|
||||
const intensity = Math.min(1, val * 2);
|
||||
ctx.fillStyle = `rgba(200, 210, 220, ${intensity * 0.8})`;
|
||||
ctx.fillRect(x * scale, y * scale, scale, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
updateGrid();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue