birth: Diffusive Monochrome Flows
This commit is contained in:
parent
91a983ca40
commit
37f7cb4a9b
1 changed files with 136 additions and 0 deletions
136
index.html
Normal file
136
index.html
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Diffusive Chaos</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #000;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
#attribution {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
color: #444;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: center;
|
||||||
|
width: 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');
|
||||||
|
|
||||||
|
// Set canvas to full window size
|
||||||
|
function resizeCanvas() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
|
||||||
|
// Parameters from generative art builder
|
||||||
|
const motion = 0.5;
|
||||||
|
const density = 0.5;
|
||||||
|
const complexity = 0.5;
|
||||||
|
const connectedness = 0.5;
|
||||||
|
const lifespan = 0.5;
|
||||||
|
const pulse = { avg: 1.05, min: 1.0, max: 1.1 };
|
||||||
|
const tone = { dryness: 0.9 };
|
||||||
|
|
||||||
|
// Reaction-diffusion parameters
|
||||||
|
const params = {
|
||||||
|
feed: 0.055 + complexity * 0.02,
|
||||||
|
kill: 0.062 - complexity * 0.02,
|
||||||
|
resolution: 1 + Math.floor(10 * density),
|
||||||
|
iterations: 1 + Math.floor(5 * complexity),
|
||||||
|
diffusion: 0.1 + motion * 0.1,
|
||||||
|
timeScale: 0.1 + motion * 0.2
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create grids
|
||||||
|
const width = Math.floor(canvas.width / params.resolution);
|
||||||
|
const height = Math.floor(canvas.height / params.resolution);
|
||||||
|
const grid = new Array(width * height).fill(1);
|
||||||
|
const next = new Array(width * height).fill(1);
|
||||||
|
|
||||||
|
// Initialize with sparse spots
|
||||||
|
const spots = Math.floor(density * width * height * 0.1);
|
||||||
|
for (let i = 0; i < spots; i++) {
|
||||||
|
const idx = Math.floor(Math.random() * width * height);
|
||||||
|
grid[idx] = Math.random();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Palette (monochrome for dryness)
|
||||||
|
const palette = {
|
||||||
|
getColor: (v) => `hsl(0, 0%, ${20 + v * 60}%)`
|
||||||
|
};
|
||||||
|
|
||||||
|
// Animation loop
|
||||||
|
function animate(timestamp) {
|
||||||
|
// Pulse effect
|
||||||
|
const pulseFactor = pulse.min + (pulse.max - pulse.min) *
|
||||||
|
(0.5 + 0.5 * Math.sin(timestamp * 0.001 * pulse.avg));
|
||||||
|
|
||||||
|
// Reaction-diffusion steps
|
||||||
|
for (let iter = 0; iter < params.iterations; iter++) {
|
||||||
|
for (let x = 1; x < width - 1; x++) {
|
||||||
|
for (let y = 1; y < height - 1; y++) {
|
||||||
|
const idx = x + y * width;
|
||||||
|
const a = grid[idx - width - 1] * params.diffusion;
|
||||||
|
const b = grid[idx] * params.diffusion;
|
||||||
|
const c = grid[idx + width + 1] * params.diffusion;
|
||||||
|
const d = grid[idx - 1] * params.diffusion;
|
||||||
|
const e = grid[idx + 1] * params.diffusion;
|
||||||
|
|
||||||
|
const laplacianA = (a + b + c + d + e) - 5 * grid[idx];
|
||||||
|
|
||||||
|
const feedRate = params.feed * (1 - grid[idx]);
|
||||||
|
const killRate = params.kill / (1 + grid[d - 1] * 10);
|
||||||
|
|
||||||
|
next[idx] = grid[idx] + (params.timeScale * pulseFactor) *
|
||||||
|
(feedRate * laplacianA - killRate - grid[idx] * next[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[grid, next] = [next, grid];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render
|
||||||
|
ctx.fillStyle = '#000';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
const cellWidth = canvas.width / width;
|
||||||
|
const cellHeight = canvas.height / height;
|
||||||
|
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
const idx = x + y * width;
|
||||||
|
const value = Math.min(1, Math.max(0, (grid[idx] - 0.5) * 2));
|
||||||
|
ctx.fillStyle = palette.getColor(value);
|
||||||
|
ctx.fillRect(
|
||||||
|
x * cellWidth,
|
||||||
|
y * cellHeight,
|
||||||
|
cellWidth,
|
||||||
|
cellHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue