birth: Chemical Fragments Bloom
This commit is contained in:
parent
bf990ef153
commit
803bd88f3f
1 changed files with 139 additions and 0 deletions
139
index.html
Normal file
139
index.html
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chemical Bloom</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: monospace;
|
||||
color: #555;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
font-size: 10px;
|
||||
color: #333;
|
||||
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();
|
||||
|
||||
// Simulation parameters
|
||||
const params = {
|
||||
feed: 0.055,
|
||||
kill: 0.062,
|
||||
diffA: 1,
|
||||
diffB: 0.5,
|
||||
width: Math.floor(canvas.width / 4),
|
||||
height: Math.floor(canvas.height / 4),
|
||||
scale: 4
|
||||
};
|
||||
|
||||
// Create grid
|
||||
const grid = Array(params.height).fill().map(() =>
|
||||
Array(params.width).fill().map(() => ({
|
||||
a: 1,
|
||||
b: 0
|
||||
}))
|
||||
);
|
||||
|
||||
// Add initial noise
|
||||
for (let y = 0; y < params.height; y++) {
|
||||
for (let x = 0; x < params.width; x++) {
|
||||
grid[y][x].a = 0.5 + Math.random() * 0.5;
|
||||
grid[y][x].b = 0.25 + Math.random() * 0.25;
|
||||
}
|
||||
}
|
||||
|
||||
// Simulation function
|
||||
function update() {
|
||||
const newGrid = grid.map(row => [...row]);
|
||||
|
||||
for (let y = 1; y < params.height - 1; y++) {
|
||||
for (let x = 1; x < params.width - 1; x++) {
|
||||
const a = grid[y][x].a;
|
||||
const b = grid[y][x].b;
|
||||
|
||||
const aNeighbors = (
|
||||
grid[y][x-1].a + grid[y][x+1].a +
|
||||
grid[y-1][x].a + grid[y+1][x].a +
|
||||
grid[y-1][x-1].a * 0.5 + grid[y-1][x+1].a * 0.5 +
|
||||
grid[y+1][x-1].a * 0.5 + grid[y+1][x+1].a * 0.5
|
||||
) / 6;
|
||||
|
||||
const bNeighbors = (
|
||||
grid[y][x-1].b + grid[y][x+1].b +
|
||||
grid[y-1][x].b + grid[y+1][x].b +
|
||||
grid[y-1][x-1].b * 0.5 + grid[y-1][x+1].b * 0.5 +
|
||||
grid[y+1][x-1].b * 0.5 + grid[y+1][x+1].b * 0.5
|
||||
) / 6;
|
||||
|
||||
newGrid[y][x].a = a + (
|
||||
params.diffA * aNeighbors -
|
||||
a * b * b +
|
||||
params.feed * (1 - a)
|
||||
);
|
||||
|
||||
newGrid[y][x].b = b + (
|
||||
params.diffB * bNeighbors +
|
||||
a * b * b -
|
||||
(params.kill + params.feed) * b
|
||||
);
|
||||
|
||||
// Clamp values
|
||||
newGrid[y][x].a = Math.max(0, Math.min(1, newGrid[y][x].a));
|
||||
newGrid[y][x].b = Math.max(0, Math.min(1, newGrid[y][x].b));
|
||||
}
|
||||
}
|
||||
|
||||
// Update grid
|
||||
grid.length = 0;
|
||||
grid.push(...newGrid);
|
||||
|
||||
// Draw
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
for (let y = 0; y < params.height; y++) {
|
||||
for (let x = 0; x < params.width; x++) {
|
||||
const val = grid[y][x].b;
|
||||
if (val > 0.1) {
|
||||
const intensity = Math.min(1, val * 3);
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${intensity * 0.8})`;
|
||||
ctx.fillRect(x * params.scale, y * params.scale, params.scale, params.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
requestAnimationFrame(animate);
|
||||
update();
|
||||
}
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue