birth: Fractured Light in Motion
This commit is contained in:
parent
3eb1702eb9
commit
52d48fddfc
1 changed files with 222 additions and 0 deletions
222
index.html
Normal file
222
index.html
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
<!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: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
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');
|
||||
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters (abstracted from original input)
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: 1.06,
|
||||
dryness: 0.9,
|
||||
tension: 0.0
|
||||
};
|
||||
|
||||
// Main animation state
|
||||
const state = {
|
||||
points: [],
|
||||
cells: [],
|
||||
time: 0,
|
||||
maxPoints: Math.floor(100 + params.density * 300),
|
||||
maxIterations: 100 + params.complexity * 200,
|
||||
thickness: 1.5 + params.connectedness * 1.5
|
||||
};
|
||||
|
||||
// Initialize points
|
||||
function initPoints() {
|
||||
state.points = [];
|
||||
for (let i = 0; i < state.maxPoints; i++) {
|
||||
state.points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * 2 * params.motion * params.pulse,
|
||||
vy: (Math.random() - 0.5) * 2 * params.motion * params.pulse,
|
||||
life: Math.random() * 100 + 100 * params.lifespan,
|
||||
hue: params.dryness > 0.7 ? Math.random() * 30 : Math.random() * 360
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Update points
|
||||
function updatePoints() {
|
||||
state.points.forEach(p => {
|
||||
p.x += p.vx;
|
||||
p.y += p.vy;
|
||||
p.life--;
|
||||
|
||||
// Wrap around edges
|
||||
if (p.x < 0) p.x = canvas.width;
|
||||
if (p.x > canvas.width) p.x = 0;
|
||||
if (p.y < 0) p.y = canvas.height;
|
||||
if (p.y > canvas.height) p.y = 0;
|
||||
|
||||
// Fade out near death
|
||||
if (p.life < 30) {
|
||||
p.opacity = p.life / 30;
|
||||
}
|
||||
});
|
||||
|
||||
// Remove dead points
|
||||
state.points = state.points.filter(p => p.life > 0);
|
||||
|
||||
// Add new points if needed
|
||||
while (state.points.length < state.maxPoints * 0.8) {
|
||||
state.points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * 2 * params.motion * params.pulse,
|
||||
vy: (Math.random() - 0.5) * 2 * params.motion * params.pulse,
|
||||
life: Math.random() * 100 + 100 * params.lifespan,
|
||||
hue: params.dryness > 0.7 ? Math.random() * 30 : Math.random() * 360
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate voronoi cells
|
||||
function calculateVoronoi() {
|
||||
state.cells = [];
|
||||
|
||||
// Clone points for safety
|
||||
const points = [...state.points];
|
||||
|
||||
// Sort by x coordinate for better performance
|
||||
points.sort((a, b) => a.x - b.x);
|
||||
|
||||
// For each point, find its voronoi cell
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const p1 = points[i];
|
||||
const cell = {
|
||||
points: [p1],
|
||||
edges: [],
|
||||
color: `hsl(${p1.hue}, 80%, ${50 + Math.sin(state.time * 0.01) * 10}%)`
|
||||
};
|
||||
|
||||
// Find neighboring points within influence range
|
||||
const influenceRange = 100 + params.connectedness * 100;
|
||||
|
||||
for (let j = 0; j < points.length; j++) {
|
||||
if (i === j) continue;
|
||||
|
||||
const p2 = points[j];
|
||||
const dx = p2.x - p1.x;
|
||||
const dy = p2.y - p1.y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < influenceRange) {
|
||||
cell.points.push(p2);
|
||||
|
||||
// Create edge between points
|
||||
cell.edges.push({
|
||||
start: p1,
|
||||
end: p2,
|
||||
length: dist
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
state.cells.push(cell);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw voronoi cells
|
||||
function drawVoronoi() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw cells
|
||||
state.cells.forEach(cell => {
|
||||
// Draw cell outline
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cell.points[0].x, cell.points[0].y);
|
||||
|
||||
for (let i = 1; i < Math.min(cell.points.length, 5); i++) {
|
||||
const p = cell.points[i];
|
||||
ctx.lineTo(p.x, p.y);
|
||||
}
|
||||
|
||||
ctx.closePath();
|
||||
ctx.strokeStyle = cell.color;
|
||||
ctx.lineWidth = state.thickness * 0.5;
|
||||
ctx.stroke();
|
||||
|
||||
// Draw edges
|
||||
ctx.beginPath();
|
||||
cell.edges.forEach(edge => {
|
||||
ctx.moveTo(edge.start.x, edge.start.y);
|
||||
ctx.lineTo(edge.end.x, edge.end.y);
|
||||
});
|
||||
ctx.strokeStyle = cell.color;
|
||||
ctx.lineWidth = params.connectedness > 0.5 ? state.thickness * 0.3 : state.thickness * 0.1;
|
||||
ctx.stroke();
|
||||
|
||||
// Draw points
|
||||
cell.points.forEach(p => {
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, 1 + params.connectedness, 0, Math.PI * 2);
|
||||
ctx.fillStyle = cell.color;
|
||||
ctx.fill();
|
||||
});
|
||||
});
|
||||
|
||||
// Add some noise to the background
|
||||
if (params.dryness > 0.7) {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
updatePoints();
|
||||
calculateVoronoi();
|
||||
drawVoronoi();
|
||||
state.time++;
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Start animation
|
||||
initPoints();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue