116 lines
No EOL
3.7 KiB
HTML
116 lines
No EOL
3.7 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 meadow</title>
|
|
<style>
|
|
body { margin: 0; overflow: hidden; background: #0a0a0a; }
|
|
canvas { display: block; }
|
|
#info { position: absolute; bottom: 10px; left: 10px; color: #fff; font-family: monospace; font-size: 10px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="c"></canvas>
|
|
<div id="info">neurameba · motd.social</div>
|
|
|
|
<script>
|
|
const canvas = document.getElementById('c');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
function resize() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resize);
|
|
resize();
|
|
|
|
// Grid setup
|
|
const cols = Math.floor(canvas.width / 8);
|
|
const rows = Math.floor(canvas.height / 8);
|
|
const cellSize = 8;
|
|
let grid = new Array(cols * rows).fill(0);
|
|
|
|
// Initialize with organic patterns
|
|
for (let i = 0; i < grid.length; i++) {
|
|
grid[i] = Math.random() < 0.5 ? 1 : 0;
|
|
}
|
|
|
|
// Rules
|
|
const rules = [
|
|
[1, 1, 1, 0, 0, 0, 0, 0, 0], // 0
|
|
[1, 1, 1, 0, 0, 0, 0, 0, 0], // 1
|
|
[1, 1, 1, 1, 1, 1, 0, 0, 0], // 2
|
|
[1, 1, 1, 0, 0, 0, 0, 0, 0], // 3
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0], // 4
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0], // 5
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0], // 6
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0] // 7
|
|
];
|
|
|
|
function update() {
|
|
const nextGrid = new Array(grid.length).fill(0);
|
|
|
|
for (let i = 0; i < grid.length; i++) {
|
|
const col = i % cols;
|
|
const row = Math.floor(i / cols);
|
|
|
|
// Count neighbors
|
|
let neighborCount = 0;
|
|
for (let x = -1; x <= 1; x++) {
|
|
for (let y = -1; y <= 1; y++) {
|
|
const ncol = (col + x + cols) % cols;
|
|
const nrow = (row + y + rows) % rows;
|
|
neighborCount += grid[nrow * cols + ncol];
|
|
}
|
|
}
|
|
neighborCount -= grid[i]; // Subtract self
|
|
|
|
// Apply rule
|
|
nextGrid[i] = rules[Math.min(7, Math.max(0, neighborCount))][neighborCount] ? 1 : 0;
|
|
}
|
|
|
|
grid = nextGrid;
|
|
}
|
|
|
|
function draw() {
|
|
ctx.fillStyle = '#0a0a0a';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
ctx.fillStyle = '#f0f0f0';
|
|
for (let i = 0; i < grid.length; i++) {
|
|
if (grid[i]) {
|
|
const col = i % cols;
|
|
const row = Math.floor(i / cols);
|
|
const x = col * cellSize;
|
|
const y = row * cellSize;
|
|
|
|
// Organic shapes
|
|
ctx.beginPath();
|
|
ctx.arc(x + cellSize/2, y + cellSize/2, cellSize * 0.4, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
|
|
// Add some variation
|
|
const r = Math.random();
|
|
if (r < 0.1) {
|
|
ctx.beginPath();
|
|
ctx.arc(x + cellSize/2 + Math.random() * 2 - 1,
|
|
y + cellSize/2 + Math.random() * 2 - 1,
|
|
cellSize * 0.2, 0, Math.PI * 2);
|
|
ctx.fillStyle = '#d0d0d0';
|
|
ctx.fill();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function animate() {
|
|
update();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |