190 lines
5.6 KiB
HTML
190 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Globe Loader</title>
|
|
<style>
|
|
html, body {
|
|
margin: 0;
|
|
height: 100%;
|
|
background: transparent;
|
|
}
|
|
body {
|
|
display: grid;
|
|
place-items: center;
|
|
background: transparent;
|
|
}
|
|
/* Square loader that fills its embedding container (keeps 1:1 proportions). */
|
|
.globe-loader {
|
|
width: 100%;
|
|
height: 100%;
|
|
aspect-ratio: 1 / 1;
|
|
/* monochrome ink — white to match the link text on the dark glass card */
|
|
color: #ffffff;
|
|
background: transparent;
|
|
}
|
|
.globe-loader canvas {
|
|
display: block;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="globe-loader" role="status" aria-label="Loading">
|
|
<canvas id="globe" width="200" height="200"></canvas>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/d3@7.9.0/dist/d3.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/topojson-client@3.1.0/dist/topojson-client.min.js"></script>
|
|
<script>
|
|
(function () {
|
|
const SIZE = 200;
|
|
const canvas = document.getElementById('globe');
|
|
const ctx = canvas.getContext('2d');
|
|
const loader = document.querySelector('.globe-loader');
|
|
|
|
// Resolve the ink color from CSS so the loader is themeable via `color`.
|
|
const ink = getComputedStyle(loader).color;
|
|
|
|
// ---- High-DPI setup -------------------------------------------------
|
|
const dpr = Math.max(1, Math.min(3, window.devicePixelRatio || 1));
|
|
canvas.width = SIZE * dpr;
|
|
canvas.height = SIZE * dpr;
|
|
ctx.scale(dpr, dpr);
|
|
|
|
const cx = SIZE / 2;
|
|
const cy = SIZE / 2;
|
|
const R = 78; // globe radius in px
|
|
|
|
// ---- Projection -----------------------------------------------------
|
|
const projection = d3.geoOrthographic()
|
|
.scale(R)
|
|
.translate([cx, cy])
|
|
.clipAngle(90);
|
|
|
|
const path = d3.geoPath(projection, ctx);
|
|
const graticule = d3.geoGraticule10();
|
|
|
|
let land = null; // merged land outline
|
|
let borders = null; // interior country borders
|
|
|
|
// ---- Whirl particles ------------------------------------------------
|
|
const TILT = -0.62; // plane tilt (radians)
|
|
const cosT = Math.cos(TILT), sinT = Math.sin(TILT);
|
|
const PARTICLES = 46;
|
|
const particles = [];
|
|
for (let i = 0; i < PARTICLES; i++) {
|
|
const rad = R + 6 + Math.random() * 18; // orbit radius
|
|
particles.push({
|
|
a: Math.random() * Math.PI * 2, // angle
|
|
rad,
|
|
speed: 0.9 + (1 - (rad - R) / 24) * 1.4 + Math.random() * 0.3,
|
|
size: 0.7 + Math.random() * 1.5,
|
|
squash: 0.30 + Math.random() * 0.14, // ellipse flattening
|
|
});
|
|
}
|
|
|
|
function drawParticle(p, front) {
|
|
const ex = Math.cos(p.a) * p.rad;
|
|
const ey = Math.sin(p.a) * p.rad * p.squash;
|
|
const x = cx + ex * cosT - ey * sinT;
|
|
const y = cy + ex * sinT + ey * cosT;
|
|
|
|
const depth = Math.sin(p.a);
|
|
const isFront = depth >= 0;
|
|
if (isFront !== front) return;
|
|
|
|
const TRAIL = 7;
|
|
for (let t = 0; t < TRAIL; t++) {
|
|
const aa = p.a - t * 0.05;
|
|
const tex = Math.cos(aa) * p.rad;
|
|
const tey = Math.sin(aa) * p.rad * p.squash;
|
|
const tx = cx + tex * cosT - tey * sinT;
|
|
const ty = cy + tex * sinT + tey * cosT;
|
|
const fade = (1 - t / TRAIL);
|
|
const near = (Math.sin(aa) + 1) / 2; // 0 back .. 1 front
|
|
const alpha = fade * (0.18 + near * 0.55);
|
|
ctx.globalAlpha = alpha;
|
|
ctx.beginPath();
|
|
ctx.arc(tx, ty, p.size * (0.5 + fade * 0.5), 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
ctx.globalAlpha = 1;
|
|
}
|
|
|
|
// ---- Render loop ----------------------------------------------------
|
|
let lambda = 0; // rotation longitude
|
|
let last = performance.now();
|
|
|
|
function frame() {
|
|
const now = performance.now();
|
|
const dt = Math.min(50, now - last) / 1000;
|
|
last = now;
|
|
|
|
lambda += dt * 22; // spin speed (deg/sec)
|
|
projection.rotate([lambda, -16, 0]);
|
|
|
|
ctx.clearRect(0, 0, SIZE, SIZE);
|
|
ctx.fillStyle = ink;
|
|
ctx.strokeStyle = ink;
|
|
ctx.lineJoin = 'round';
|
|
ctx.lineCap = 'round';
|
|
|
|
for (const p of particles) p.a += dt * p.speed;
|
|
|
|
for (const p of particles) drawParticle(p, false);
|
|
|
|
ctx.globalAlpha = 0.9;
|
|
ctx.lineWidth = 1.4;
|
|
ctx.beginPath();
|
|
ctx.arc(cx, cy, R, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
|
|
ctx.globalAlpha = 0.16;
|
|
ctx.lineWidth = 0.6;
|
|
ctx.beginPath();
|
|
path(graticule);
|
|
ctx.stroke();
|
|
|
|
if (land) {
|
|
ctx.globalAlpha = 0.95;
|
|
ctx.lineWidth = 1.1;
|
|
ctx.beginPath();
|
|
path(land);
|
|
ctx.stroke();
|
|
}
|
|
if (borders) {
|
|
ctx.globalAlpha = 0.42;
|
|
ctx.lineWidth = 0.7;
|
|
ctx.beginPath();
|
|
path(borders);
|
|
ctx.stroke();
|
|
}
|
|
|
|
ctx.globalAlpha = 1;
|
|
for (const p of particles) drawParticle(p, true);
|
|
|
|
ctx.globalAlpha = 1;
|
|
}
|
|
frame();
|
|
setInterval(frame, 1000 / 60);
|
|
|
|
// ---- Load real country geometry ------------------------------------
|
|
const SRC = 'https://cdn.jsdelivr.net/npm/world-atlas@2.0.2/countries-110m.json';
|
|
fetch(SRC)
|
|
.then(r => r.json())
|
|
.then(world => {
|
|
const countries = topojson.feature(world, world.objects.countries);
|
|
land = countries;
|
|
borders = topojson.mesh(world, world.objects.countries, (a, b) => a !== b);
|
|
})
|
|
.catch(() => {
|
|
console.warn('world-atlas fetch failed; showing graticule globe only');
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|