birth: Flowing Curiosity Fields
This commit is contained in:
parent
af7a4ec25a
commit
50c051c645
1 changed files with 221 additions and 0 deletions
221
index.html
Normal file
221
index.html
Normal file
|
|
@ -0,0 +1,221 @@
|
||||||
|
<!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-color: #0a0a1a;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#attribution {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10px;
|
||||||
|
right: 10px;
|
||||||
|
color: rgba(255, 255, 255, 0.3);
|
||||||
|
font-size: 10px;
|
||||||
|
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();
|
||||||
|
|
||||||
|
// Organism parameters
|
||||||
|
const motion = 0.5;
|
||||||
|
const density = 0.5;
|
||||||
|
const complexity = 0.5;
|
||||||
|
const connectedness = 0.5;
|
||||||
|
const lifespan = 0.5;
|
||||||
|
const pulse = { avg: 1.1, min: 1.0, max: 1.2 };
|
||||||
|
const tone = {
|
||||||
|
anger: 0.00,
|
||||||
|
sadness: 0.00,
|
||||||
|
curiosity: 0.70,
|
||||||
|
dryness: 0.90,
|
||||||
|
playfulness: 0.10,
|
||||||
|
tension: 0.00
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flow field configuration
|
||||||
|
const fieldResolution = 50;
|
||||||
|
const fieldSize = 30;
|
||||||
|
const maxForce = 0.2 * motion;
|
||||||
|
const particleCount = 100 + Math.floor(density * 150);
|
||||||
|
let field = [];
|
||||||
|
let particles = [];
|
||||||
|
|
||||||
|
// Initialize flow field
|
||||||
|
function initField() {
|
||||||
|
field = [];
|
||||||
|
const cols = Math.ceil(canvas.width / fieldSize);
|
||||||
|
const rows = Math.ceil(canvas.height / fieldSize);
|
||||||
|
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
field[y] = [];
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
const angle = Math.random() * Math.PI * 2;
|
||||||
|
const strength = 0.5 + Math.random() * 0.5;
|
||||||
|
field[y][x] = { angle, strength };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Particle class
|
||||||
|
class Particle {
|
||||||
|
constructor() {
|
||||||
|
this.reset();
|
||||||
|
this.size = 0.5 + Math.random() * 1.5;
|
||||||
|
this.maxSpeed = 0.5 * motion;
|
||||||
|
this.lifespan = 100 + Math.random() * 200;
|
||||||
|
this.age = 0;
|
||||||
|
this.trail = [];
|
||||||
|
this.trailMax = 5 + Math.floor(complexity * 10);
|
||||||
|
this.connectedness = connectedness;
|
||||||
|
this.color = getParticleColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.pos = {
|
||||||
|
x: Math.random() * canvas.width,
|
||||||
|
y: Math.random() * canvas.height
|
||||||
|
};
|
||||||
|
this.vel = {
|
||||||
|
x: (Math.random() - 0.5) * 2,
|
||||||
|
y: (Math.random() - 0.5) * 2
|
||||||
|
};
|
||||||
|
this.prevPos = { ...this.pos };
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
// Apply flow field force
|
||||||
|
const fieldX = Math.floor(this.pos.x / fieldSize);
|
||||||
|
const fieldY = Math.floor(this.pos.y / fieldSize);
|
||||||
|
const fieldVal = field[Math.min(fieldVal, field.length-1)]?.[Math.min(fieldX, field[0].length-1)] || { angle: 0, strength: 0 };
|
||||||
|
|
||||||
|
const forceX = Math.cos(fieldVal.angle) * fieldVal.strength * maxForce;
|
||||||
|
const forceY = Math.sin(fieldVal.angle) * fieldVal.strength * maxForce;
|
||||||
|
|
||||||
|
this.vel.x += forceX;
|
||||||
|
this.vel.y += forceY;
|
||||||
|
|
||||||
|
// Limit speed
|
||||||
|
const speed = Math.sqrt(this.vel.x * this.vel.x + this.vel.y * this.vel.y);
|
||||||
|
if (speed > this.maxSpeed) {
|
||||||
|
this.vel.x = (this.vel.x / speed) * this.maxSpeed;
|
||||||
|
this.vel.y = (this.vel.y / speed) * this.maxSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update position
|
||||||
|
this.prevPos = { ...this.pos };
|
||||||
|
this.pos.x += this.vel.x;
|
||||||
|
this.pos.y += this.vel.y;
|
||||||
|
|
||||||
|
// Boundary check
|
||||||
|
if (this.pos.x < 0 || this.pos.x > canvas.width) {
|
||||||
|
this.vel.x *= -0.5;
|
||||||
|
this.pos.x = Math.max(0, Math.min(canvas.width, this.pos.x));
|
||||||
|
}
|
||||||
|
if (this.pos.y < 0 || this.pos.y > canvas.height) {
|
||||||
|
this.vel.y *= -0.5;
|
||||||
|
this.pos.y = Math.max(0, Math.min(canvas.height, this.pos.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update trail
|
||||||
|
this.trail.push({ ...this.pos });
|
||||||
|
if (this.trail.length > this.trailMax) {
|
||||||
|
this.trail.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Age and lifespan
|
||||||
|
this.age++;
|
||||||
|
if (this.age > this.lifespan) {
|
||||||
|
this.reset();
|
||||||
|
this.age = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
draw() {
|
||||||
|
ctx.strokeStyle = this.color;
|
||||||
|
ctx.lineWidth = this.size * pulseScale();
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(this.prevPos.x, this.prevPos.y);
|
||||||
|
|
||||||
|
// Draw trail with decreasing opacity
|
||||||
|
for (let i = 0; i < this.trail.length; i++) {
|
||||||
|
const t = i / this.trail.length;
|
||||||
|
const opacity = 0.1 + (1 - t) * 0.9;
|
||||||
|
ctx.globalAlpha = opacity;
|
||||||
|
ctx.lineTo(this.trail[i].x, this.trail[i].y);
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pulseScale() {
|
||||||
|
const t = pulse.avg + (pulse.max - pulse.min) * (Math.sin(Date.now() * 0.002) * 0.5 + 0.5);
|
||||||
|
return 0.9 + 0.1 * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getParticleColor() {
|
||||||
|
if (tone.dryness > 0.8) {
|
||||||
|
const hue = Math.floor(Math.random() * 30) - 15;
|
||||||
|
return `hsl(${180 + hue}, 20%, ${70 + Math.random() * 10}%)`;
|
||||||
|
} else if (tone.curiosity > 0.6) {
|
||||||
|
const hue = 150 + Math.floor(Math.random() * 60);
|
||||||
|
const saturation = 50 + Math.floor(Math.random() * 30);
|
||||||
|
const lightness = 50 + Math.floor(Math.random() * 10);
|
||||||
|
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||||
|
} else {
|
||||||
|
return `hsl(${Math.random() * 360}, 30%, ${70 + Math.random() * 10}%)`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initParticles() {
|
||||||
|
particles = [];
|
||||||
|
for (let i = 0; i < particleCount; i++) {
|
||||||
|
particles.push(new Particle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Update particles
|
||||||
|
particles.forEach(p => p.update());
|
||||||
|
|
||||||
|
// Draw particles
|
||||||
|
particles.forEach(p => p.draw());
|
||||||
|
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize and start
|
||||||
|
initField();
|
||||||
|
initParticles();
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue