birth: Fading Fractal Echoes
This commit is contained in:
parent
bc7b187ed9
commit
30d4d14549
1 changed files with 166 additions and 0 deletions
166
index.html
Normal file
166
index.html
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cellular Nebula</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
font-family: monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
text-shadow: 0 0 5px rgba(0, 188, 212, 0.5);
|
||||
}
|
||||
</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 resize() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resize);
|
||||
resize();
|
||||
|
||||
// Parameters derived from input
|
||||
const MOTION = 0.5;
|
||||
const DENSITY = 0.5;
|
||||
const COMPLEXITY = 0.5;
|
||||
const CONNECTEDNESS = 0.5;
|
||||
const LIFESPAN = 0.5;
|
||||
const PULSE_AVG = 1.11;
|
||||
const DRYNESS = 0.9;
|
||||
|
||||
// Cellular automata grid
|
||||
const GRID_SIZE = 64;
|
||||
const CELL_SIZE = Math.min(canvas.width, canvas.height) / GRID_SIZE;
|
||||
const cols = Math.ceil(canvas.width / CELL_SIZE);
|
||||
const rows = Math.ceil(canvas.height / CELL_SIZE);
|
||||
|
||||
// Initialize grid
|
||||
let grid = new Array(rows).fill().map(() =>
|
||||
new Array(cols).fill().map(() => Math.random() > 0.5 ? 1 : 0)
|
||||
);
|
||||
|
||||
// Neighborhood types (Moore neighborhood with varying range)
|
||||
const NEIGHBORHOOD = Math.max(1, Math.floor(COMPLEXITY * 4));
|
||||
|
||||
// Colors based on dryness (monochrome)
|
||||
const BASE_HUE = 0;
|
||||
const SATURATION = 0;
|
||||
const LIGHTNESS = DRYNESS > 0.8 ? 90 : 70;
|
||||
|
||||
function drawCell(x, y, alive, age) {
|
||||
if (!alive) return;
|
||||
|
||||
const hue = BASE_HUE;
|
||||
const saturation = SATURATION;
|
||||
const lightness = LIGHTNESS - (age * 5);
|
||||
const alpha = DRYNESS > 0.7 ? 0.3 + (age * 0.05) : 0.5;
|
||||
|
||||
ctx.fillStyle = `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
||||
ctx.fillRect(x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
|
||||
function countAliveNeighbors(x, y) {
|
||||
let count = 0;
|
||||
for (let i = -NEIGHBORHOOD; i <= NEIGHBORHOOD; i++) {
|
||||
for (let j = -NEIGHBORHOOD; j <= NEIGHBORHOOD; j++) {
|
||||
if (i === 0 && j === 0) continue;
|
||||
const nx = x + i;
|
||||
const ny = y + j;
|
||||
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows) {
|
||||
count += grid[ny][nx];
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
const rules = [
|
||||
// Survival rules (B/S)
|
||||
{ births: [3], survive: [2, 3], complexity: 0.3 },
|
||||
// Apoptosis rules (more death)
|
||||
{ births: [4], survive: [2], complexity: 0.7 },
|
||||
// Aging rules (LIFESPAN affects decay)
|
||||
{ births: [3], survive: [2, 3], maxAge: 20, complexity: 0.5 }
|
||||
];
|
||||
|
||||
// Select active rule based on parameters
|
||||
const activeRule = rules[Math.floor(COMPLEXITY * rules.length)];
|
||||
|
||||
function updateGrid() {
|
||||
const newGrid = grid.map(arr => [...arr]);
|
||||
const ageGrid = grid.map(arr => [...arr].map(cell => cell * (Math.random() * 0.5 + 0.5)));
|
||||
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const alive = grid[y][x];
|
||||
const neighbors = countAliveNeighbors(x, y);
|
||||
const isBirth = activeRule.births.includes(neighbors);
|
||||
const isSurvive = activeRule.survive.includes(neighbors);
|
||||
const maxAge = activeRule.maxAge || 10;
|
||||
|
||||
if (!alive && isBirth) {
|
||||
newGrid[y][x] = 1;
|
||||
ageGrid[y][x] = 0;
|
||||
} else if (alive && !isSurvive) {
|
||||
newGrid[y][x] = 0;
|
||||
ageGrid[y][x] = 0;
|
||||
} else if (alive) {
|
||||
ageGrid[y][x] += 0.01 * MOTION * PULSE_AVG;
|
||||
if (ageGrid[y][x] > maxAge) {
|
||||
newGrid[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grid = newGrid;
|
||||
}
|
||||
|
||||
let age = 0;
|
||||
function animate() {
|
||||
ctx.fillStyle = 'rgba(0, 10, 20, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
updateGrid();
|
||||
drawGrid();
|
||||
|
||||
age++;
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
function drawGrid() {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
drawCell(x, y, grid[y][x], ageGrid[y][x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize age grid
|
||||
const ageGrid = grid.map(arr => [...arr].map(cell => cell * (Math.random() * 0.5 + 0.5)));
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue