birth: Turbulent Diffusion Dreams
This commit is contained in:
parent
d8a930229b
commit
529f7ab712
1 changed files with 224 additions and 0 deletions
224
index.html
Normal file
224
index.html
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Diffusive Echoes</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #444;
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="info">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 derived from the abstract specs
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulseAvg: 1.08,
|
||||
pulseRange: 0.15,
|
||||
dryness: 0.9,
|
||||
playfulness: 0.1,
|
||||
tension: 0.0,
|
||||
energy: 0.4
|
||||
};
|
||||
|
||||
// Reaction-diffusion simulation
|
||||
const size = Math.floor(Math.min(canvas.width, canvas.height) / 2);
|
||||
const gridWidth = Math.floor(canvas.width / 4);
|
||||
const gridHeight = Math.floor(canvas.height / 4);
|
||||
|
||||
// Initialize two grids for the reaction-diffusion model
|
||||
let gridA = new Array(gridWidth * gridHeight).fill(0);
|
||||
let gridB = new Array(gridWidth * gridHeight).fill(0);
|
||||
|
||||
// Initialize with random seeds
|
||||
for (let i = 0; i < gridWidth * gridHeight; i++) {
|
||||
if (Math.random() < 0.1 * (1 + params.density * 9)) {
|
||||
gridA[i] = Math.random();
|
||||
}
|
||||
}
|
||||
|
||||
// Simulation parameters
|
||||
const feed = 0.055 + params.connectedness * 0.02;
|
||||
const kill = 0.062 + params.motion * 0.03;
|
||||
const diffA = 0.05 + params.complexity * 0.1;
|
||||
const diffB = 0.1 + params.complexity * 0.2;
|
||||
const timeStep = 1;
|
||||
|
||||
// Palette based on parameters
|
||||
const isDry = params.dryness > 0.7;
|
||||
const isPlayful = params.playfulness > 0.3;
|
||||
const isCurious = params.curiosity > 0.3;
|
||||
|
||||
let hueBase = 180;
|
||||
if (isCurious) hueBase = 160; // Teals
|
||||
if (isPlayful) hueBase = 60; // Yellows
|
||||
|
||||
let saturation = isDry ? 50 : 90;
|
||||
let brightness = 60 + params.energy * 40;
|
||||
|
||||
// Animation state
|
||||
let frameCount = 0;
|
||||
let pulse = params.pulseAvg;
|
||||
let lastTime = 0;
|
||||
|
||||
function updateGrids() {
|
||||
// Create temporary grids
|
||||
const newA = new Array(gridWidth * gridHeight).fill(0);
|
||||
const newB = new Array(gridWidth * gridHeight).fill(0);
|
||||
|
||||
// Apply reaction-diffusion rules
|
||||
for (let y = 1; y < gridHeight - 1; y++) {
|
||||
for (let x = 1; x < gridWidth - 1; x++) {
|
||||
const i = y * gridWidth + x;
|
||||
|
||||
// Calculate laplacian (neighbor average)
|
||||
const laplacianA = (
|
||||
gridA[i - 1] + gridA[i + 1] +
|
||||
gridA[i - gridWidth] + gridA[i + gridWidth] +
|
||||
gridA[i - gridWidth - 1] + gridA[i - gridWidth + 1] +
|
||||
gridA[i + gridWidth - 1] + gridA[i + gridWidth + 1]
|
||||
) / 8 - gridA[i];
|
||||
|
||||
const laplacianB = (
|
||||
gridB[i - 1] + gridB[i + 1] +
|
||||
gridB[i - gridWidth] + gridB[i + gridWidth] +
|
||||
gridB[i - gridWidth - 1] + gridB[i - gridWidth + 1] +
|
||||
gridB[i + gridWidth - 1] + gridB[i + gridWidth + 1]
|
||||
) / 8 - gridB[i];
|
||||
|
||||
// Reaction terms
|
||||
const reaction = gridA[i] * gridB[i];
|
||||
|
||||
newA[i] = gridA[i] + (diffA * laplacianA - reaction + feed * (1 - gridA[i])) * timeStep;
|
||||
newB[i] = gridB[i] + (diffB * laplacianB + reaction - (kill + feed) * gridB[i]) * timeStep;
|
||||
|
||||
// Clamp values
|
||||
newA[i] = Math.max(0, Math.min(1, newA[i]));
|
||||
newB[i] = Math.max(0, Math.min(1, newB[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Update grids
|
||||
for (let i = 0; i < gridWidth * gridHeight; i++) {
|
||||
gridA[i] = newA[i];
|
||||
gridB[i] = newB[i];
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
if (params.tension > 0.5) {
|
||||
ctx.filter = 'contrast(150%) brightness(80%)';
|
||||
} else {
|
||||
ctx.filter = 'none';
|
||||
}
|
||||
|
||||
// Fade background slightly
|
||||
if (params.lifespan > 0.5) {
|
||||
ctx.fillStyle = `rgba(10, 10, 10, 0.05)`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
// Draw reaction-diffusion cells
|
||||
const cellWidth = canvas.width / gridWidth;
|
||||
const cellHeight = canvas.height / gridHeight;
|
||||
|
||||
// Calculate hue variation
|
||||
const hueVariation = 30 * params.complexity;
|
||||
|
||||
for (let y = 0; y < gridHeight; y++) {
|
||||
for (let x = 0; x < gridWidth; x++) {
|
||||
const i = y * gridWidth + x;
|
||||
const valA = gridA[i];
|
||||
const valB = gridB[i];
|
||||
|
||||
// Combined value with some reaction-diffusion magic
|
||||
const combined = valA - valB;
|
||||
|
||||
if (Math.abs(combined) > 0.1) {
|
||||
// Use valA for hue variation
|
||||
const hue = (hueBase + hueVariation * combined) % 360;
|
||||
|
||||
// Brightness based on energy and density
|
||||
const bright = brightness + params.density * 20 * (0.5 + combined);
|
||||
|
||||
// Saturation based on dryness
|
||||
const sat = saturation * (1 - params.dryness * 0.5);
|
||||
|
||||
ctx.fillStyle = `hsl(${hue}, ${sat}%, ${bright}%)`;
|
||||
|
||||
// Elliptical shapes for complexity
|
||||
const phase = frameCount * 0.01;
|
||||
const scale = 0.3 + 0.7 * Math.abs(combined);
|
||||
const w = cellWidth * scale * (0.5 + valA * 0.5);
|
||||
const h = cellHeight * scale * (0.5 + valB * 0.5);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(
|
||||
x * cellWidth + cellWidth / 2 + Math.sin(y * 0.3 + phase) * 5,
|
||||
y * cellHeight + cellHeight / 2 + Math.cos(x * 0.3 + phase) * 5,
|
||||
w, h, 0, 0, Math.PI * 2
|
||||
);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update pulse for variation
|
||||
frameCount++;
|
||||
if (frameCount % 30 === 0) {
|
||||
pulse = params.pulseAvg + (Math.random() * 2 - 1) * params.pulseRange;
|
||||
}
|
||||
}
|
||||
|
||||
function animate(timestamp) {
|
||||
const deltaTime = timestamp - lastTime;
|
||||
lastTime = timestamp;
|
||||
|
||||
// Slow down animation based on motion parameter
|
||||
const speed = 0.01 + params.motion * 0.03;
|
||||
|
||||
if (deltaTime > 16) { // Skip frames if needed
|
||||
updateGrids();
|
||||
draw();
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue