211 lines
No EOL
7 KiB
HTML
211 lines
No EOL
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>Flow Field Organism</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #444;
|
|
font-size: 10px;
|
|
text-shadow: 0 0 5px #000;
|
|
}
|
|
</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();
|
|
|
|
// Parameters based on generative art builder
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.06, min: 0.9, max: 1.2 },
|
|
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
|
|
};
|
|
|
|
// Flow field variables
|
|
const fieldSize = 20;
|
|
const particleCount = Math.floor(100 + params.density * 200);
|
|
const particles = [];
|
|
const field = [];
|
|
let time = 0;
|
|
|
|
// Initialize flow field
|
|
function initField() {
|
|
for (let y = 0; y < Math.floor(canvas.height / fieldSize); y++) {
|
|
field[y] = [];
|
|
for (let x = 0; x < Math.floor(canvas.width / fieldSize); x++) {
|
|
// Create swirling flow patterns
|
|
field[y][x] = {
|
|
vx: Math.sin(x * 0.1 + time * 0.05),
|
|
vy: Math.cos(y * 0.1 + time * 0.05) * Math.sin(x * 0.05)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
// Create particles
|
|
function initParticles() {
|
|
particles.length = 0;
|
|
for (let i = 0; i < particleCount; i++) {
|
|
particles.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
size: 1 + Math.random() * 2,
|
|
speed: 0.5 + Math.random() * 1.5,
|
|
trail: [],
|
|
maxTrailLength: 5 + Math.floor(params.complexity * 10),
|
|
color: `hsl(0, 0%, ${params.tone.dryness > 0.8 ? 85 : 70}%)`,
|
|
life: 0
|
|
});
|
|
}
|
|
}
|
|
|
|
// Update flow field
|
|
function updateField() {
|
|
time += 0.01;
|
|
|
|
for (let y = 0; y < field.length; y++) {
|
|
for (let x = 0; x < field[y].length; x++) {
|
|
const nx = x + Math.sin(time * 0.02) * 2;
|
|
const ny = y + Math.cos(time * 0.03) * 2;
|
|
|
|
field[y][x].vx = Math.sin(nx * 0.1) * 0.5;
|
|
field[y][x].vy = Math.cos(ny * 0.1) * 0.3;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update particles
|
|
function updateParticles() {
|
|
particles.forEach(p => {
|
|
// Get flow field value
|
|
const fx = Math.floor(p.x / fieldSize);
|
|
const fy = Math.floor(p.y / fieldSize);
|
|
|
|
if (fx >= 0 && fx < field[0].length && fy >= 0 && fy < field.length) {
|
|
const flow = field[fy][fx];
|
|
p.x += flow.vx * p.speed * params.motion;
|
|
p.y += flow.vy * p.speed * params.motion;
|
|
} else {
|
|
// Random movement when out of bounds
|
|
p.x = Math.random() * canvas.width;
|
|
p.y = Math.random() * canvas.height;
|
|
}
|
|
|
|
// Add to trail
|
|
p.trail.push({x: p.x, y: p.y});
|
|
if (p.trail.length > p.maxTrailLength) {
|
|
p.trail.shift();
|
|
}
|
|
|
|
// Wrap around
|
|
if (p.x < 0) p.x = canvas.width;
|
|
if (p.x > canvas.width) p.x = 0;
|
|
if (p.y < 0) p.y = canvas.height;
|
|
if (p.y > canvas.height) p.y = 0;
|
|
|
|
p.life += 0.01 * params.lifespan;
|
|
});
|
|
|
|
// Occasionally reset particles to maintain density
|
|
if (Math.random() < 0.01 * (1 - params.density)) {
|
|
const p = particles[Math.floor(Math.random() * particles.length)];
|
|
p.x = Math.random() * canvas.width;
|
|
p.y = Math.random() * canvas.height;
|
|
p.size = 1 + Math.random() * 2;
|
|
}
|
|
}
|
|
|
|
// Draw everything
|
|
function draw() {
|
|
// Soft background fade
|
|
ctx.fillStyle = `rgba(5, 5, 5, ${params.tone.dryness > 0.8 ? 0.05 : 0.1})`;
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw flow field (subtle)
|
|
ctx.strokeStyle = `rgba(255, 255, 255, 0.03)`;
|
|
ctx.lineWidth = 0.5;
|
|
|
|
for (let y = 0; y < field.length; y += 3) {
|
|
for (let x = 0; x < field[y].length; x += 3) {
|
|
const flow = field[y][x];
|
|
const x2 = x * fieldSize + fieldSize/2;
|
|
const y2 = y * fieldSize + fieldSize/2;
|
|
const x3 = x2 + flow.vx * 5;
|
|
const y3 = y2 + flow.vy * 5;
|
|
|
|
ctx.beginPath();
|
|
ctx.moveTo(x2, y2);
|
|
ctx.lineTo(x3, y3);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
|
|
// Draw particles with trails
|
|
particles.forEach(p => {
|
|
// Draw trail
|
|
ctx.strokeStyle = p.color;
|
|
ctx.lineWidth = p.size / 2;
|
|
|
|
if (p.trail.length > 1) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(p.trail[0].x, p.trail[0].y);
|
|
for (let i = 1; i < p.trail.length; i++) {
|
|
const prev = p.trail[i-1];
|
|
const curr = p.trail[i];
|
|
const dist = Math.sqrt((curr.x - prev.x) ** 2 + (curr.y - prev.y) ** 2);
|
|
ctx.lineWidth = p.size * Math.max(0.3, 1 - dist / 10);
|
|
ctx.lineTo(curr.x, curr.y);
|
|
}
|
|
ctx.stroke();
|
|
}
|
|
|
|
// Draw head
|
|
ctx.fillStyle = p.color;
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
});
|
|
}
|
|
|
|
function animate() {
|
|
updateField();
|
|
updateParticles();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
initField();
|
|
initParticles();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |