diffusive-ecologies-lingeri.../index.html

202 lines
No EOL
6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neural Diffusion</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
color: #ddd;
font-family: 'Courier New', monospace;
display: flex;
flex-direction: column;
height: 100vh;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
font-size: 10px;
opacity: 0.5;
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');
// Set canvas to full window size
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Parameters aligned with the brief
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.03, min: 0.80, max: 1.20 }
};
// Reaction-diffusion simulation with Turing patterns
const cols = Math.floor(canvas.width / 2);
const rows = Math.floor(canvas.height / 2);
const grid = create2DArray(cols, rows);
const next = create2DArray(cols, rows);
// Adjusted for low motion, high density feel
const F = params.complexity * 0.05 + 0.051; // Feed rate
const K = params.connectedness * 0.06 + 0.06; // Kill rate
const DA = params.complexity * 0.2 + 0.1;
const DB = params.connectedness * 0.1 + 0.05;
// Add some noise
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
if (Math.random() < params.density * 0.8) {
grid[i][j] = {
a: 1,
b: 0
};
} else {
grid[i][j] = {
a: 0,
b: 0
};
}
}
}
// Drop a few perturbations
for (let k = 0; k < cols * rows * 0.001; k++) {
const i = Math.floor(Math.random() * cols);
const j = Math.floor(Math.random() * rows);
grid[i][j].b = 1;
}
function create2DArray(w, h) {
const arr = new Array(w);
for (let i = 0; i < w; i++) {
arr[i] = new Array(h);
}
return arr;
}
function laplacianA(x, y) {
let sum = 0;
for (let dx = -1; dx <= 1; dx++) {
for (let dy = -1; dy <= 1; dy++) {
const xx = (x + dx + cols) % cols;
const yy = (y + dy + rows) % rows;
sum += grid[xx][yy].a;
}
}
return (sum / 9) - grid[x][y].a;
}
function laplacianB(x, y) {
let sum = 0;
for (let dx = -1; dx <= 1; dx++) {
for (let dy = -1; dy <= 1; dy++) {
const xx = (x + dx + cols) % cols;
const yy = (y + dy + rows) % rows;
sum += grid[xx][yy].b;
}
}
return (sum / 9) - grid[x][y].b;
}
// Pulse modulation
let time = 0;
function update() {
time += 0.01;
// Apply pulse to parameters
const pulseFactor = params.pulse.avg + Math.sin(time * 0.3) * 0.2;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const a = grid[x][y].a;
const b = grid[x][y].b;
const laplacianAVal = laplacianA(x, y);
const laplacianBVal = laplacianB(x, y);
// Gray-Scott model
next[x][y].a = a + (
DA * laplacianAVal -
a * b * b +
F * (1 - a)
) * pulseFactor;
next[x][y].b = b + (
DB * laplacianBVal +
a * b * b -
(F + K) * b
) * pulseFactor;
}
}
// Swap buffers
const temp = grid;
grid = next;
next = temp;
draw();
requestAnimationFrame(update);
}
function draw() {
ctx.fillStyle = '#0a0a0a';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const imageData = ctx.createImageData(cols, rows);
const data = imageData.data;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
const idx = (y * cols + x) * 4;
const a = grid[x][y].a;
const b = grid[x][y].b;
// Monochrome with dryness
const value = Math.min(1, Math.max(0, (b - a) * 2));
const gray = Math.floor(value * 255);
data[idx] = gray;
data[idx + 1] = gray;
data[idx + 2] = gray;
data[idx + 3] = 255;
}
}
ctx.putImageData(imageData, 0, 0);
// Apply slight blur for texture
ctx.filter = 'blur(0.5px)';
ctx.drawImage(canvas, 0, 0, cols, rows, 0, 0, canvas.width, canvas.height);
ctx.filter = 'none';
}
update();
</script>
</body>
</html>