210 lines
No EOL
7.3 KiB
HTML
210 lines
No EOL
7.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Neurameba Flow Field</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background-color: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 20px;
|
|
right: 20px;
|
|
color: #ffffff80;
|
|
font-size: 12px;
|
|
z-index: 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');
|
|
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
// Flow field parameters
|
|
const params = {
|
|
motion: 0.500,
|
|
density: 0.500,
|
|
complexity: 0.500,
|
|
connectedness: 0.500,
|
|
lifespan: 0.500,
|
|
pulse: 1.08,
|
|
tone: {
|
|
anger: 0.00,
|
|
sadness: 0.00,
|
|
curiosity: 0.60,
|
|
dryness: 0.80,
|
|
playfulness: 0.20,
|
|
tension: 0.00
|
|
}
|
|
};
|
|
|
|
// Generate initial flow field
|
|
const fieldSize = 32;
|
|
const field = [];
|
|
for (let y = 0; y < fieldSize; y++) {
|
|
field[y] = [];
|
|
for (let x = 0; x < fieldSize; x++) {
|
|
// Base vector with some noise
|
|
const angle = (x / fieldSize) * Math.PI * 2 + Math.random() * 0.1;
|
|
const length = 0.5 + Math.sin(x * 0.3) * 0.3;
|
|
field[y][x] = {
|
|
vx: Math.cos(angle) * length,
|
|
vy: Math.sin(angle) * length,
|
|
baseAngle: angle
|
|
};
|
|
}
|
|
}
|
|
|
|
// Particle system
|
|
const particles = [];
|
|
const particleCount = Math.floor(100 + 300 * params.density);
|
|
|
|
for (let i = 0; i < particleCount; i++) {
|
|
particles.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: 0,
|
|
vy: 0,
|
|
size: 1 + Math.random() * 2,
|
|
color: getParticleColor(),
|
|
lifetime: 0,
|
|
maxLifetime: 100 + Math.random() * 200 * params.lifespan,
|
|
trail: [],
|
|
trailLength: 5 + Math.floor(params.motion * 20)
|
|
});
|
|
}
|
|
|
|
function getParticleColor() {
|
|
const r = Math.floor(50 + 50 * params.tone.curiosity * (1 - params.tone.dryness));
|
|
const g = Math.floor(100 + 100 * params.tone.curiosity * (1 - params.tone.dryness));
|
|
const b = Math.floor(150 + 100 * params.tone.curiosity * (1 - params.tone.dryness));
|
|
return `rgba(${r}, ${g}, ${b}, 0.7)`;
|
|
}
|
|
|
|
function updateField() {
|
|
// Slightly perturb the field based on motion
|
|
for (let y = 0; y < fieldSize; y++) {
|
|
for (let x = 0; x < fieldSize; x++) {
|
|
const cell = field[y][x];
|
|
cell.baseAngle += (Math.random() - 0.5) * 0.1 * params.motion;
|
|
cell.vx = Math.cos(cell.baseAngle) * (0.5 + Math.sin(x * 0.3) * 0.3);
|
|
cell.vy = Math.sin(cell.baseAngle) * (0.5 + Math.sin(y * 0.3) * 0.3);
|
|
}
|
|
}
|
|
}
|
|
|
|
function updateParticles() {
|
|
for (const p of particles) {
|
|
// Find nearest field point
|
|
const fieldX = Math.floor((p.x / canvas.width) * fieldSize) % fieldSize;
|
|
const fieldY = Math.floor((p.y / canvas.height) * fieldSize) % fieldSize;
|
|
const cell = field[fieldY][fieldX];
|
|
|
|
// Apply flow field forces
|
|
const force = params.pulse * params.motion * 0.2;
|
|
p.vx = p.vx * 0.95 + cell.vx * force;
|
|
p.vy = p.vy * 0.95 + cell.vy * force;
|
|
|
|
// Add some turbulence
|
|
p.vx += (Math.random() - 0.5) * 0.05 * params.motion * params.complexity;
|
|
p.vy += (Math.random() - 0.5) * 0.05 * params.motion * params.complexity;
|
|
|
|
// Update position with boundary checks
|
|
p.x += p.vx;
|
|
p.y += p.vy;
|
|
|
|
p.x = (p.x + canvas.width) % canvas.width;
|
|
p.y = (p.y + canvas.height) % canvas.height;
|
|
|
|
// Update trail
|
|
p.trail.push({x: p.x, y: p.y});
|
|
if (p.trail.length > p.trailLength) {
|
|
p.trail.shift();
|
|
}
|
|
|
|
p.lifetime++;
|
|
}
|
|
|
|
// Cull dead particles
|
|
if (Math.random() < 0.02 * (1 - params.lifespan)) {
|
|
const deadIndex = Math.floor(Math.random() * particles.length);
|
|
const deadParticle = particles[deadIndex];
|
|
deadParticle.maxLifetime = 0; // Mark for replacement
|
|
}
|
|
|
|
// Replace dead particles
|
|
for (let i = 0; i < particles.length; i++) {
|
|
if (particles[i].lifetime > particles[i].maxLifetime) {
|
|
const angle = Math.random() * Math.PI * 2;
|
|
const length = Math.max(canvas.width, canvas.height) * 0.1;
|
|
particles[i] = {
|
|
x: canvas.width/2 + Math.cos(angle) * length,
|
|
y: canvas.height/2 + Math.sin(angle) * length,
|
|
vx: Math.cos(angle) * 2,
|
|
vy: Math.sin(angle) * 2,
|
|
size: 1 + Math.random() * 2,
|
|
color: getParticleColor(),
|
|
lifetime: 0,
|
|
maxLifetime: 100 + Math.random() * 200 * params.lifespan,
|
|
trail: [],
|
|
trailLength: 5 + Math.floor(params.motion * 20)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
function draw() {
|
|
// Dim background slightly
|
|
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw particles
|
|
for (const p of particles) {
|
|
// Draw trail
|
|
ctx.beginPath();
|
|
for (let i = 0; i < p.trail.length; i++) {
|
|
const t = p.trail[i];
|
|
const alpha = i / p.trail.length * 0.5;
|
|
ctx.moveTo(t.x, t.y);
|
|
ctx.lineTo(p.trail[i-1]?.x || t.x, p.trail[i-1]?.y || t.y);
|
|
}
|
|
ctx.strokeStyle = p.color.replace('0.7', '0.3');
|
|
ctx.lineWidth = p.size * 0.3;
|
|
ctx.stroke();
|
|
|
|
// Draw particle
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
ctx.fillStyle = p.color;
|
|
ctx.fill();
|
|
}
|
|
|
|
updateField();
|
|
updateParticles();
|
|
}
|
|
|
|
function animate() {
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |