Spaces:
Running
Running
Download shared/js/wireframe3d.js from Tonic/uas-eus-webhook: direct link, hf CLI and curl.
- Browser
- Download file 4.28 kB
-
https://huggingface.co/spaces/Tonic/uas-eus-webhook/resolve/main/shared/js/wireframe3d.js
- Command line
-
hf download hf://spaces/Tonic/uas-eus-webhook/shared/js/wireframe3d.js
-
curl -L -o wireframe3d.js https://huggingface.co/spaces/Tonic/uas-eus-webhook/resolve/main/shared/js/wireframe3d.js
4.28 kB
| /* Hand-rolled canvas-2D 3D wireframe (no deps): ground grid + wireframe quadcopter + radar rings. | |
| Used as the animated parallax backdrop on c.uas.eus (red on white) and section art on uas.eus. */ | |
| (function () { | |
| function project(p, ry, rx, s, cx, cy) { | |
| // rotate Y then X, weak perspective | |
| var cosY = Math.cos(ry), sinY = Math.sin(ry), cosX = Math.cos(rx), sinX = Math.sin(rx); | |
| var x = p[0] * cosY + p[2] * sinY, z = -p[0] * sinY + p[2] * cosY, y = p[1]; | |
| var y2 = y * cosX - z * sinX, z2 = y * sinX + z * cosX; | |
| var f = 3.2 / (3.2 + z2 * 0.01); | |
| return [cx + x * s * f, cy + y2 * s * f]; | |
| } | |
| function dronePoints(scale) { | |
| var s = scale || 1, pts = [], edges = []; | |
| var body = [[-0.5, 0, 0], [0.5, 0, 0], [0.5, 0.15, 0.35], [-0.5, 0.15, 0.35], [-0.5, 0.15, -0.35], [0.5, 0.15, -0.35], [0, -0.25, 0]]; | |
| body.forEach(function (p) { pts.push([p[0] * s, p[1] * s, p[2] * s]); }); | |
| var be = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [3, 6], [4, 6]]; | |
| be.forEach(function (e) { edges.push(e); }); | |
| var arms = [[-0.4, 0.1, 0.2], [0.4, 0.1, 0.2], [0.4, 0.1, -0.2], [-0.4, 0.1, -0.2]]; | |
| arms.forEach(function (a, i) { | |
| var tip = [a[0] * 2.2 * s, a[1] * s, a[2] * 2.2 * s]; | |
| pts.push(tip); edges.push([6 + i, pts.length - 1]); | |
| // rotor ring (8 pts) | |
| var base = pts.length; | |
| for (var k = 0; k < 8; k++) { | |
| var an = k / 8 * Math.PI * 2; | |
| pts.push([tip[0] + Math.cos(an) * 0.35 * s, tip[1], tip[2] + Math.sin(an) * 0.35 * s]); | |
| } | |
| for (var k2 = 0; k2 < 8; k2++) edges.push([base + k2, base + (k2 + 1) % 8]); | |
| }); | |
| return { pts: pts, edges: edges }; | |
| } | |
| window.Wireframe = { | |
| mount(canvas, opts) { | |
| opts = opts || {}; | |
| var color = opts.color || '#D52B1E'; | |
| var ctx = canvas.getContext('2d'); | |
| var drone = dronePoints(opts.scale || 1); | |
| var W = 0, H = 0, t = 0, raf = 0; | |
| var reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; | |
| function size() { | |
| var dpr = Math.min(window.devicePixelRatio || 1, 2); | |
| W = canvas.clientWidth; H = canvas.clientHeight; | |
| canvas.width = W * dpr; canvas.height = H * dpr; | |
| ctx.setTransform(dpr, 0, 0, dpr, 0, 0); | |
| } | |
| function draw() { | |
| raf = requestAnimationFrame(draw); | |
| if (reduce) t = 0.6; else t += 0.008; | |
| ctx.clearRect(0, 0, W, H); | |
| var cx = W * (opts.cx || 0.5), cy = H * (opts.cy || 0.42); | |
| var s = Math.min(W, H) * (opts.size || 0.16); | |
| var ry = t, rx = -0.42; | |
| // ground grid | |
| ctx.strokeStyle = color; ctx.globalAlpha = 0.16; ctx.lineWidth = 1; | |
| var gs = s * 1.6, n = 9; | |
| for (var i = -n; i <= n; i++) { | |
| var a = project([i * gs / n, 1.6, -gs], 0, rx, 1, cx, cy); | |
| var b = project([i * gs / n, 1.6, gs], 0, rx, 1, cx, cy); | |
| var c = project([-gs, 1.6, i * gs / n], 0, rx, 1, cx, cy); | |
| var d = project([gs, 1.6, i * gs / n], 0, rx, 1, cx, cy); | |
| ctx.beginPath(); ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]); ctx.stroke(); | |
| ctx.beginPath(); ctx.moveTo(c[0], c[1]); ctx.lineTo(d[0], d[1]); ctx.stroke(); | |
| } | |
| ctx.globalAlpha = 0.9; | |
| // radar rings | |
| for (var r = 0; r < 3; r++) { | |
| ctx.globalAlpha = 0.28 - r * 0.08; | |
| ctx.beginPath(); ctx.arc(cx, cy + s * 1.55, s * (0.9 + r * 0.55 + (t * 0.4) % 0.55), 0, Math.PI * 2); ctx.stroke(); | |
| } | |
| // drone | |
| ctx.globalAlpha = 1; ctx.lineWidth = 1.4; | |
| var bob = Math.sin(t * 2.2) * 0.08; | |
| var P = drone.pts.map(function (p) { return project([p[0], p[1] + bob, p[2]], ry, rx, s, cx, cy); }); | |
| ctx.beginPath(); | |
| drone.edges.forEach(function (e) { ctx.moveTo(P[e[0]][0], P[e[0]][1]); ctx.lineTo(P[e[1]][0], P[e[1]][1]); }); | |
| ctx.stroke(); | |
| // sweep line | |
| ctx.globalAlpha = 0.5; | |
| var an = t * 1.7; | |
| ctx.beginPath(); ctx.moveTo(cx, cy + s * 1.55); | |
| ctx.lineTo(cx + Math.cos(an) * s * 2.6, cy + s * 1.55 + Math.sin(an) * s * 2.6); ctx.stroke(); | |
| ctx.globalAlpha = 1; | |
| } | |
| size(); window.addEventListener('resize', size); | |
| draw(); | |
| return { stop: function () { cancelAnimationFrame(raf); } }; | |
| } | |
| }; | |
| })(); | |