232 lines
No EOL
7.9 KiB
HTML
232 lines
No EOL
7.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Voronoi Organism</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
color: #ccc;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
}
|
|
canvas {
|
|
flex: 1;
|
|
}
|
|
.attribution {
|
|
text-align: center;
|
|
padding: 10px;
|
|
font-size: 12px;
|
|
opacity: 0.6;
|
|
background: rgba(0,0,0,0.3);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="canvas"></canvas>
|
|
<div class="attribution">neurameba · motd.social</div>
|
|
|
|
<script>
|
|
(function() {
|
|
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;
|
|
}
|
|
resizeCanvas();
|
|
window.addEventListener('resize', resizeCanvas);
|
|
|
|
// Parameters from prompt
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.08, min: 1.05, max: 1.10 },
|
|
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.20, dryness: 0.80, playfulness: 0.00, tension: 0.00 }
|
|
};
|
|
|
|
// Generate seed points for voronoi
|
|
function generateSeeds() {
|
|
const seeds = [];
|
|
const count = Math.floor(200 + 800 * params.density);
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
seeds.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
vy: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
life: Math.random() * 200 + 100,
|
|
maxLife: Math.random() * 200 + 100
|
|
});
|
|
}
|
|
return seeds;
|
|
}
|
|
|
|
// Update seeds
|
|
function updateSeeds(seeds) {
|
|
seeds.forEach(seed => {
|
|
seed.x += seed.vx;
|
|
seed.y += seed.vy;
|
|
|
|
// Wrap around edges
|
|
if (seed.x < 0) seed.x = canvas.width;
|
|
if (seed.x > canvas.width) seed.x = 0;
|
|
if (seed.y < 0) seed.y = canvas.height;
|
|
if (seed.y > canvas.height) seed.y = 0;
|
|
|
|
seed.life -= 0.5;
|
|
});
|
|
|
|
// Remove dead seeds and add new ones
|
|
const newSeeds = [];
|
|
seeds.forEach(seed => {
|
|
if (seed.life > 0) newSeeds.push(seed);
|
|
});
|
|
|
|
while (newSeeds.length < Math.floor(200 + 800 * params.density)) {
|
|
newSeeds.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
vy: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
life: Math.random() * 200 + 100,
|
|
maxLife: Math.random() * 200 + 100
|
|
});
|
|
}
|
|
|
|
return newSeeds;
|
|
}
|
|
|
|
// Draw voronoi cells
|
|
function drawVoronoi(seeds) {
|
|
// Clear with semi-transparent to create trails
|
|
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 sites = seeds.map(s => ({ x: s.x, y: s.y }));
|
|
const cells = diagram.compute(sites, bbox);
|
|
|
|
// Draw cells with varying styles
|
|
cells.forEach(cell => {
|
|
if (!cell || !cell.halfedges) return;
|
|
|
|
const points = [];
|
|
cell.halfedges.forEach(he => {
|
|
points.push(he.getStartpoint());
|
|
});
|
|
|
|
if (points.length > 0) {
|
|
// Calculate color based on seed properties
|
|
const seed = seeds[cell.site.voronoiId];
|
|
const lifeRatio = seed.life / seed.maxLife;
|
|
const hue = 120 + 60 * lifeRatio; // Green to yellow
|
|
const saturation = 30 + 70 * (1 - lifeRatio);
|
|
const lightness = 20 + 30 * lifeRatio;
|
|
|
|
// Apply dryness to reduce saturation
|
|
ctx.fillStyle = `hsl(${hue}, ${saturation * (1 - params.tone.dryness)}%, ${lightness}%)`;
|
|
|
|
ctx.beginPath();
|
|
ctx.moveTo(points[0].x, points[0].y);
|
|
for (let i = 1; i < points.length; i++) {
|
|
ctx.lineTo(points[i].x, points[i].y);
|
|
}
|
|
ctx.closePath();
|
|
ctx.fill();
|
|
|
|
// Draw border
|
|
ctx.strokeStyle = `hsla(${hue}, 80%, 20%, 0.3)`;
|
|
ctx.lineWidth = 0.5;
|
|
ctx.stroke();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
const seeds = updateSeeds(window.seeds || generateSeeds());
|
|
window.seeds = seeds;
|
|
drawVoronoi(seeds);
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
// Initialize
|
|
window.seeds = generateSeeds();
|
|
animate();
|
|
})();
|
|
|
|
// Simple Voronoi implementation
|
|
function Voronoi() {
|
|
this.edges = [];
|
|
this.cells = [];
|
|
}
|
|
|
|
Voronoi.prototype.compute = function(sites, bbox) {
|
|
this.edges = [];
|
|
this.cells = sites.map((site, i) => {
|
|
return {
|
|
site: site,
|
|
halfedges: []
|
|
};
|
|
});
|
|
|
|
// Sort sites by x-coordinate
|
|
sites.sort((a, b) => a.x - b.x);
|
|
|
|
// Build fortune diagram (simplified)
|
|
// In a real implementation, this would be more complex
|
|
for (let i = 0; i < sites.length; i++) {
|
|
for (let j = i + 1; j < sites.length; j++) {
|
|
const a = sites[i];
|
|
const b = sites[j];
|
|
const dx = b.x - a.x;
|
|
const dy = b.y - a.y;
|
|
const d = Math.sqrt(dx * dx + dy * dy);
|
|
|
|
// Create edge if within reasonable distance
|
|
if (d < 200) {
|
|
this.edges.push({
|
|
left: a,
|
|
right: b,
|
|
voronoiId: i
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// Assign edges to cells
|
|
this.edges.forEach(edge => {
|
|
const cell = this.cells[edge.voronoiId];
|
|
if (cell) {
|
|
cell.halfedges.push(new HalfEdge(edge));
|
|
}
|
|
});
|
|
|
|
return this.cells;
|
|
};
|
|
|
|
function HalfEdge(edge) {
|
|
this.edge = edge;
|
|
this.angle = Math.atan2(edge.right.y - edge.left.y, edge.right.x - edge.left.x);
|
|
}
|
|
|
|
HalfEdge.prototype.getStartpoint = function() {
|
|
return this.edge.left;
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |