birth: Dry Echoes of Divided Cells
This commit is contained in:
parent
f06f413ce3
commit
869097be7a
1 changed files with 138 additions and 0 deletions
138
index.html
Normal file
138
index.html
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Cellular Flux</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
text-align: center;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="c"></canvas>
|
||||
<div id="attribution">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();
|
||||
|
||||
// Cellular automata parameters
|
||||
const size = 8;
|
||||
const cols = Math.floor(canvas.width / size);
|
||||
const rows = Math.floor(canvas.height / size);
|
||||
let grid = new Array(rows).fill().map(() => new Array(cols).fill(0));
|
||||
let nextGrid = new Array(rows).fill().map(() => new Array(cols).fill(0));
|
||||
|
||||
// Initialize with density parameter
|
||||
function initGrid() {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
grid[y][x] = Math.random() < 0.5 * (0.2 + 0.8 * 0.5) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
initGrid();
|
||||
|
||||
// Complexity rules
|
||||
function calculateNeighbors(x, y) {
|
||||
let sum = 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) {
|
||||
sum += grid[ny][nx];
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
function updateGrid() {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const neighbors = calculateNeighbors(x, y);
|
||||
const cell = grid[y][x];
|
||||
|
||||
// High complexity rules
|
||||
if (cell === 1) {
|
||||
nextGrid[y][x] = neighbors > 1 && neighbors < 5 ? 1 : 0;
|
||||
} else {
|
||||
nextGrid[y][x] = neighbors === 3 || neighbors === 5 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
}
|
||||
|
||||
// Drawing with motion parameter
|
||||
function draw() {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.fillStyle = '#fff';
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
if (grid[y][x] === 1) {
|
||||
// Motion variation (0.5)
|
||||
const offsetX = (Math.random() - 0.5) * 2 * 0.5;
|
||||
const offsetY = (Math.random() - 0.5) * 2 * 0.5;
|
||||
ctx.fillRect(
|
||||
x * size + offsetX,
|
||||
y * size + offsetY,
|
||||
size * 0.8,
|
||||
size * 0.8
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
updateGrid();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
animate();
|
||||
|
||||
// Handle clicks to perturb
|
||||
canvas.addEventListener('click', (e) => {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const x = Math.floor((e.clientX - rect.left) / size);
|
||||
const y = Math.floor((e.clientY - rect.top) / size);
|
||||
if (x >= 0 && x < cols && y >= 0 && y < rows) {
|
||||
grid[y][x] = 1;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue