birth: Pulsing Life Fragments
This commit is contained in:
parent
b05f3a0ed2
commit
44ff7df104
1 changed files with 184 additions and 0 deletions
184
index.html
Normal file
184
index.html
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<!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;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
canvas {
|
||||
flex: 1;
|
||||
}
|
||||
.attribution {
|
||||
color: #555;
|
||||
text-align: center;
|
||||
font-family: monospace;
|
||||
font-size: 10px;
|
||||
padding: 8px;
|
||||
background: rgba(0,0,0,0.3);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div class="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();
|
||||
|
||||
// Configuration based on parameters
|
||||
const config = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
tone: {
|
||||
dryness: 0.9,
|
||||
curiosity: 0.1
|
||||
},
|
||||
pulse: {
|
||||
avg: 1.07,
|
||||
min: 1.0,
|
||||
max: 1.1
|
||||
}
|
||||
};
|
||||
|
||||
// Cellular automata grid
|
||||
const gridSize = Math.min(100, Math.max(40, 100 * config.density));
|
||||
const cellSize = Math.max(2, Math.min(8, 8 * config.complexity));
|
||||
const cols = Math.floor(canvas.width / cellSize);
|
||||
const rows = Math.floor(canvas.height / cellSize);
|
||||
|
||||
// State variables
|
||||
let grid = createEmptyGrid();
|
||||
let nextGrid = createEmptyGrid();
|
||||
let generation = 0;
|
||||
let pulseTimer = 0;
|
||||
let pulseDirection = 1;
|
||||
|
||||
// Color scheme based on tone
|
||||
const colors = {
|
||||
background: '#0a0a0a',
|
||||
alive: `hsl(180, 80%, ${50 + Math.sin(Date.now() * 0.001) * 10}%)`,
|
||||
dead: '#111',
|
||||
highlight: `hsl(180, 50%, ${80 + Math.sin(Date.now() * 0.0015) * 5}%)`
|
||||
};
|
||||
|
||||
// Initialize grid
|
||||
function createEmptyGrid() {
|
||||
return Array(rows).fill().map(() =>
|
||||
Array(cols).fill().map(() => Math.random() > 0.85 ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
// Game of Life-like rules with adjustments
|
||||
function updateGrid() {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const neighbors = countNeighbors(x, y);
|
||||
|
||||
// Modified rules based on parameters
|
||||
if (grid[y][x] === 1) {
|
||||
// Survival with probability based on motion/connectivity
|
||||
nextGrid[y][x] = (neighbors >= 2 && neighbors <= 4) ?
|
||||
(Math.random() > (0.3 - config.motion * 0.15) ? 1 : 0) : 0;
|
||||
} else {
|
||||
// Birth with probability based on density/complexity
|
||||
nextGrid[y][x] = (neighbors === 3) ?
|
||||
(Math.random() > (0.4 - config.complexity * 0.2) ? 1 : 0) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
generation++;
|
||||
}
|
||||
|
||||
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 + cols) % cols;
|
||||
const ny = (y + dy + rows) % rows;
|
||||
count += grid[ny][nx];
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
// Update pulse effect
|
||||
pulseTimer += 0.01 * pulseDirection;
|
||||
if (pulseTimer > 1) {
|
||||
pulseTimer = 1;
|
||||
pulseDirection = -1;
|
||||
} else if (pulseTimer < 0.9) {
|
||||
pulseTimer = 0.9;
|
||||
pulseDirection = 1;
|
||||
}
|
||||
|
||||
// Update grid based on motion parameter
|
||||
const updateRate = 1 + config.motion * 2;
|
||||
if (generation % Math.floor(10 / updateRate) === 0) {
|
||||
updateGrid();
|
||||
}
|
||||
|
||||
// Draw
|
||||
ctx.fillStyle = colors.background;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw cells with variable size based on complexity
|
||||
const cellVariation = 0.5 + config.complexity * 0.5;
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
if (grid[y][x]) {
|
||||
const size = cellSize * (0.8 + Math.sin(x * 0.1) * cellVariation * 0.2) *
|
||||
(0.9 + Math.sin(y * 0.1 + Date.now() * 0.001) * cellVariation * 0.1);
|
||||
|
||||
// Color variation based on pulse
|
||||
const hue = 180 + Math.sin(Date.now() * 0.002) * 20;
|
||||
const saturation = 70 + Math.sin(x * 0.05) * 20;
|
||||
const lightness = 40 + pulseTimer * 10;
|
||||
|
||||
ctx.fillStyle = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||
ctx.fillRect(x * cellSize, y * cellSize, size, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight random cells based on connectedness
|
||||
if (Math.random() < config.connectedness * 0.1) {
|
||||
const x = Math.floor(Math.random() * cols);
|
||||
const y = Math.floor(Math.random() * rows);
|
||||
const size = cellSize * 1.5;
|
||||
ctx.fillStyle = colors.highlight;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x * cellSize + cellSize/2, y * cellSize + cellSize/2, size/2, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue