144 lines
No EOL
4.4 KiB
HTML
144 lines
No EOL
4.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Neurameba Cellular Dynamics</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background-color: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
color: #ccc;
|
|
}
|
|
#canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
font-size: 10px;
|
|
opacity: 0.5;
|
|
}
|
|
</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();
|
|
|
|
// Cellular automata parameters
|
|
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: { dryness: 0.7, playfulness: 0.1 },
|
|
width: canvas.width,
|
|
height: canvas.height
|
|
};
|
|
|
|
// State
|
|
const cells = [];
|
|
const states = [];
|
|
const palette = ['#ffffff', '#cccccc', '#999999'];
|
|
const cellSize = 8;
|
|
const cols = Math.floor(canvas.width / cellSize);
|
|
const rows = Math.floor(canvas.height / cellSize);
|
|
|
|
// Initialize cells
|
|
function init() {
|
|
for (let i = 0; i < cols * rows; i++) {
|
|
cells[i] = Math.random() > 0.5 ? 1 : 0;
|
|
states[i] = {
|
|
lifespan: Math.random(),
|
|
pulse: 1.0,
|
|
energy: Math.random() * 0.5 + 0.5
|
|
};
|
|
}
|
|
}
|
|
|
|
// Update cell states
|
|
function update() {
|
|
for (let i = 0; i < cols; i++) {
|
|
for (let j = 0; j < rows; j++) {
|
|
const idx = j * cols + i;
|
|
const neighbors = countNeighbors(i, j);
|
|
|
|
// Simple rules with some randomness based on parameters
|
|
if (cells[idx] === 1) {
|
|
if (neighbors < 2 || neighbors > 3) {
|
|
cells[idx] = 0;
|
|
}
|
|
} else {
|
|
if (neighbors === 3 && Math.random() > 0.7) {
|
|
cells[idx] = 1;
|
|
}
|
|
}
|
|
|
|
// Apply pulse variation
|
|
states[idx].pulse = params.pulse.avg +
|
|
(params.pulse.max - params.pulse.min) *
|
|
(Math.sin(Date.now() * 0.001 * params.pulse.avg) * 0.5 + 0.5);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Count live neighbors
|
|
function countNeighbors(x, y) {
|
|
let count = 0;
|
|
for (let i = -1; i <= 1; i++) {
|
|
for (let j = -1; j <= 1; j++) {
|
|
if (i === 0 && j === 0) continue;
|
|
const nx = x + i;
|
|
const ny = y + j;
|
|
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows && cells[ny * cols + nx] === 1) {
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
// Draw cells
|
|
function draw() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
for (let i = 0; i < cols; i++) {
|
|
for (let j = 0; j < rows; j++) {
|
|
const idx = j * cols + i;
|
|
if (cells[idx] === 1) {
|
|
const energy = states[idx].energy * states[idx].pulse;
|
|
ctx.fillStyle = palette[Math.floor(energy * (palette.length - 1))];
|
|
ctx.fillRect(i * cellSize, j * cellSize, cellSize, cellSize);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
update();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
init();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |