mossed-pulse-in-grids-o7yx/index.html

167 lines
No EOL
5.3 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 Mutation</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
#canvas {
display: block;
width: 100vw;
height: 100vh;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #444444;
font-size: 10px;
text-align: right;
}
</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');
// Set canvas to full window size
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Simulation parameters
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.11, min: 0.9, max: 1.3 },
tone: {
anger: 0.0,
sadness: 0.0,
curiosity: 0.7,
dryness: 0.8,
playfulness: 0.1,
tension: 0.0
}
};
// Derived quantities
const cellSize = Math.max(2, 10 - params.density * 8);
const cols = Math.floor(canvas.width / cellSize);
const rows = Math.floor(canvas.height / cellSize);
const grid = Array(rows).fill().map(() => Array(cols).fill(0));
const nextGrid = Array(rows).fill().map(() => Array(cols).fill(0));
// Colors based on tone parameters
const baseColor = params.tone.dryness > 0.5 ?
'rgba(200, 220, 150, 0.8)' :
`hsl(${200 + params.tone.curiosity * 80}, 70%, 70%)`;
// Initialize grid with some noise
function initializeGrid() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
grid[y][x] = Math.random() < 0.3 ? 1 : 0;
}
}
}
// Cellular automaton rules
function updateGrid() {
const liveNeighbors = (x, y) => {
let count = 0;
for (let ny = -1; ny <= 1; ny++) {
for (let nx = -1; nx <= 1; nx++) {
if (nx === 0 && ny === 0) continue;
const px = (x + nx + cols) % cols;
const py = (y + ny + rows) % rows;
count += grid[py][px];
}
}
return count;
};
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const neighbors = liveNeighbors(x, y);
const cell = grid[y][x];
// Modified Conway's Game of Life with mutation chance
if (cell === 1) {
nextGrid[y][x] = (neighbors === 2 || neighbors === 3) ? 1 : 0;
} else {
nextGrid[y][x] = neighbors >= 3 ? 1 : 0;
}
// Add some random mutation
if (Math.random() < 0.005 * params.complexity) {
nextGrid[y][x] = 1;
}
}
}
// Swap grids
[grid, nextGrid] = [nextGrid, grid];
}
// Drawing function
function drawGrid() {
ctx.fillStyle = '#0a0a0a80';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = baseColor;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
if (grid[y][x] === 1) {
const px = x * cellSize;
const py = y * cellSize;
const pulseFactor = params.pulse.avg + Math.sin(Date.now() * 0.001) * 0.15;
// Vary size based on motion and lifespan
const size = cellSize * (0.5 + 0.5 * params.motion) * pulseFactor;
contextAlpha = params.lifespan > 0.5 ? 0.9 : 0.7;
ctx.globalAlpha = contextAlpha;
ctx.beginPath();
ctx.arc(
px + cellSize/2,
py + cellSize/2,
size/2,
0,
Math.PI * 2
);
ctx.fill();
ctx.globalAlpha = 1;
}
}
}
}
// Animation loop
function animate() {
updateGrid();
drawGrid();
requestAnimationFrame(animate);
}
// Start simulation
initializeGrid();
animate();
</script>
</body>
</html>