birth: Voronoi Tides of Curiosity
This commit is contained in:
parent
f6726cba60
commit
b3390cb495
1 changed files with 256 additions and 0 deletions
256
index.html
Normal file
256
index.html
Normal file
|
|
@ -0,0 +1,256 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Voronoi Drift</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0a1a;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#attribution {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 10px;
|
||||||
|
right: 10px;
|
||||||
|
color: #555;
|
||||||
|
font-size: 10px;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
</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();
|
||||||
|
|
||||||
|
// Voronoi parameters
|
||||||
|
const params = {
|
||||||
|
points: 500 * (0.5 + 0.5 * Math.random()),
|
||||||
|
motion: 0.5,
|
||||||
|
density: 0.5,
|
||||||
|
complexity: 0.5,
|
||||||
|
connectedness: 0.5,
|
||||||
|
lifespan: 0.5,
|
||||||
|
pulse: 1.07
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate Voronoi points with variation
|
||||||
|
function generatePoints() {
|
||||||
|
const points = [];
|
||||||
|
const centerX = canvas.width / 2;
|
||||||
|
const centerY = canvas.height / 2;
|
||||||
|
const maxDist = Math.sqrt(centerX * centerX + centerY * centerY);
|
||||||
|
|
||||||
|
for (let i = 0; i < params.points; i++) {
|
||||||
|
const angle = Math.random() * Math.PI * 2;
|
||||||
|
const dist = maxDist * Math.pow(Math.random(), 0.5);
|
||||||
|
let x = centerX + dist * Math.cos(angle);
|
||||||
|
let y = centerY + dist * Math.sin(angle);
|
||||||
|
|
||||||
|
// Add motion
|
||||||
|
x += (Math.random() - 0.5) * params.motion * 100;
|
||||||
|
y += (Math.random() - 0.5) * params.motion * 100;
|
||||||
|
|
||||||
|
points.push({x, y, life: Math.random(), color: getPointColor()});
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPointColor() {
|
||||||
|
// Curiosity=0.7 (teals), dryness=0.8 (monochrome), playfulness=0.3 (subtle brightness)
|
||||||
|
const hue = 170 + 20 * Math.sin(Date.now() * 0.001 + Math.random() * 10);
|
||||||
|
const saturation = 40 + 20 * Math.sin(Date.now() * 0.0015);
|
||||||
|
const lightness = 60 + 10 * Math.sin(Date.now() * 0.0012);
|
||||||
|
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let points = generatePoints();
|
||||||
|
let time = 0;
|
||||||
|
|
||||||
|
function updatePoints() {
|
||||||
|
time += 0.01;
|
||||||
|
|
||||||
|
// Update existing points
|
||||||
|
for (let i = 0; i < points.length; i++) {
|
||||||
|
const p = points[i];
|
||||||
|
p.x += (Math.random() - 0.5) * params.motion * 2;
|
||||||
|
p.y += (Math.random() - 0.5) * params.motion * 2;
|
||||||
|
p.life = (p.life + 0.001 * params.lifespan) % 1;
|
||||||
|
p.color = getPointColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new points occasionally
|
||||||
|
if (Math.random() < 0.05 * params.density) {
|
||||||
|
points.push({
|
||||||
|
x: Math.random() * canvas.width,
|
||||||
|
y: Math.random() * canvas.height,
|
||||||
|
life: 0,
|
||||||
|
color: getPointColor()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old points
|
||||||
|
points = points.filter(p => p.life < 0.7 || Math.random() > 0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawVoronoi() {
|
||||||
|
// Clear with slight fade
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Create Voronoi diagram
|
||||||
|
const diagram = new Voronoi();
|
||||||
|
const bbox = {xl: 0, xr: canvas.width, yt: 0, yb: canvas.height};
|
||||||
|
const cells = diagram.compute(points.map(p => ({x: p.x, y: p.y})), bbox);
|
||||||
|
|
||||||
|
// Draw cells
|
||||||
|
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
|
||||||
|
for (let i = 0; i < cells.length; i++) {
|
||||||
|
const cell = cells[i];
|
||||||
|
if (!cell || !cell.halfedges || cell.halfedges.length === 0) continue;
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(cell.halfedges[0].getStartpoint().x, cell.halfedges[0].getStartpoint().y);
|
||||||
|
|
||||||
|
for (let j = 0; j < cell.halfedges.length; j++) {
|
||||||
|
const endpoint = cell.halfedges[j].getEndpoint();
|
||||||
|
ctx.lineTo(endpoint.x, endpoint.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// Fill with point color
|
||||||
|
ctx.fillStyle = points[i].color;
|
||||||
|
ctx.globalAlpha = points[i].life * 0.7;
|
||||||
|
ctx.fill();
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
updatePoints();
|
||||||
|
drawVoronoi();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple Voronoi implementation
|
||||||
|
function Voronoi() {
|
||||||
|
this.compute = function(sites, bbox) {
|
||||||
|
const edges = [];
|
||||||
|
const cells = [];
|
||||||
|
|
||||||
|
// This is a simplified Voronoi diagram calculation
|
||||||
|
// In a real implementation, we would use a proper algorithm
|
||||||
|
for (let i = 0; i < sites.length; i++) {
|
||||||
|
const cell = {
|
||||||
|
site: sites[i],
|
||||||
|
halfedges: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create edges between sites
|
||||||
|
for (let j = i + 1; j < sites.length; j++) {
|
||||||
|
const other = sites[j];
|
||||||
|
|
||||||
|
// Calculate edge between two sites
|
||||||
|
const edge = {
|
||||||
|
left: sites[i],
|
||||||
|
right: sites[j],
|
||||||
|
start: {x: 0, y: 0},
|
||||||
|
end: {x: 0, y: 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate perpendicular bisector
|
||||||
|
const dx = other.x - sites[i].x;
|
||||||
|
const dy = other.y - sites[i].y;
|
||||||
|
const len = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
if (len === 0) continue;
|
||||||
|
|
||||||
|
const nx = dx / len;
|
||||||
|
const ny = dy / len;
|
||||||
|
|
||||||
|
const midX = (sites[i].x + other.x) / 2;
|
||||||
|
const midY = (sites[i].y + other.y) / 2;
|
||||||
|
|
||||||
|
// Create segment for the edge
|
||||||
|
edge.start.x = midX - ny * 10000;
|
||||||
|
edge.start.y = midY + nx * 10000;
|
||||||
|
edge.end.x = midX + ny * 10000;
|
||||||
|
edge.end.y = midY - nx * 10000;
|
||||||
|
|
||||||
|
edges.push(edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find intersecting edges with bbox
|
||||||
|
const halfedges = [];
|
||||||
|
for (let j = 0; j < edges.length; j++) {
|
||||||
|
const edge = edges[j];
|
||||||
|
if (!edge) continue;
|
||||||
|
|
||||||
|
// Calculate intersection with bbox
|
||||||
|
const intersections = [];
|
||||||
|
|
||||||
|
// Check each bbox edge
|
||||||
|
function intersect(p1, p2, p3, p4) {
|
||||||
|
const denom = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);
|
||||||
|
if (denom === 0) return null;
|
||||||
|
|
||||||
|
const ua = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denom;
|
||||||
|
const ub = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denom;
|
||||||
|
|
||||||
|
if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
|
||||||
|
return {
|
||||||
|
x: p1.x + ua * (p2.x - p1.x),
|
||||||
|
y: p1.y + ua * (p2.y - p1.y)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
intersections.push(intersect(edge.start, edge.end, {x: bbox.xl, y: bbox.yt}, {x: bbox.xr, y: bbox.yt})); // top
|
||||||
|
intersections.push(intersect(edge.start, edge.end, {x: bbox.xr, y: bbox.yt}, {x: bbox.xr, y: bbox.yb})); // right
|
||||||
|
intersections.push(intersect(edge.start, edge.end, {x: bbox.xr, y: bbox.yb}, {x: bbox.xl, y: bbox.yb})); // bottom
|
||||||
|
intersections.push(intersect(edge.start, edge.end, {x: bbox.xl, y: bbox.yb}, {x: bbox.xl, y: bbox.yt})); // left
|
||||||
|
|
||||||
|
// Remove null intersections
|
||||||
|
const validIntersections = intersections.filter(p => p !== null);
|
||||||
|
|
||||||
|
if (validIntersections.length >= 2) {
|
||||||
|
// Create halfedge
|
||||||
|
halfedges.push({
|
||||||
|
getStartpoint: () => validIntersections[0],
|
||||||
|
getEndpoint: () => validIntersections[1]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.halfedges = halfedges;
|
||||||
|
cells.push(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cells;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue