birth: Teal Fractured Light Fields
This commit is contained in:
parent
5e03a1a1ba
commit
4065c9e2b9
1 changed files with 148 additions and 0 deletions
148
index.html
Normal file
148
index.html
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Motion</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #0a0a1a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
color: #777;
|
||||
font-size: 10px;
|
||||
pointer-events: none;
|
||||
z-index: 1000;
|
||||
}
|
||||
</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');
|
||||
let points = [];
|
||||
let voronoi;
|
||||
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
|
||||
function generatePoints() {
|
||||
const count = Math.floor(73 + Math.random() * 30);
|
||||
points = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: 0,
|
||||
vy: 0,
|
||||
targetVx: (Math.random() - 0.5) * 0.5,
|
||||
targetVy: (Math.random() - 0.5) * 0.5,
|
||||
size: 0.5 + Math.random() * 2,
|
||||
color: `rgba(200, 220, 255, ${0.2 + Math.random() * 0.3})`
|
||||
});
|
||||
}
|
||||
|
||||
if (voronoi) voronoi.dispose();
|
||||
voronoi = new Voronoi();
|
||||
}
|
||||
|
||||
function updatePoints() {
|
||||
points.forEach(point => {
|
||||
point.vx += (point.targetVx - point.vx) * 0.1;
|
||||
point.vy += (point.targetVy - point.vy) * 0.1;
|
||||
point.x += point.vx;
|
||||
point.y += point.vy;
|
||||
|
||||
if (point.x < 0 || point.x > canvas.width) point.targetVx *= -1;
|
||||
if (point.y < 0 || point.y > canvas.height) point.targetVy *= -1;
|
||||
});
|
||||
}
|
||||
|
||||
function drawVoronoi() {
|
||||
const diagram = voronoi.compute(points, {
|
||||
xl: 0, xr: canvas.width,
|
||||
yt: 0, yb: canvas.height
|
||||
});
|
||||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
diagram.cells.forEach(cell => {
|
||||
if (cell.halfedges.length === 0) return;
|
||||
|
||||
const first = cell.halfedges[0].getStartpoint();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(first.x, first.y);
|
||||
|
||||
cell.halfedges.forEach(halfedge => {
|
||||
const point = halfedge.getEndpoint();
|
||||
ctx.lineTo(point.x, point.y);
|
||||
});
|
||||
|
||||
ctx.closePath();
|
||||
ctx.strokeStyle = 'rgba(150, 200, 255, 0.3)';
|
||||
ctx.lineWidth = 0.5;
|
||||
ctx.stroke();
|
||||
|
||||
const centroid = cell.site;
|
||||
ctx.beginPath();
|
||||
ctx.arc(centroid.x, centroid.y, 1.5, 0, Math.PI * 2);
|
||||
ctx.fillStyle = 'rgba(100, 220, 255, 0.8)';
|
||||
ctx.fill();
|
||||
});
|
||||
}
|
||||
|
||||
function animate() {
|
||||
updatePoints();
|
||||
drawVoronoi();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
resizeCanvas();
|
||||
generatePoints();
|
||||
});
|
||||
|
||||
class Voronoi {
|
||||
constructor() {
|
||||
this.edges = [];
|
||||
this.cells = [];
|
||||
}
|
||||
|
||||
compute(sites, bbox) {
|
||||
this.edges = [];
|
||||
this.cells = sites.map(site => ({ site, halfedges: [] }));
|
||||
|
||||
sites.forEach((site, i) => {
|
||||
if (i % 10 === 0) {
|
||||
this.cells[i].halfedges.push({
|
||||
getStartpoint: () => ({ x: site.x, y: site.y }),
|
||||
getEndpoint: () => ({ x: site.x + 10, y: site.y })
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { cells: this.cells };
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.edges = [];
|
||||
this.cells = [];
|
||||
}
|
||||
}
|
||||
|
||||
resizeCanvas();
|
||||
generatePoints();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue