birth: Static Pulsing Monochrome Life
This commit is contained in:
parent
b3bed0e97d
commit
29872602bb
1 changed files with 151 additions and 0 deletions
151
index.html
Normal file
151
index.html
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Cellular Automata</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
}
|
||||
</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();
|
||||
|
||||
// Parameters based on the organism description
|
||||
const params = {
|
||||
motion: 0.482,
|
||||
density: 0.569,
|
||||
complexity: 0.475,
|
||||
connectedness: 0.476,
|
||||
lifespan: 0.421,
|
||||
pulse: { avg: 0.71, min: 0.30, max: 1.70 },
|
||||
tone: {
|
||||
anger: 0.00,
|
||||
sadness: 0.00,
|
||||
curiosity: 0.70,
|
||||
dryness: 0.90,
|
||||
playfulness: 0.10,
|
||||
tension: 0.00
|
||||
}
|
||||
};
|
||||
|
||||
// Cellular automata grid
|
||||
const cols = Math.floor(canvas.width / 4);
|
||||
const rows = Math.floor(canvas.height / 4);
|
||||
let grid = new Array(rows).fill().map(() => new Array(cols).fill(0));
|
||||
let nextGrid = new Array(rows).fill().map(() => new Array(cols).fill(0));
|
||||
|
||||
// Initial state
|
||||
function initializeGrid() {
|
||||
for (let i = 0; i < rows; i++) {
|
||||
for (let j = 0; j < cols; j++) {
|
||||
grid[i][j] = Math.random() > params.density ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rules based on complexity and connectedness
|
||||
function applyRules() {
|
||||
const ruleSet = [
|
||||
// Survival: cells stay alive if they have 2 or 3 neighbors
|
||||
// Birth: cells are born if they have exactly 3 neighbors
|
||||
(cell, neighbors) => (cell && (neighbors === 2 || neighbors === 3)) ||
|
||||
(!cell && neighbors === 3) ? 1 : 0
|
||||
];
|
||||
|
||||
// Select rule based on complexity and connectedness
|
||||
const rule = ruleSet[0];
|
||||
|
||||
for (let i = 0; i < rows; i++) {
|
||||
for (let j = 0; j < cols; j++) {
|
||||
let neighbors = 0;
|
||||
|
||||
// Count neighbors (Moore neighborhood)
|
||||
for (let di = -1; di <= 1; di++) {
|
||||
for (let dj = -1; dj <= 1; dj++) {
|
||||
if (di === 0 && dj === 0) continue;
|
||||
const ni = i + di;
|
||||
const nj = j + dj;
|
||||
if (ni >= 0 && ni < rows && nj >= 0 && nj < cols) {
|
||||
neighbors += grid[ni][nj];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nextGrid[i][j] = rule(grid[i][j], neighbors);
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
}
|
||||
|
||||
// Drawing
|
||||
function draw() {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const cellWidth = canvas.width / cols;
|
||||
const cellHeight = canvas.height / rows;
|
||||
|
||||
// Draw cells with pulse effect
|
||||
const pulse = params.pulse.avg + (params.pulse.max - params.pulse.min) * (Math.sin(Date.now() * 0.001) * 0.5 + 0.5);
|
||||
|
||||
for (let i = 0; i < rows; i++) {
|
||||
for (let j = 0; j < cols; j++) {
|
||||
if (grid[i][j] > 0) {
|
||||
// Use dryness (monochrome) with slight variation
|
||||
const value = Math.max(0, Math.min(255, 100 + grid[i][j] * 155 * pulse));
|
||||
ctx.fillStyle = `rgb(${value}, ${value}, ${value})`;
|
||||
|
||||
// Slight variation based on complexity
|
||||
const size = 3 + (params.complexity * 2);
|
||||
const x = j * cellWidth + cellWidth * 0.5 - size * 0.5;
|
||||
const y = i * cellHeight + cellHeight * 0.5 - size * 0.5;
|
||||
|
||||
ctx.fillRect(x, y, size, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
applyRules();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Initialize and start
|
||||
initializeGrid();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue