142 lines
No EOL
4.7 KiB
HTML
142 lines
No EOL
4.7 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 Echoes</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background-color: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
#canvas {
|
|
display: block;
|
|
background: #0a0a0a;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
left: 10px;
|
|
color: rgba(255, 255, 255, 0.3);
|
|
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');
|
|
|
|
// Set canvas to full window size
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
// Reaction-diffusion parameters (adjusted for the given parameters)
|
|
const params = {
|
|
feed: 0.055,
|
|
kill: 0.062,
|
|
diffusionA: 1.0,
|
|
diffusionB: 0.5,
|
|
timeStep: 0.1,
|
|
gridSize: 6,
|
|
initDensity: 0.2 + (0.5 * 0.4),
|
|
complexity: 0.5,
|
|
motion: 0.5
|
|
};
|
|
|
|
// Initialize grids
|
|
const sizeX = Math.floor(canvas.width / params.gridSize) + 2;
|
|
const sizeY = Math.floor(canvas.height / params.gridSize) + 2;
|
|
let grid = new Array(sizeX * sizeY).fill(0);
|
|
let nextGrid = new Array(sizeX * sizeY).fill(0);
|
|
|
|
// Initialize with sparse noise
|
|
function initGrid() {
|
|
for (let i = 0; i < grid.length; i++) {
|
|
grid[i] = (Math.random() < params.initDensity) ? Math.random() : 0;
|
|
}
|
|
}
|
|
|
|
// Reaction-diffusion kernel
|
|
function updateGrid() {
|
|
for (let x = 1; x < sizeX - 1; x++) {
|
|
for (let y = 1; y < sizeY - 1; y++) {
|
|
const idx = x + y * sizeX;
|
|
const a = grid[idx];
|
|
const b = nextGrid[idx];
|
|
|
|
// Compute 2D laplacian (simplified)
|
|
let lapA = 0, lapB = 0;
|
|
for (let dx = -1; dx <= 1; dx++) {
|
|
for (let dy = -1; dy <= 1; dy++) {
|
|
if (dx === 0 && dy === 0) continue;
|
|
const nidx = (x + dx) + (y + dy) * sizeX;
|
|
lapA += grid[nidx];
|
|
lapB += nextGrid[nidx];
|
|
}
|
|
}
|
|
lapA = lapA / 8 - a;
|
|
lapB = lapB / 8 - b;
|
|
|
|
// Gray-Scott equations
|
|
const feedRate = params.feed * (1 - 0.5 * params.complexity);
|
|
const killRate = params.kill * (1 + 0.5 * params.complexity);
|
|
const reaction = a * b * b;
|
|
nextGrid[idx] = a + (params.diffusionA * lapA) - reaction + feedRate * (1 - a);
|
|
nextGrid[idx] += (Math.random() * 0.01 - 0.005) * params.motion; // Noise for motion
|
|
}
|
|
}
|
|
|
|
// Swap grids
|
|
[grid, nextGrid] = [nextGrid, grid];
|
|
}
|
|
|
|
// Drawing
|
|
function drawGrid() {
|
|
const imageData = ctx.createImageData(canvas.width, canvas.height);
|
|
const data = imageData.data;
|
|
|
|
for (let x = 0; x < sizeX - 2; x++) {
|
|
for (let y = 0; y < sizeY - 2; y++) {
|
|
const idx = (x + 1) + (y + 1) * sizeX;
|
|
const val = grid[idx];
|
|
|
|
// Color mapping (teals/curiosity with dryness/monochrome emphasis)
|
|
const intensity = val * 0.8;
|
|
const r = intensity * 120;
|
|
const g = intensity * 180;
|
|
const b = intensity * 200;
|
|
|
|
// Set pixel color
|
|
const pixelIdx = (x + (y * (sizeX - 2))) * 4;
|
|
data[pixelIdx] = r;
|
|
data[pixelIdx + 1] = g;
|
|
data[pixelIdx + 2] = b;
|
|
data[pixelIdx + 3] = 255;
|
|
}
|
|
}
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
updateGrid();
|
|
drawGrid();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
initGrid();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |