pulsing-gray-membranes-i1mv/index.html

237 lines
No EOL
8.1 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 Organism</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#attribution {
position: fixed;
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();
// System parameters
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: {
avg: 1.11,
min: 1.0,
max: 1.2
},
tone: {
anger: 0.0,
sadness: 0.0,
curiosity: 0.0,
dryness: 0.9,
playfulness: 0.0,
tension: 0.0
}
};
// Cell automaton state
const grid = [];
const cellSize = 8;
const cols = Math.floor(canvas.width / cellSize);
const rows = Math.floor(canvas.height / cellSize);
// Initialize grid
for (let y = 0; y < rows; y++) {
grid[y] = [];
for (let x = 0; x < cols; x++) {
// Base state with some initial randomness
grid[y][x] = {
state: Math.random() > 0.5 ? 1 : 0,
nextState: 0,
energy: 0,
lifespan: params.lifespan * 100 + 50,
pulse: params.pulse.avg
};
}
}
// Cellular automaton rules (Life-like with variations)
function updateGrid() {
const neighborOffsets = [
[-1,-1], [-1,0], [-1,1],
[0,-1], [0,1],
[1,-1], [1,0], [1,1]
];
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const cell = grid[y][x];
let liveNeighbors = 0;
// Count live neighbors
for (const [ox, oy] of neighborOffsets) {
const nx = x + ox;
const ny = y + oy;
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows) {
if (grid[ny][nx].state > 0.5) {
liveNeighbors++;
}
}
}
// Determine next state based on params
const birth = params.connectedness > 0.7 ? 3 : 2;
const survive = params.connectedness > 0.7 ? [2,3] : [1,2,3];
const birthProb = params.complexity * 0.5 + 0.3;
const deathProb = 1 - params.lifespan * 0.7;
cell.nextState = cell.state;
if (cell.state > 0.5) {
// Survival
if (survive.includes(liveNeighbors)) {
cell.nextState = 1;
cell.energy += params.motion * 0.05;
} else {
cell.energy *= deathProb;
if (Math.random() < deathProb) {
cell.nextState = 0;
cell.energy = 0;
}
}
} else {
// Birth
if (liveNeighbors >= birth && Math.random() < birthProb) {
cell.nextState = 1;
cell.energy = params.density * 0.5 + 0.3;
}
}
// Energy decay
cell.energy *= 0.98;
// Pulse variation
cell.pulse = params.pulse.avg +
(params.pulse.max - params.pulse.avg) *
Math.sin(Date.now() * 0.001) * 0.1;
}
}
// Update states
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
grid[y][x].state = grid[y][x].nextState;
}
}
}
// Drawing function
function draw() {
const time = Date.now() * 0.001;
const hue = (Math.sin(time * 0.3) * 30 + 180) % 360;
// Clear with semi-transparent overlay for trails
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
let totalEnergy = 0;
let liveCells = 0;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const cell = grid[y][x];
// Track statistics
if (cell.state > 0.5) {
liveCells++;
totalEnergy += cell.energy;
}
if (cell.state > 0.5) {
// Cell is alive
const size = cellSize * (0.5 + cell.energy * 1.5);
const alpha = 0.7 + cell.energy * 0.3;
const adjustedHue = hue + (Math.sin(time + x * 0.1 + y * 0.05) * 10);
ctx.fillStyle = `hsla(${adjustedHue}, 80%, 60%, ${alpha})`;
ctx.beginPath();
ctx.arc(
x * cellSize + cellSize/2,
y * cellSize + cellSize/2,
size * cell.pulse,
0,
Math.PI * 2
);
ctx.fill();
// Draw subtle connections to neighbors
if (params.connectedness > 0.3) {
ctx.strokeStyle = `hsla(${adjustedHue}, 30%, 40%, ${alpha * 0.3})`;
ctx.lineWidth = 0.5 + cell.energy * 0.2;
for (let oy = -1; oy <= 1; oy++) {
for (let ox = -1; ox <= 1; ox++) {
const nx = x + ox;
const ny = y + oy;
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows &&
grid[ny][nx].state > 0.5) {
ctx.beginPath();
ctx.moveTo(
x * cellSize + cellSize/2,
y * cellSize + cellSize/2
);
ctx.lineTo(
nx * cellSize + cellSize/2,
ny * cellSize + cellSize/2
);
ctx.stroke();
}
}
}
}
}
}
}
// Update grid
updateGrid();
}
function animate() {
draw();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>