static-flow-in-motion-7w7r/index.html

226 lines
No EOL
6.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>Static Flow</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
color: #333;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
font-size: 10px;
color: #555;
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');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Flow field parameters
const cols = 60;
const rows = 40;
const cellSize = Math.min(canvas.width, canvas.height) / Math.min(cols, rows);
// Particle system
const particles = [];
const particleCount = Math.floor(1000 * (0.5 + Math.sin(Date.now() * 0.001) * 0.2));
class Particle {
constructor() {
this.reset();
this.size = 0.5 + Math.random() * 1.5;
this.lifespan = 100 + Math.random() * 100;
this.age = 0;
this.velocity = new Vec2(0, 0);
}
reset() {
this.pos = new Vec2(
Math.random() * canvas.width,
Math.random() * canvas.height
);
this.prevPos = new Vec2(this.pos.x, this.pos.y);
this.vel = new Vec2(Math.random() - 0.5, Math.random() - 0.5).normalize().scale(2);
this.color = '#ffffff';
this.trail = [];
}
update(field) {
this.prevPos.set(this.pos);
// Flow field influence
const fieldX = Math.floor(this.pos.x / cellSize);
const fieldY = Math.floor(this.pos.y / cellSize);
const fieldVec = field[fieldY][fieldX];
this.vel.lerp(fieldVec, 0.1);
this.vel.normalize();
this.vel.scale(2 + Math.sin(Date.now() * 0.0005) * 0.5);
this.pos.add(this.vel);
this.age++;
// Boundary check
if (this.pos.x < 0 || this.pos.x > canvas.width ||
this.pos.y < 0 || this.pos.y > canvas.height) {
this.reset();
}
// Trail
this.trail.push({
x: this.pos.x,
y: this.pos.y,
age: 0
});
if (this.trail.length > 50) {
this.trail.shift();
}
// Color based on dryness
const hue = Math.random() * 30;
this.color = `hsl(${hue}, 20%, 80%)`;
}
draw() {
ctx.strokeStyle = this.color;
ctx.lineWidth = this.size;
ctx.beginPath();
ctx.moveTo(this.prevPos.x, this.prevPos.y);
for (let i = 0; i < this.trail.length; i++) {
const trail = this.trail[i];
const alpha = 1 - (trail.age / 50);
ctx.globalAlpha = alpha * 0.8;
ctx.lineTo(trail.x, trail.y);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
}
class Vec2 {
constructor(x, y) {
this.x = x;
this.y = y;
}
set(v) {
this.x = v.x;
this.y = v.y;
}
add(v) {
this.x += v.x;
this.y += v.y;
return this;
}
sub(v) {
this.x -= v.x;
this.y -= v.y;
return this;
}
scale(s) {
this.x *= s;
this.y *= s;
return this;
}
length() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
normalize() {
const len = this.length();
if (len > 0) {
this.x /= len;
this.y /= len;
}
return this;
}
lerp(v, t) {
this.x += (v.x - this.x) * t;
this.y += (v.y - this.y) * t;
return this;
}
}
function generateFlowField() {
const field = [];
const time = Date.now() * 0.001;
for (let y = 0; y < rows; y++) {
field[y] = [];
for (let x = 0; x < cols; x++) {
const angle = (x * 0.1 + y * 0.1 + time) * 0.5;
const speed = 0.5 + Math.sin(angle * 3) * 0.5;
field[y][x] = new Vec2(
Math.cos(angle) * speed,
Math.sin(angle) * speed
);
}
}
return field;
}
function initParticles() {
particles.length = 0;
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle());
}
}
let flowField = generateFlowField();
initParticles();
function animate() {
// Clear with fade effect
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Update flow field
flowField = generateFlowField();
// Update and draw particles
for (const particle of particles) {
particle.update(flowField);
particle.draw();
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>