birth: Fractured Monochrome Geometry
This commit is contained in:
parent
adc408d290
commit
9a4b6cdb04
1 changed files with 188 additions and 0 deletions
188
index.html
Normal file
188
index.html
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
<!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: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
font-size: 12px;
|
||||
pointer-events: none;
|
||||
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
</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
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.06, min: 1.0, max: 1.1 },
|
||||
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
|
||||
};
|
||||
|
||||
// State
|
||||
const sites = [];
|
||||
const edges = [];
|
||||
const maxEdgeCount = Math.floor(500 + params.density * 1000);
|
||||
const baseComplexity = params.complexity;
|
||||
let frameCount = 0;
|
||||
|
||||
// Color palette
|
||||
function getColor() {
|
||||
const hue = 0; // Monochrome
|
||||
const value = 50 + Math.sin(frameCount * 0.05) * 10;
|
||||
return `hsl(${hue}, 0%, ${value}%)`;
|
||||
}
|
||||
|
||||
// Generate initial Voronoi sites
|
||||
function generateSites() {
|
||||
const count = Math.floor(50 + params.density * 50);
|
||||
for (let i = 0; i < count; i++) {
|
||||
sites.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * 2 * params.motion,
|
||||
vy: (Math.random() - 0.5) * 2 * params.motion,
|
||||
life: Math.random() * 100 + 50
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate Voronoi edges (simplified)
|
||||
function calculateEdges() {
|
||||
edges.length = 0;
|
||||
|
||||
// Simple Delaunay triangulation approximation
|
||||
for (let i = 0; i < sites.length; i++) {
|
||||
for (let j = i + 1; j < sites.length; j++) {
|
||||
const dx = sites[j].x - sites[i].x;
|
||||
const dy = sites[j].y - sites[i].y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 100 * baseComplexity) {
|
||||
edges.push({
|
||||
a: i,
|
||||
b: j,
|
||||
dist: dist
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Limit edges to maintain density
|
||||
edges.sort((a, b) => a.dist - b.dist);
|
||||
edges.length = Math.min(edges.length, maxEdgeCount);
|
||||
}
|
||||
|
||||
// Update sites and edges
|
||||
function update() {
|
||||
frameCount++;
|
||||
|
||||
// Update sites
|
||||
for (let i = 0; i < sites.length; i++) {
|
||||
const site = sites[i];
|
||||
site.x += site.vx;
|
||||
site.y += site.vy;
|
||||
|
||||
// Bounce at edges
|
||||
if (site.x < 0 || site.x > canvas.width) site.vx *= -1;
|
||||
if (site.y < 0 || site.y > canvas.height) site.vy *= -1;
|
||||
|
||||
site.life -= 1 * params.lifespan;
|
||||
|
||||
// Split on death
|
||||
if (site.life <= 0 && sites.length < maxEdgeCount * 2) {
|
||||
sites.push({
|
||||
x: site.x,
|
||||
y: site.y,
|
||||
vx: (Math.random() - 0.5) * 2 * params.motion,
|
||||
vy: (Math.random() - 0.5) * 2 * params.motion,
|
||||
life: Math.random() * 100 + 50
|
||||
});
|
||||
site.life = 200; // Reset parent
|
||||
}
|
||||
}
|
||||
|
||||
// Occasionally regenerate edges
|
||||
if (frameCount % 30 === 0 || edges.length < maxEdgeCount * 0.5) {
|
||||
calculateEdges();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
function draw() {
|
||||
// Fade background
|
||||
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw edges
|
||||
ctx.strokeStyle = getColor();
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
|
||||
for (const edge of edges) {
|
||||
const a = sites[edge.a];
|
||||
const b = sites[edge.b];
|
||||
ctx.moveTo(a.x, a.y);
|
||||
ctx.lineTo(b.x, b.y);
|
||||
}
|
||||
|
||||
ctx.stroke();
|
||||
|
||||
// Draw sites
|
||||
for (const site of sites) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(site.x, site.y, 2, 0, Math.PI * 2);
|
||||
ctx.fillStyle = getColor();
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Pulse effect
|
||||
const pulse = params.pulse.avg + Math.sin(frameCount * 0.1) * 0.05;
|
||||
document.body.style.transform = `scale(${pulse})`;
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
update();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Initialize
|
||||
generateSites();
|
||||
calculateEdges();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue