birth: Static Fields in Motion
This commit is contained in:
parent
be33fa4f96
commit
f05d5e6553
1 changed files with 139 additions and 0 deletions
139
index.html
Normal file
139
index.html
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Static Fields</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
color: #f0f0f0;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
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 cols = Math.floor(canvas.width * 0.02);
|
||||
const rows = Math.floor(canvas.height * 0.02);
|
||||
const cellSize = Math.min(canvas.width / cols, canvas.height / rows);
|
||||
|
||||
// CA grid and state
|
||||
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 pattern based on parameters
|
||||
function initGrid() {
|
||||
for (let i = 0; i < cols; i++) {
|
||||
for (let j = 0; j < rows; j++) {
|
||||
// Density parameter affects initial state
|
||||
grid[i][j] = Math.random() < 0.3 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CA rules with variation based on parameters
|
||||
function computeCell(i, j) {
|
||||
let sum = 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;
|
||||
sum += grid[ni][nj];
|
||||
}
|
||||
}
|
||||
|
||||
// Conway's Game of Life with mutation based on complexity
|
||||
if (grid[i][j] === 1) {
|
||||
nextGrid[i][j] = (sum === 2 || sum === 3) ? 1 : 0;
|
||||
} else {
|
||||
nextGrid[i][j] = (sum === 3) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Add some random mutation based on complexity
|
||||
if (Math.random() < 0.01 * 0.5) {
|
||||
nextGrid[i][j] = 1 - nextGrid[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// Drawing with dryness parameter
|
||||
function drawCell(i, j) {
|
||||
if (grid[i][j] === 0) return;
|
||||
|
||||
const x = i * cellSize;
|
||||
const y = j * cellSize;
|
||||
const size = cellSize * 0.8;
|
||||
|
||||
// Dryness makes everything monochrome
|
||||
ctx.fillStyle = `hsl(0, 0%, ${Math.random() * 30 + 10}%)`;
|
||||
ctx.fillRect(x + cellSize * 0.1, y + cellSize * 0.1, size, size);
|
||||
}
|
||||
|
||||
// Animation with pulse
|
||||
let pulse = 1.05;
|
||||
let pulseDir = -0.01;
|
||||
|
||||
function animate() {
|
||||
// Update pulse
|
||||
pulse += pulseDir;
|
||||
if (pulse > 1.10) pulseDir = -0.01;
|
||||
if (pulse < 1.00) pulseDir = 0.01;
|
||||
|
||||
// Clear with dark background
|
||||
ctx.fillStyle = '#0a0a0a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update cellular automata
|
||||
for (let i = 0; i < cols; i++) {
|
||||
for (let j = 0; j < rows; j++) {
|
||||
computeCell(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
|
||||
// Draw cells
|
||||
for (let i = 0; i < cols; i++) {
|
||||
for (let j = 0; j < rows; j++) {
|
||||
drawCell(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initGrid();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue