132 lines
No EOL
3.8 KiB
HTML
132 lines
No EOL
3.8 KiB
HTML
```html
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Cellular Nebula</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a1a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #555;
|
|
font-size: 10px;
|
|
text-shadow: 0 0 5px rgba(0,0,0,0.5);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="canvas"></canvas>
|
|
<div id="attribution">neurameba · motd.social</div>
|
|
<script>
|
|
const canvas = document.getElementById('canvas');
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
const palette = [
|
|
'#1a237e',
|
|
'#303f9f',
|
|
'#3f51b5',
|
|
'#5c6bc0',
|
|
'#7986cb',
|
|
'#9575cd',
|
|
'#b39ddb',
|
|
'#d1c4e9',
|
|
'#e8eaf6'
|
|
];
|
|
|
|
const GRID_SIZE = 3;
|
|
const cols = Math.floor(canvas.width / GRID_SIZE);
|
|
const rows = Math.floor(canvas.height / GRID_SIZE);
|
|
let grid = createEmptyGrid();
|
|
|
|
function createEmptyGrid() {
|
|
return Array(rows).fill().map(() => Array(cols).fill(0));
|
|
}
|
|
|
|
function initializeGrid() {
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
grid[y][x] = Math.random() > 0.7 ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
function updateGrid() {
|
|
const newGrid = createEmptyGrid();
|
|
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
const neighbors = countNeighbors(x, y);
|
|
|
|
// Conway's Game of Life with variations
|
|
if (grid[y][x] === 1) {
|
|
newGrid[y][x] = neighbors >= 2 && neighbors <= 4 ? 1 : 0;
|
|
} else {
|
|
newGrid[y][x] = neighbors === 3 ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
grid = newGrid;
|
|
}
|
|
|
|
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 && grid[ny][nx] === 1) {
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
function drawGrid() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
if (grid[y][x] === 1) {
|
|
const hue = 220 + (Math.sin(x * 0.1) * 30);
|
|
const saturation = 70 + (Math.sin(y * 0.1) * 20);
|
|
const lightness = 50 + (Math.sin(x * 0.05 + y * 0.05) * 10);
|
|
|
|
ctx.fillStyle = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
|
ctx.fillRect(x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE, GRID_SIZE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function animate() {
|
|
updateGrid();
|
|
drawGrid();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
initializeGrid();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
``` |