birth: Fractured Light in Motion
This commit is contained in:
parent
690a269a18
commit
ad43e28171
1 changed files with 185 additions and 0 deletions
185
index.html
Normal file
185
index.html
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Voronoi Fracture</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #111;
|
||||
color: #888;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
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 derived from the prompt
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.09, min: 1.00, max: 1.20 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.10, dryness: 0.90, playfulness: 0.00, tension: 0.00 }
|
||||
};
|
||||
|
||||
// Voronoi fracture system
|
||||
const voronoi = [];
|
||||
const points = [];
|
||||
const maxPoints = 200;
|
||||
const pointSize = 40;
|
||||
const fractureLines = [];
|
||||
const colors = [
|
||||
'#eee', '#aaa', '#888', '#666', '#444', '#222'
|
||||
];
|
||||
|
||||
function initVoronoi() {
|
||||
points.length = 0;
|
||||
voronoi.length = 0;
|
||||
fractureLines.length = 0;
|
||||
|
||||
const count = Math.floor(params.density * maxPoints * 1.5);
|
||||
const complexityFactor = params.complexity * 2 + 0.5;
|
||||
const connectednessFactor = params.connectedness * 1.8;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * params.motion * 2,
|
||||
vy: (Math.random() - 0.5) * params.motion * 2,
|
||||
size: pointSize * (0.5 + Math.random() * 0.5),
|
||||
life: Math.random() * 50 + 50,
|
||||
color: colors[Math.floor(Math.random() * colors.length)]
|
||||
});
|
||||
}
|
||||
|
||||
// Create voronoi fracture lines
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
for (let j = i + 1; j < Math.min(i + 5, points.length); j++) {
|
||||
const dx = points[j].x - points[i].x;
|
||||
const dy = points[j].y - points[i].y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < pointSize * 2) {
|
||||
fractureLines.push({
|
||||
x1: points[i].x,
|
||||
y1: points[i].y,
|
||||
x2: points[j].x,
|
||||
y2: points[j].y,
|
||||
opacity: 0.7,
|
||||
thickness: 1 + Math.random() * 2
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateVoronoi() {
|
||||
const motionMultiplier = params.motion * params.pulse.avg;
|
||||
const lifespanMultiplier = params.lifespan * 0.8 + 0.2;
|
||||
|
||||
// Update points
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const p = points[i];
|
||||
|
||||
// Movement
|
||||
p.x += p.vx * motionMultiplier;
|
||||
p.y += p.vy * motionMultiplier;
|
||||
|
||||
// Bounce off edges
|
||||
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
||||
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
||||
|
||||
// Lifespan decay
|
||||
p.life -= 0.5 * lifespanMultiplier;
|
||||
|
||||
// Reset if died
|
||||
if (p.life <= 0) {
|
||||
p.x = Math.random() * canvas.width;
|
||||
p.y = Math.random() * canvas.height;
|
||||
p.life = Math.random() * 50 + 50;
|
||||
}
|
||||
}
|
||||
|
||||
// Update fracture lines
|
||||
fractureLines.forEach(line => {
|
||||
line.opacity = 0.3 + Math.random() * 0.4;
|
||||
});
|
||||
}
|
||||
|
||||
function drawVoronoi() {
|
||||
// Clear with semi-transparent to create trails
|
||||
ctx.fillStyle = 'rgba(17, 17, 17, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw fracture lines
|
||||
fractureLines.forEach(line => {
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, ' + line.opacity + ')';
|
||||
ctx.lineWidth = line.thickness;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(line.x1, line.y1);
|
||||
ctx.lineTo(line.x2, line.y2);
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
// Draw points
|
||||
points.forEach(p => {
|
||||
ctx.fillStyle = p.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size * 0.5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
// Glow effect
|
||||
const gradient = ctx.createRadialGradient(
|
||||
p.x, p.y, 0,
|
||||
p.x, p.y, p.size
|
||||
);
|
||||
gradient.addColorStop(0, 'rgba(255, 255, 255, 0.3)');
|
||||
gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
});
|
||||
}
|
||||
|
||||
function animate() {
|
||||
updateVoronoi();
|
||||
drawVoronoi();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initVoronoi();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue