birth: Fractured Light Memories
This commit is contained in:
parent
499be89563
commit
57253fcd77
1 changed files with 123 additions and 0 deletions
123
index.html
Normal file
123
index.html
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<!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;
|
||||
color: #aaa;
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="info">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();
|
||||
|
||||
const points = [];
|
||||
const voronoi = [];
|
||||
const colors = [
|
||||
'#f0f0f0',
|
||||
'#d0d0d0',
|
||||
'#a0a0a0',
|
||||
'#707070'
|
||||
];
|
||||
|
||||
function init() {
|
||||
const count = Math.floor(50 + 200 * 0.5);
|
||||
for (let i = 0; i < count; i++) {
|
||||
points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * 0.5 * (0.5 + 0.5),
|
||||
vy: (Math.random() - 0.5) * 0.5 * (0.5 + 0.5),
|
||||
fixed: Math.random() > 0.7
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
for (const p of points) {
|
||||
if (!p.fixed) {
|
||||
p.x += p.vx;
|
||||
p.y += p.vy;
|
||||
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
||||
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateVoronoi() {
|
||||
voronoi.length = 0;
|
||||
for (let x = 0; x < canvas.width; x += 2) {
|
||||
for (let y = 0; y < canvas.height; y += 2) {
|
||||
if (Math.random() > 0.5) continue;
|
||||
let minDist = Infinity;
|
||||
let closest = 0;
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const d = Math.hypot(x - points[i].x, y - points[i].y);
|
||||
if (d < minDist) {
|
||||
minDist = d;
|
||||
closest = i;
|
||||
}
|
||||
}
|
||||
voronoi.push({
|
||||
x, y,
|
||||
color: colors[closest % colors.length],
|
||||
dist: minDist
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
ctx.fillStyle = '#0a0a0a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.fillStyle = '#1a1a1a';
|
||||
for (const v of voronoi) {
|
||||
ctx.fillStyle = v.color;
|
||||
ctx.fillRect(v.x, v.y, 2, 2);
|
||||
}
|
||||
|
||||
for (const p of points) {
|
||||
ctx.fillStyle = p.fixed ? '#ffaaaa' : '#ffffff';
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, 3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
update();
|
||||
calculateVoronoi();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
init();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue