birth: Monochrome Life in Pulses
This commit is contained in:
parent
22b2688a8b
commit
4b98a3f7b9
1 changed files with 173 additions and 0 deletions
173
index.html
Normal file
173
index.html
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
<!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;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
#canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#attribution {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 20px;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<div id="attribution">neurameba · motd.social</div>
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
const canvas = document.getElementById('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// Set canvas to full window size
|
||||||
|
function resizeCanvas() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
|
||||||
|
// Parameters from prompt
|
||||||
|
const params = {
|
||||||
|
motion: 0.5,
|
||||||
|
density: 0.5,
|
||||||
|
complexity: 0.5,
|
||||||
|
connectedness: 0.5,
|
||||||
|
lifespan: 0.5,
|
||||||
|
pulse: { avg: 1.1, min: 1.0, max: 1.3 },
|
||||||
|
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.8, playfulness: 0.0, tension: 0.0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Derived parameters
|
||||||
|
const cellSize = 8 + 16 * (1 - params.complexity); // 8-24
|
||||||
|
const cols = Math.floor(canvas.width / cellSize);
|
||||||
|
const rows = Math.floor(canvas.height / cellSize);
|
||||||
|
|
||||||
|
// Grid definition
|
||||||
|
const grid = createEmptyGrid();
|
||||||
|
const nextGrid = createEmptyGrid();
|
||||||
|
|
||||||
|
function createEmptyGrid() {
|
||||||
|
return Array(rows).fill().map(() => Array(cols).fill(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize with density
|
||||||
|
function initializeGrid() {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
grid[y][x] = Math.random() < params.density ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cellular automaton rules
|
||||||
|
const ruleset = [
|
||||||
|
// Classic Conway's B3/S23
|
||||||
|
{ birth: [3], survival: [2, 3] }
|
||||||
|
];
|
||||||
|
|
||||||
|
function nextGeneration() {
|
||||||
|
const rule = ruleset[0];
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
let neighbors = countNeighbors(x, y);
|
||||||
|
|
||||||
|
if (grid[y][x] === 1) {
|
||||||
|
nextGrid[y][x] = rule.survival.includes(neighbors) ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
nextGrid[y][x] = rule.birth.includes(neighbors) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap grids
|
||||||
|
[grid, nextGrid] = [nextGrid, grid];
|
||||||
|
}
|
||||||
|
|
||||||
|
function countNeighbors(x, y) {
|
||||||
|
let count = 0;
|
||||||
|
for (let dy = -1; dy <= 1; dy++) {
|
||||||
|
for (let dx = -1; dx <= 1; dx++) {
|
||||||
|
if (dx === 0 && dy === 0) continue;
|
||||||
|
const nx = x + dx;
|
||||||
|
const ny = y + dy;
|
||||||
|
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows) {
|
||||||
|
count += grid[ny][nx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drawing functions
|
||||||
|
function drawCell(x, y, value) {
|
||||||
|
const hue = 0; // Monochrome
|
||||||
|
const saturation = value === 1 ? '100%' : '0%';
|
||||||
|
const lightness = value === 1 ? '30%' : '10%';
|
||||||
|
const alpha = value === 1 ? 0.8 : 0.2;
|
||||||
|
|
||||||
|
ctx.fillStyle = `hsla(${hue}, ${saturation}, ${lightness}, ${alpha})`;
|
||||||
|
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawGrid() {
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
drawCell(x, y, grid[y][x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animation control
|
||||||
|
let lastTime = 0;
|
||||||
|
let generation = 0;
|
||||||
|
|
||||||
|
function animate(time) {
|
||||||
|
const deltaTime = time - lastTime;
|
||||||
|
lastTime = time;
|
||||||
|
|
||||||
|
if (deltaTime > 1000/60) {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Pulse effect on density
|
||||||
|
const pulseFactor = params.pulse.avg +
|
||||||
|
(Math.random() * 2 - 1) * (params.pulse.max - params.pulse.min) * 0.1;
|
||||||
|
const currentDensity = params.density * pulseFactor;
|
||||||
|
|
||||||
|
// Occasionally reset with current density
|
||||||
|
if (generation % 100 === 0) {
|
||||||
|
initializeGrid();
|
||||||
|
} else {
|
||||||
|
nextGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
drawGrid();
|
||||||
|
generation++;
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start animation
|
||||||
|
initializeGrid();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue