birth: Fractured Light Voronoi
This commit is contained in:
parent
9838d2b557
commit
e0d2086c31
1 changed files with 196 additions and 0 deletions
196
index.html
Normal file
196
index.html
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
<!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;
|
||||
color: #666;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
font-size: 10px;
|
||||
color: #444;
|
||||
text-align: right;
|
||||
}
|
||||
</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 resize() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resize);
|
||||
resize();
|
||||
|
||||
// Parameters derived from prompt
|
||||
const params = {
|
||||
motion: 0.544,
|
||||
density: 0.459,
|
||||
complexity: 0.335,
|
||||
connectedness: 0.558,
|
||||
lifespan: 0.292,
|
||||
survivingNodes: 5,
|
||||
branchCount: 4,
|
||||
loops: 12,
|
||||
maxDepth: 4,
|
||||
thicknessRatio: 1.00,
|
||||
fractalDimension: 1.000,
|
||||
finalEnergy: 34.4,
|
||||
pulse: { avg: 0.41, min: 0.30, max: 1.25 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.10, dryness: 0.80, playfulness: 0.10, tension: 0.00 }
|
||||
};
|
||||
|
||||
// State
|
||||
const points = [];
|
||||
const cells = [];
|
||||
let time = 0;
|
||||
const hues = [20, 40, 60]; // muted dryness palette
|
||||
|
||||
// Initialize points with voronoi seed
|
||||
function initPoints() {
|
||||
points.length = 0;
|
||||
const count = Math.floor(50 + params.density * 300);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
points.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,
|
||||
hue: hues[Math.floor(Math.random() * hues.length)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Update points with pulse-driven motion
|
||||
function updatePoints() {
|
||||
points.forEach(p => {
|
||||
p.x += p.vx * params.pulse.avg;
|
||||
p.y += p.vy * params.pulse.avg;
|
||||
p.life += 0.1;
|
||||
|
||||
// Bounce at edges
|
||||
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
||||
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
||||
});
|
||||
}
|
||||
|
||||
// Generate voronoi cells
|
||||
function generateVoronoi() {
|
||||
cells.length = 0;
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const cell = {
|
||||
center: points[i],
|
||||
neighbors: [],
|
||||
thickness: 0.5 + params.thicknessRatio * 0.5,
|
||||
depth: 0
|
||||
};
|
||||
cells.push(cell);
|
||||
|
||||
// Find neighbors (simplified)
|
||||
for (let j = 0; j < points.length; j++) {
|
||||
if (i !== 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 < 100 * (1 - params.complexity)) {
|
||||
cell.neighbors.push(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw voronoi with fractal recursion
|
||||
function drawVoronoi() {
|
||||
// Background fade
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw cells
|
||||
cells.forEach(cell => {
|
||||
// Draw cell border
|
||||
ctx.strokeStyle = `hsl(${cell.center.hue}, 30%, ${70 - params.pulse.avg * 20}%)`;
|
||||
ctx.lineWidth = cell.thickness * (0.5 + Math.sin(time * 0.1) * 0.5);
|
||||
|
||||
// Simplified cell drawing (actual voronoi would use Fortune's algorithm)
|
||||
ctx.beginPath();
|
||||
const size = 50 + params.complexity * 50;
|
||||
ctx.arc(cell.center.x, cell.center.y, size, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
|
||||
// Draw connecting lines to neighbors
|
||||
cell.neighbors.forEach(neighbor => {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cell.center.x, cell.center.y);
|
||||
ctx.lineTo(points[neighbor].x, points[neighbor].y);
|
||||
ctx.stroke();
|
||||
});
|
||||
});
|
||||
|
||||
// Recursive fractal centers
|
||||
if (params.fractalDimension > 0.9) {
|
||||
ctx.strokeStyle = 'hsla(200, 30%, 70%, 0.3)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
const count = Math.floor(3 + params.complexity * 7);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const x = Math.random() * canvas.width;
|
||||
const y = Math.random() * canvas.height;
|
||||
const depth = 3;
|
||||
|
||||
drawFractalLine(x, y, depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawFractalLine(x, y, depth) {
|
||||
if (depth <= 0) return;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, y);
|
||||
|
||||
const angle = time * 0.05 * params.motion;
|
||||
const length = 20 * (1 - params.complexity) + 40 * params.complexity;
|
||||
const nx = x + Math.cos(angle) * length;
|
||||
const ny = y + Math.sin(angle) * length;
|
||||
|
||||
ctx.lineTo(nx, ny);
|
||||
ctx.stroke();
|
||||
|
||||
drawFractalLine(nx, ny, depth - 1);
|
||||
}
|
||||
|
||||
// Main animation loop
|
||||
function animate() {
|
||||
time += 0.01;
|
||||
|
||||
updatePoints();
|
||||
generateVoronoi();
|
||||
drawVoronoi();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initPoints();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue