152 lines
No EOL
4.9 KiB
HTML
152 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>Dry Diffusion</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
#canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #333;
|
|
font-size: 10px;
|
|
pointer-events: none;
|
|
mix-blend-mode: difference;
|
|
}
|
|
</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');
|
|
|
|
// Set canvas to full window size
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
// Parameters derived from generative art builder
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.05, min: 1.0, max: 1.1 },
|
|
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
|
|
};
|
|
|
|
// Reaction-diffusion simulation
|
|
const size = Math.min(100, params.density * 200);
|
|
const grid = Array.from({ length: size }, () =>
|
|
Array.from({ length: size }, () => ({
|
|
a: Math.random() * 0.1 + 0.05,
|
|
b: Math.random() * 0.1,
|
|
oldA: 0,
|
|
oldB: 0
|
|
}))
|
|
);
|
|
|
|
// Center of the grid
|
|
const center = Math.floor(size / 2);
|
|
|
|
function simulate() {
|
|
for (let y = 1; y < size - 1; y++) {
|
|
for (let x = 1; x < size - 1; x++) {
|
|
const cell = grid[y][x];
|
|
const neighbors = [
|
|
grid[y-1][x], grid[y+1][x],
|
|
grid[y][x-1], grid[y][x+1],
|
|
grid[y-1][x-1], grid[y-1][x+1],
|
|
grid[y+1][x-1], grid[y+1][x+1]
|
|
];
|
|
|
|
// Calculate averages
|
|
let sumA = 0, sumB = 0;
|
|
neighbors.forEach(neighbor => {
|
|
sumA += neighbor.a;
|
|
sumB += neighbor.b;
|
|
});
|
|
const avgA = sumA / neighbors.length;
|
|
const avgB = sumB / neighbors.length;
|
|
|
|
// Reaction-diffusion equations
|
|
const reaction = cell.a * cell.b * cell.b;
|
|
const feed = 0.055;
|
|
const kill = 0.062;
|
|
const diffA = 1.0;
|
|
const diffB = 0.5;
|
|
|
|
cell.oldA = cell.a;
|
|
cell.oldB = cell.b;
|
|
|
|
cell.a += (diffA * (avgA - cell.a) - reaction + feed * (1 - cell.a)) * params.motion;
|
|
cell.b += (diffB * (avgB - cell.b) + reaction - (feed + kill) * cell.b) * params.motion;
|
|
}
|
|
}
|
|
|
|
// Update grid
|
|
for (let y = 1; y < size - 1; y++) {
|
|
for (let x = 1; x < size - 1; x++) {
|
|
const cell = grid[y][x];
|
|
cell.a = cell.oldA;
|
|
cell.b = cell.oldB;
|
|
}
|
|
}
|
|
}
|
|
|
|
function draw() {
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.01)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
const scale = Math.min(canvas.width, canvas.height) / size;
|
|
const offsetX = (canvas.width - size * scale) / 2;
|
|
const offsetY = (canvas.height - size * scale) / 2;
|
|
|
|
for (let y = 1; y < size - 1; y++) {
|
|
for (let x = 1; x < size - 1; x++) {
|
|
const cell = grid[y][x];
|
|
const a = Math.pow(cell.a, 0.2 + params.tone.dryness * 0.8);
|
|
const b = Math.pow(cell.b, 0.2);
|
|
|
|
// Dryness creates monochrome patterns
|
|
const value = Math.min(1, (a - b * 0.5) * 2);
|
|
const gray = Math.floor(255 * value);
|
|
|
|
ctx.fillStyle = `rgb(${gray}, ${gray}, ${gray})`;
|
|
ctx.fillRect(
|
|
offsetX + x * scale,
|
|
offsetY + y * scale,
|
|
scale * 0.9,
|
|
scale * 0.9
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
function animate() {
|
|
simulate();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |