teal-currents-in-quiet-grid.../index.html

127 lines
No EOL
4.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cellular Bloom</title>
<style>
body { margin: 0; overflow: hidden; background: #0a0a0a; }
canvas { display: block; }
#attribution { position: fixed; bottom: 10px; right: 10px; color: #444; font-family: monospace; font-size: 10px; }
</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 derived from generative rules
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: 1.07,
tone: {
anger: 0,
sadness: 0,
curiosity: 0.8,
dryness: 0.9,
playfulness: 0.1,
tension: 0
}
};
// Cellular automaton grid
const cols = Math.floor(canvas.width / 8) + 1;
const rows = Math.floor(canvas.height / 8) + 1;
let grid = new Array(cols).fill().map(() => new Array(rows).fill(0));
let nextGrid = new Array(cols).fill().map(() => new Array(rows).fill(0));
// Initialize with sparse live cells
function initializeGrid() {
const density = params.density * 0.3 + 0.1; // Scale to reasonable density
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
grid[i][j] = Math.random() < density ? 1 : 0;
}
}
}
initializeGrid();
// Game of Life rules with variation
function updateGrid() {
const motionFactor = params.motion * 0.8 + 0.2; // Ensure some movement
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
let neighbors = 0;
for (let di = -1; di <= 1; di++) {
for (let dj = -1; dj <= 1; dj++) {
if (di === 0 && dj === 0) continue;
const ni = (i + di + cols) % cols;
const nj = (j + dj + rows) % rows;
neighbors += grid[ni][nj];
}
}
// Modified rules with randomness based on motion
const birth = 2 + Math.floor(motionFactor * 3);
const survival = 3 + Math.floor(motionFactor * 2);
if (grid[i][j] === 1) {
nextGrid[i][j] = neighbors >= survival || Math.random() < 0.1 * motionFactor ? 1 : 0;
} else {
nextGrid[i][j] = neighbors === birth || Math.random() < 0.05 * motionFactor ? 1 : 0;
}
}
}
[grid, nextGrid] = [nextGrid, grid];
}
// Drawing with teal curiosity tones
function drawGrid() {
const size = 8 * (0.5 + params.density * 0.5); // Vary cell size
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
if (grid[i][j] === 1) {
const hue = 160 + (Math.sin(i * 0.1 + j * 0.1) * 30);
const saturation = 70 + Math.sin(Date.now() * 0.001) * 20;
const vibrancy = params.tone.dryness < 0.5 ?
`hsl(${hue}, ${saturation}%, 60%)` :
`hsl(${hue}, ${saturation}%, ${50 + Math.random() * 10}%)`;
ctx.fillStyle = vibrancy;
ctx.fillRect(i * size, j * size, size, size);
}
}
}
}
// Animation loop
function animate() {
updateGrid();
drawGrid();
requestAnimationFrame(animate);
}
animate();
// Handle clicks to reset
canvas.addEventListener('click', () => {
initializeGrid();
});
</script>
</body>
</html>