static-surface-drifting-ujxz/index.html

165 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>Static Surface</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: monospace;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 20px;
color: #555;
font-size: 10px;
text-align: center;
width: 100%;
pointer-events: none;
}
</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 from prompt
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.25, min: 1.0, max: 1.55 },
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
};
// Reaction-diffusion simulation
const size = 100;
const grid = Array(size).fill().map(() =>
Array(size).fill().map(() =>
[Math.random() * 0.1, Math.random() * 0.1]
)
);
const next = Array(size).fill().map(() =>
Array(size).fill().map(() => [0, 0])
);
const feed = 0.055;
const kill = 0.062;
const diffA = 1.0;
const diffB = 0.5;
const dt = 1.0;
function update() {
for (let x = 1; x < size - 1; x++) {
for (let y = 1; y < size - 1; y++) {
const a = grid[x][y][0];
const b = grid[x][y][1];
const laplacianA = (grid[x-1][y][0] + grid[x+1][y][0] +
grid[x][y-1][0] + grid[x][y+1][0] -
4 * a) * diffA;
const laplacianB = (grid[x-1][y][1] + grid[x+1][y][1] +
grid[x][y-1][1] + grid[x][y+1][1] -
4 * b) * diffB;
const reaction = a * b * b;
next[x][y][0] = a + (dt * (laplacianA - reaction));
next[x][y][1] = b + (dt * (laplacianB + reaction));
// Clamping
next[x][y][0] = Math.max(0, Math.min(next[x][y][0], 1));
next[x][y][1] = Math.max(0, Math.min(next[x][y][1], 1));
}
}
// Swap grids
[grid, next].forEach((arr, i) => {
for (let x = 0; x < size; x++) {
for (let y = 0; y < size; y++) {
arr[x][y][0] = next[x][y][0];
arr[x][y][1] = next[x][y][1];
}
}
});
}
function draw() {
const scale = Math.min(canvas.width, canvas.height) / size;
const offsetX = (canvas.width - size * scale) / 2;
const offsetY = (canvas.height - size * scale) / 2;
ctx.fillStyle = '#000000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let x = 0; x < size; x++) {
for (let y = 0; y < size; y++) {
const a = grid[x][y][0];
const b = grid[x][y][1];
if (b > 0.06) { // Only draw when B is sufficiently active
const intensity = Math.min(1, b * 2);
ctx.fillStyle = `rgba(255, 255, 255, ${intensity * 0.8})`;
ctx.beginPath();
ctx.arc(
offsetX + x * scale + scale/2,
offsetY + y * scale + scale/2,
scale * 0.3 * (0.5 + intensity * 0.5),
0, Math.PI * 2
);
ctx.fill();
}
}
}
// Add some structure to the noise
ctx.lineWidth = scale * 0.1;
ctx.strokeStyle = `rgba(200, 200, 200, 0.3)`;
for (let i = 0; i < 50; i++) {
const x1 = Math.floor(Math.random() * size);
const y1 = Math.floor(Math.random() * size);
const x2 = Math.floor(Math.random() * size);
const y2 = Math.floor(Math.random() * size);
ctx.beginPath();
ctx.moveTo(offsetX + x1 * scale + scale/2, offsetY + y1 * scale + scale/2);
ctx.lineTo(offsetX + x2 * scale + scale/2, offsetY + y2 * scale + scale/2);
ctx.stroke();
}
}
function animate() {
update();
draw();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>