drifting-molecular-currents.../index.html

211 lines
7 KiB
HTML
Raw Permalink Normal View History

2026-09-20 18:21:23 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Drifting Currents</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
color: #e0e0e0;
}
#canvas {
display: block;
width: 100vw;
height: 100vh;
}
#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 (abstracted from specification)
const params = {
motion: 0.577,
density: 0.520,
complexity: 0.485,
connectedness: 0.543,
lifespan: 0.499,
survivingNodes: 83,
branchCount: 58,
loops: 169,
maxDepth: 19,
thicknessRatio: 1.25,
fractalDimension: 1.601,
finalEnergy: 421.4,
pulse: { avg: 0.65, min: 0.30, max: 1.75 },
tone: {
anger: 0.00,
sadness: 0.00,
curiosity: 0.70,
dryness: 0.90,
playfulness: 0.10,
tension: 0.00
}
};
// Flow field properties
const particleCount = Math.floor(params.density * 1000 + 200);
const particles = [];
const fieldResolution = Math.floor(50 + params.complexity * 50);
const fieldSize = { x: canvas.width, y: canvas.height };
// Color scheme (teals with dry/monochrome influence)
function getColor() {
const hue = 180 + Math.sin(Date.now() * 0.0005) * 30;
const saturation = 40 + params.tone.curiosity * 30;
const lightness = 60 + params.tone.dryness * (-20);
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
}
// Flow field creation with turbulence
function createFlowField() {
const field = [];
const time = Date.now() * 0.0001;
for (let y = 0; y < fieldResolution; y++) {
for (let x = 0; x < fieldResolution; x++) {
const px = (x / fieldResolution) * fieldSize.x;
const py = (y / fieldResolution) * fieldSize.y;
// Base noise (simplex-like)
const nx = px * 0.005;
const ny = py * 0.005;
const angle = Math.sin(nx + time * 0.1) * Math.cos(ny + time * 0.05) * Math.PI;
// Add some randomness based on parameters
const turbulence = 0.5 + params.motion * 0.5;
const finalAngle = angle + (Math.random() - 0.5) * turbulence;
field.push({
x: Math.cos(finalAngle),
y: Math.sin(finalAngle),
strength: 1.0
});
}
}
return field;
}
// Particle system
class Particle {
constructor() {
this.reset();
this.size = 0.5 + Math.random() * 1.5;
this.lifespan = params.lifespan * 2000 + Math.random() * 1000;
this.maxSpeed = 0.5 + params.motion * 2;
}
reset() {
this.x = Math.random() * fieldSize.x;
this.y = Math.random() * fieldSize.y;
this.prevX = this.x;
this.prevY = this.y;
this.age = 0;
this.speed = this.maxSpeed * (0.3 + Math.random() * 0.7);
this.angle = Math.random() * Math.PI * 2;
this.color = getColor();
}
update(field) {
this.age += 16; // ~60fps
// Get field influence
const fieldX = Math.floor((this.x / fieldSize.x) * fieldResolution) % fieldResolution;
const fieldY = Math.floor((this.y / fieldSize.y) * fieldResolution) % fieldResolution;
const fieldIndex = fieldX + fieldY * fieldResolution;
const force = field[fieldIndex];
// Apply field influence
this.angle = Math.atan2(force.y, force.x) +
(Math.random() - 0.5) * params.motion * 0.3;
// Move particle
this.prevX = this.x;
this.prevY = this.y;
this.x += Math.cos(this.angle) * this.speed;
this.y += Math.sin(this.angle) * this.speed;
// Boundary conditions (wrap around)
if (this.x < 0) this.x = fieldSize.x;
if (this.x > fieldSize.x) this.x = 0;
if (this.y < 0) this.y = fieldSize.y;
if (this.y > fieldSize.y) this.y = 0;
// Fade out at edges
const edgeFade = Math.min(
Math.min(this.x, fieldSize.x - this.x) / 100,
Math.min(this.y, fieldSize.y - this.y) / 100
);
this.color = getColor();
ctx.strokeStyle = this.color.replace('%)', `%, ${Math.max(0, 1 - this.age/this.lifespan)}%)`);
}
draw() {
ctx.beginPath();
ctx.moveTo(this.prevX, this.prevY);
ctx.lineTo(this.x, this.y);
ctx.stroke();
}
}
// Initialize particles
function initParticles() {
particles.length = 0;
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle());
}
}
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineCap = 'round';
ctx.lineWidth = params.thicknessRatio * (0.3 + params.dryness * 0.2);
const field = createFlowField();
// Update and draw particles
for (let i = 0; i < particles.length; i++) {
particles[i].update(field);
if (particles[i].age < particles[i].lifespan) {
particles[i].draw();
} else {
particles[i].reset();
}
}
requestAnimationFrame(animate);
}
// Initialize and start
initParticles();
animate();
</script>
</body>
</html>