diffused-neural-veins-dcuh/index.html

163 lines
No EOL
5.2 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;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#credits {
position: fixed;
bottom: 10px;
right: 10px;
color: rgba(255, 255, 255, 0.3);
font-size: 10px;
pointer-events: none;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="credits">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();
const params = {
motion: 0.564,
density: 0.586,
complexity: 0.420,
connectedness: 0.512,
lifespan: 0.532,
pulse: { avg: 0.47, min: 0.30, max: 1.55 }
};
const gridSize = Math.min(120, 80 + Math.floor(params.density * 40));
const cellSize = Math.max(4, 8 - Math.floor(params.complexity * 3));
const cols = Math.floor(canvas.width / cellSize);
const rows = Math.floor(canvas.height / cellSize);
const grid = createGrid();
const nextGrid = createGrid();
let frameCount = 0;
function createGrid() {
const size = Math.floor(cols * rows * params.density);
const g = new Array(size).fill(0);
for (let i = 0; i < size; i++) {
g[i] = Math.random() * 0.1;
}
return g;
}
function updateGrid() {
const p = params.pulse;
const pulseVal = p.min + (p.max - p.min) * (Math.sin(frameCount * 0.05) * 0.5 + 0.5);
for (let i = 0; i < grid.length; i++) {
const x = i % cols;
const y = Math.floor(i / cols);
const neighbors = getNeighbors(x, y);
let sum = 0;
for (const n of neighbors) {
sum += grid[n];
}
sum /= neighbors.length;
const reaction = grid[i] * (1 - grid[i]) * 0.5;
const diffusion = (sum - grid[i]) * 0.1 * pulseVal;
nextGrid[i] = Math.min(1, Math.max(0, grid[i] + reaction + diffusion));
}
const temp = grid;
grid.length = 0;
grid.push(...nextGrid);
nextGrid.length = 0;
nextGrid.push(...temp);
}
function getNeighbors(x, y) {
const neighbors = [];
const offsets = [
[-1, -1], [0, -1], [1, -1],
[-1, 0], [1, 0],
[-1, 1], [0, 1], [1, 1]
];
for (const [dx, dy] of offsets) {
const nx = (x + dx + cols) % cols;
const ny = (y + dy + rows) % rows;
neighbors.push(ny * cols + nx);
}
return neighbors;
}
function drawGrid() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < grid.length; i++) {
if (grid[i] > 0.01) {
const x = (i % cols) * cellSize;
const y = Math.floor(i / cols) * cellSize;
const size = cellSize * grid[i] * (0.5 + params.pulse.avg) * 2;
const alpha = grid[i] * 0.8;
ctx.fillStyle = `rgba(150, 200, 255, ${alpha})`;
ctx.beginPath();
ctx.arc(x + cellSize/2, y + cellSize/2, size/2, 0, Math.PI * 2);
ctx.fill();
}
}
for (let i = 0; i < grid.length; i++) {
if (grid[i] > 0.3) {
const x = (i % cols) * cellSize;
const y = Math.floor(i / cols) * cellSize;
ctx.strokeStyle = `rgba(255, 255, 255, ${grid[i] * 0.3})`;
ctx.lineWidth = 1;
ctx.beginPath();
const neighbors = getNeighbors(i % cols, Math.floor(i / cols));
for (const n of neighbors) {
if (grid[n] > 0.3 && Math.random() < params.connectedness) {
ctx.moveTo(x + cellSize/2, y + cellSize/2);
const nx = (n % cols) * cellSize;
const ny = Math.floor(n / cols) * cellSize;
ctx.lineTo(nx + cellSize/2, ny + cellSize/2);
}
}
ctx.stroke();
}
}
}
function animate() {
updateGrid();
drawGrid();
frameCount++;
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>