164 lines
No EOL
4.9 KiB
HTML
164 lines
No EOL
4.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Diffuse Echoes</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: monospace;
|
|
color: #4a4a4a;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
font-size: 10px;
|
|
color: #333;
|
|
}
|
|
</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
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.12, min: 0.9, max: 1.3 },
|
|
tone: {
|
|
anger: 0.0,
|
|
sadness: 0.0,
|
|
curiosity: 0.7,
|
|
dryness: 0.9,
|
|
playfulness: 0.1,
|
|
tension: 0.0
|
|
}
|
|
};
|
|
|
|
// Reaction-diffusion simulation
|
|
const W = canvas.width;
|
|
const H = canvas.height;
|
|
const size = 4;
|
|
const cols = Math.floor(W / size);
|
|
const rows = Math.floor(H / size);
|
|
|
|
let current, next;
|
|
|
|
// Initialize grids
|
|
function initGrids() {
|
|
current = new Array(cols * rows).fill(0);
|
|
next = new Array(cols * rows).fill(0);
|
|
|
|
// Add random seed points
|
|
const seedCount = Math.floor(params.density * 50) + 10;
|
|
for (let i = 0; i < seedCount; i++) {
|
|
const x = Math.floor(Math.random() * cols);
|
|
const y = Math.floor(Math.random() * rows);
|
|
current[y * cols + x] = 1;
|
|
}
|
|
}
|
|
|
|
// Gray-Scott reaction diffusion
|
|
function updateGrids() {
|
|
const F = 0.055 + params.motion * 0.02;
|
|
const k = 0.06 + params.connectedness * 0.04;
|
|
const timeScale = 0.15;
|
|
|
|
for (let y = 1; y < rows - 1; y++) {
|
|
for (let x = 1; x < cols - 1; x++) {
|
|
const i = y * cols + x;
|
|
const u = current[i];
|
|
const v = next[i];
|
|
|
|
// Diffusion
|
|
let sumU = 0, sumV = 0;
|
|
for (let dy = -1; dy <= 1; dy++) {
|
|
for (let dx = -1; dx <= 1; dx++) {
|
|
const ni = (y + dy) * cols + (x + dx);
|
|
sumU += current[ni];
|
|
sumV += next[ni];
|
|
}
|
|
}
|
|
sumU /= 9;
|
|
sumV /= 9;
|
|
|
|
// React
|
|
const newV = v +
|
|
(u * v * v * timeScale) -
|
|
(k * v) +
|
|
(0.125 * params.complexity * (sumV - v));
|
|
|
|
next[i] = Math.min(Math.max(newV, 0), 1);
|
|
}
|
|
}
|
|
|
|
// Swap buffers
|
|
[current, next] = [next, current];
|
|
}
|
|
|
|
// Drawing
|
|
function draw() {
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
const hue = 170 + Math.sin(Date.now() * 0.001) * 20; // Teal-ish
|
|
const saturation = 80 + params.tone.curiosity * 20;
|
|
const brightness = 50 + params.motion * 20;
|
|
|
|
for (let y = 0; y < rows; y++) {
|
|
for (let x = 0; x < cols; x++) {
|
|
const i = y * cols + x;
|
|
const val = current[i];
|
|
|
|
if (val > 0.01) {
|
|
const alpha = val * 0.8;
|
|
const size = params.density * 3 + 1;
|
|
ctx.fillStyle = `hsla(${hue}, ${saturation}%, ${brightness}%, ${alpha})`;
|
|
ctx.beginPath();
|
|
ctx.arc(
|
|
x * size + size/2,
|
|
y * size + size/2,
|
|
size * 0.5 * params.motion * 1.5,
|
|
0,
|
|
Math.PI * 2
|
|
);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
updateGrids();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
initGrids();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |