teal-echoes-in-the-vortex-6wpo/index.html

191 lines
No EOL
6.4 KiB
HTML

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffusive Organism</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
#canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
color: #555;
font-size: 10px;
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 based on the generative art parameters
const PARAMS = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.08, min: 0.95, max: 1.2 },
tone: { curiosity: 0.7, dryness: 0.9, playfulness: 0.1 }
};
// Reaction-diffusion simulation parameters
const SIM_PARAMS = {
feedRate: 0.055,
killRate: 0.062,
diffusionRateA: 1.0,
diffusionRateB: 0.5,
timeStep: 1.0,
gridSize: 3,
decay: 0.1
};
// Cell states
const grid = {
current: new Array(Math.floor(canvas.width / SIM_PARAMS.gridSize) + 1)
.fill()
.map(() => new Array(Math.floor(canvas.height / SIM_PARAMS.gridSize) + 1).fill(0)),
next: new Array(Math.floor(canvas.width / SIM_PARAMS.gridSize) + 1)
.fill()
.map(() => new Array(Math.floor(canvas.height / SIM_PARAMS.gridSize) + 1).fill(0))
};
// Initialize with sparse patterns
function initializeGrid() {
const cols = grid.current.length;
const rows = grid.current[0].length;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
// Sparse random distribution
if (Math.random() < PARAMS.density * 0.02) {
grid.current[x][y] = Math.random() * 0.5 + 0.5;
} else {
grid.current[x][y] = 0;
}
}
}
}
// Moore neighborhood for reaction-diffusion
function getNeighbors(x, y) {
const neighbors = [];
for (let dx = -1; dx <= 1; dx++) {
for (let dy = -1; dy <= 1; dy++) {
if (dx === 0 && dy === 0) continue;
const nx = (x + dx + grid.current.length) % grid.current.length;
const ny = (y + dy + grid.current[0].length) % grid.current[0].length;
neighbors.push({x: nx, y: ny, distance: Math.sqrt(dx*dx + dy*dy)});
}
}
return neighbors;
}
// Gray-Scott reaction-diffusion equations
function updateSimulation() {
const cols = grid.current.length;
const rows = grid.current[0].length;
const f = SIM_PARAMS.feedRate;
const k = SIM_PARAMS.killRate;
const da = SIM_PARAMS.diffusionRateA;
const db = SIM_PARAMS.diffusionRateB;
const dt = SIM_PARAMS.timeStep;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const a = grid.current[x][y];
const b = 1 - a;
// Reaction terms
const reaction = a * b * b;
// Diffusion (simplified)
const neighbors = getNeighbors(x, y);
let totalDiff = 0;
neighbors.forEach(neighbor => {
totalDiff += grid.current[neighbor.x][neighbor.y] * neighbor.distance;
});
totalDiff /= neighbors.length;
const newA = a + da * totalDiff - reaction + f * (1 - a) * dt;
const newB = b + db * totalDiff + reaction - (k + f) * b * dt;
grid.next[x][y] = Math.max(0, Math.min(1, newA));
}
}
// Swap buffers
[grid.current, grid.next] = [grid.next, grid.current];
}
// Render with teal/cyan palette (curiosity) and reduced contrast (dryness)
function render() {
const cols = grid.current.length;
const rows = grid.current[0].length;
const cellWidth = SIM_PARAMS.gridSize;
const cellHeight = SIM_PARAMS.gridSize;
ctx.fillStyle = 'rgba(10, 15, 20, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const value = grid.current[x][y];
if (value > 0.05) {
const intensity = value * 255;
const teal = Math.min(255, intensity * 1.5);
const alpha = value * 0.3 * PARAMS.pulse.avg;
ctx.fillStyle = `rgba(0, ${teal}, ${teal}, ${alpha})`;
ctx.fillRect(
x * cellWidth,
y * cellHeight,
cellWidth + 1,
cellHeight + 1
);
}
}
}
}
// Animate with pulse variation
function animate() {
const pulseFactor = PARAMS.pulse.avg + (Math.random() * (PARAMS.pulse.max - PARAMS.pulse.min) - PARAMS.pulse.avg) * 0.2;
SIM_PARAMS.feedRate = 0.05 + pulseFactor * 0.005;
SIM_PARAMS.killRate = 0.055 + pulseFactor * 0.007;
updateSimulation();
render();
requestAnimationFrame(animate);
}
// Initialize and start
initializeGrid();
animate();
</script>
</body>
</html>
```