161 lines
No EOL
5.4 KiB
HTML
161 lines
No EOL
5.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>Cellular Drift</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #444;
|
|
font-size: 10px;
|
|
text-shadow: 0 0 5px #222;
|
|
}
|
|
</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();
|
|
|
|
// Parameters derived from generative art system
|
|
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: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.8, playfulness: 0.1, tension: 0.0 }
|
|
};
|
|
|
|
// Cell settings
|
|
const cellSize = 20;
|
|
const cols = Math.floor(canvas.width / cellSize);
|
|
const rows = Math.floor(canvas.height / cellSize);
|
|
const grid = Array(rows).fill().map(() => Array(cols).fill(0));
|
|
|
|
// Initialize with some "alive" cells based on density
|
|
function initGrid() {
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
grid[y][x] = Math.random() < params.density ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Cellular automata rules
|
|
function updateGrid() {
|
|
const newGrid = grid.map(arr => [...arr]);
|
|
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
let neighbors = 0;
|
|
|
|
// Count 8 neighbors
|
|
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) {
|
|
neighbors += grid[ny][nx];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Modified Game of Life rules with motion influence
|
|
const motionFactor = params.motion * 2;
|
|
if (grid[y][x] === 1) {
|
|
// Survival: stay alive if enough neighbors, but with some randomness
|
|
newGrid[y][x] = (neighbors >= 2 - motionFactor && neighbors <= 3 + motionFactor) ? 1 : 0;
|
|
} else {
|
|
// Birth: come to life if exactly 3 neighbors, with some randomness
|
|
newGrid[y][x] = (neighbors === 3) ? (Math.random() < 0.3 ? 1 : 0) : 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
return newGrid;
|
|
}
|
|
|
|
// Drawing function
|
|
function drawGrid() {
|
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.1)';
|
|
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
if (grid[y][x]) {
|
|
const lifeRatio = params.lifespan;
|
|
const brightness = lifeRatio * 0.7 + 0.3;
|
|
|
|
ctx.fillStyle = `rgba(255, 255, 255, ${brightness})`;
|
|
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
// Update grid based on pulse
|
|
const pulseFactor = params.pulse.avg * (1 + Math.sin(Date.now() * 0.001) * 0.1);
|
|
|
|
// Occasionally reset or nudge the grid
|
|
if (Math.random() < 0.05) {
|
|
// Add some random alive cells based on motion
|
|
const addCount = Math.floor(params.density * 5 * pulseFactor);
|
|
for (let i = 0; i < addCount; i++) {
|
|
const x = Math.floor(Math.random() * cols);
|
|
const y = Math.floor(Math.random() * rows);
|
|
grid[y][x] = 1;
|
|
}
|
|
}
|
|
|
|
const newGrid = updateGrid();
|
|
// Flicker effect based on motion
|
|
if (Math.random() < params.motion * 0.03) {
|
|
grid.forEach((row, y) => {
|
|
row.forEach((cell, x) => {
|
|
if (Math.random() < 0.5) {
|
|
newGrid[y][x] = cell;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
grid.length = 0;
|
|
newGrid.forEach(row => grid.push([...row]));
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
drawGrid();
|
|
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
initGrid();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |