fading-echoes-of-structure-.../index.html

170 lines
No EOL
5.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dissolution Protocol</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
background: #000;
height: 100%;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #333;
font-size: 10px;
z-index: 100;
}
</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();
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.03, min: 0.8, max: 1.2 },
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.9, playfulness: 0, tension: 0 }
};
const gridSize = 30;
const cols = Math.floor(canvas.width / gridSize);
const rows = Math.floor(canvas.height / gridSize);
let grid = createGrid();
let nextGrid = createGrid();
function createGrid() {
const g = [];
const totalCells = cols * rows;
const aliveCount = Math.floor(totalCells * params.density * 0.7);
for (let i = 0; i < rows; i++) {
g[i] = [];
for (let j = 0; j < cols; j++) {
g[i][j] = Math.random() < (params.density * 0.7) ? 1 : 0;
}
}
// Initialize with some pattern
for (let i = 0; i < aliveCount; i++) {
const x = Math.floor(Math.random() * cols);
const y = Math.floor(Math.random() * rows);
if (Math.random() < 0.3) {
g[y][x] = 2; // Special state
}
}
return g;
}
function updateGrid() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const currentState = grid[y][x];
if (currentState === 0) {
// Resurrection based on pulse
if (Math.random() < (params.pulse.avg * 0.005)) {
nextGrid[y][x] = 1;
} else {
nextGrid[y][x] = 0;
}
} else {
// Update based on CA rules
let neighbors = countNeighbors(x, y);
if (currentState === 1) {
// Simple life/death
nextGrid[y][x] = (neighbors === 2 || neighbors === 3) ? 1 : 0;
} else if (currentState === 2) {
// Special state that creates complexity
nextGrid[y][x] = (neighbors < 2 || neighbors > 3) ? 0 : 2;
}
}
}
}
// Swap grids
[grid, nextGrid] = [nextGrid, createGrid()];
}
function countNeighbors(x, y) {
let count = 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) {
count += grid[ny][nx] > 0 ? 1 : 0;
}
}
}
return count;
}
function draw() {
ctx.fillStyle = `rgba(0, 0, 0, ${0.1 + (1 - params.tone.dryness) * 0.1})`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const pulseScale = params.pulse.avg;
const cellSize = gridSize * pulseScale;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
if (grid[y][x] > 0) {
const state = grid[y][x];
const hue = state === 1 ? 0 : 200; // Red/Blue based on state
const saturation = 50 + Math.sin(Date.now() * 0.001) * 30;
const value = 50 + state * 20;
const alpha = 0.7 + Math.sin(x * 0.1 + y * 0.1 + Date.now() * 0.002) * 0.3;
ctx.fillStyle = `hsla(${hue}, ${saturation}%, ${value}%, ${alpha})`;
ctx.beginPath();
ctx.arc(
x * gridSize + gridSize/2,
y * gridSize + gridSize/2,
cellSize/2 * (0.3 + state * 0.4),
0, Math.PI * 2
);
ctx.fill();
}
}
}
if (Math.random() < params.motion * 0.01) {
updateGrid();
}
}
function animate() {
draw();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>