/* * ICOSIN hero accent — a node network in the shape of Borneo (Equator through Pontianak, * link to the co-host campus), turning gently with the pointer. */ import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js"; const box = document.querySelector(".hero-art"); const canvas = box && box.querySelector("canvas"); const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; function hasWebGL() { try { const c = document.createElement("canvas"); return !!(c.getContext("webgl2") || c.getContext("webgl")); } catch (e) { return false; } } if (canvas && hasWebGL()) { document.documentElement.classList.add("has-3d"); init(); } function init() { const COAST = [ [109.6, 2.1], [110.3, 1.7], [111.2, 2.4], [111.8, 2.9], [113.0, 3.2], [114.0, 4.6], [115.0, 4.9], [115.5, 5.3], [116.1, 6.0], [116.8, 7.0], [117.3, 6.6], [117.7, 5.9], [119.2, 5.1], [118.3, 4.4], [117.8, 4.0], [117.6, 3.0], [118.0, 2.3], [118.9, 1.1], [117.9, 0.8], [117.5, 0.0], [117.5, -0.9], [116.9, -1.5], [116.5, -2.5], [116.2, -3.3], [116.0, -3.9], [115.0, -4.0], [114.5, -3.5], [113.0, -3.2], [112.0, -3.4], [111.6, -3.0], [110.7, -3.0], [110.2, -2.9], [110.0, -1.8], [109.4, -0.9], [109.0, 0.0], [108.9, 0.8], [109.0, 1.5] ]; const S = 0.62, C0 = [114.0, 1.4]; const geo = ([lon, lat]) => [(lon - C0[0]) * S, (lat - C0[1]) * S]; const poly = COAST.map(geo); const PNK = geo([109.33, -0.03]); const SMH = geo([110.5, 1.46]); const EQ_Y = geo([0, 0])[1]; const inside = (x, y) => { let c = false; for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) { const [xi, yi] = poly[i], [xj, yj] = poly[j]; if ((yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c; } return c; }; /* Map layout: the first NET nodes carry the network links, the rest fill the island lightly. */ const NET = 380; const N = 1200; const map = []; let perim = 0; const segs = poly.map((p, i) => { const q = poly[(i + 1) % poly.length]; const l = Math.hypot(q[0] - p[0], q[1] - p[1]); perim += l; return { p, q, l }; }); const EDGE = 120; for (let k = 0; k < EDGE; k++) { let d = (k / EDGE) * perim; for (const s of segs) { if (d <= s.l) { const t = d / s.l; map.push([s.p[0] + (s.q[0] - s.p[0]) * t, s.p[1] + (s.q[1] - s.p[1]) * t, 0]); break; } d -= s.l; } } while (map.length < N) { const x = (Math.random() - 0.5) * 7.2, y = (Math.random() - 0.5) * 7.4; if (inside(x, y)) map.push([x, y, (Math.random() - 0.5) * (map.length < NET ? 0.8 : 0.3)]); } const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true }); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100); camera.position.set(0, -0.2, 12.4); const group = new THREE.Group(); scene.add(group); const GREEN = new THREE.Color("#0e5a4a"), TERRA = new THREE.Color("#b5532f"), GOLD = new THREE.Color("#c9a54a"); /* Particles */ const pos = new Float32Array(N * 3), col = new Float32Array(N * 3); for (let i = 0; i < N; i++) { pos.set(map[i], i * 3); const c = i < NET ? (Math.random() < 0.12 ? TERRA : GREEN) : GREEN; col.set([c.r, c.g, c.b], i * 3); } const pGeo = new THREE.BufferGeometry(); pGeo.setAttribute("position", new THREE.BufferAttribute(pos, 3)); pGeo.setAttribute("color", new THREE.BufferAttribute(col, 3)); const dot = (() => { const c = document.createElement("canvas"); c.width = c.height = 64; const g = c.getContext("2d"); g.beginPath(); g.arc(32, 32, 28, 0, Math.PI * 2); g.fillStyle = "#fff"; g.fill(); return new THREE.CanvasTexture(c); })(); const pMat = new THREE.PointsMaterial({ size: 0.06, vertexColors: true, map: dot, transparent: true, alphaTest: 0.4 }); group.add(new THREE.Points(pGeo, pMat)); /* Network links among the first NET nodes. */ const pairs = []; for (let i = 0; i < NET; i++) { let f = 0; for (let j = i + 1; j < NET && f < 3; j++) { const dx = map[i][0] - map[j][0], dy = map[i][1] - map[j][1]; if (dx * dx + dy * dy < 0.36) { pairs.push(i, j); f++; } } } const lPos = new Float32Array(pairs.length * 3); for (let p = 0; p < pairs.length; p++) lPos.set(map[pairs[p]], p * 3); const lGeo = new THREE.BufferGeometry(); lGeo.setAttribute("position", new THREE.BufferAttribute(lPos, 3)); const lMat = new THREE.LineBasicMaterial({ color: GREEN, transparent: true, opacity: 0.22 }); group.add(new THREE.LineSegments(lGeo, lMat)); /* Map furniture: Equator, the two campuses and the link between them. */ const eqMat = new THREE.LineDashedMaterial({ color: GOLD, dashSize: 0.14, gapSize: 0.1, transparent: true }); const eq = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(-4.6, EQ_Y, 0), new THREE.Vector3(4.6, EQ_Y, 0)]), eqMat); eq.computeLineDistances(); group.add(eq); const A = new THREE.Vector3(PNK[0], PNK[1], 0), B = new THREE.Vector3(SMH[0], SMH[1], 0); const rings = []; [A, B].forEach((v) => { const dm = new THREE.MeshBasicMaterial({ color: TERRA, transparent: true }); const m = new THREE.Mesh(new THREE.SphereGeometry(0.11, 24, 16), dm); m.position.copy(v); group.add(m); const rm = new THREE.MeshBasicMaterial({ color: TERRA, transparent: true, opacity: 0.5, side: THREE.DoubleSide }); const ring = new THREE.Mesh(new THREE.RingGeometry(0.18, 0.21, 40), rm); ring.position.copy(v); group.add(ring); rings.push(ring); }); const mid = A.clone().add(B).multiplyScalar(0.5).add(new THREE.Vector3(-0.3, 0.1, 0.9)); const arcMat = new THREE.LineBasicMaterial({ color: TERRA, transparent: true }); group.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints(new THREE.QuadraticBezierCurve3(A, mid, B).getPoints(40)), arcMat)); const labels = [ { el: box.querySelector("[data-city=pnk]"), v: A }, { el: box.querySelector("[data-city=smh]"), v: B } ]; function resize() { const w = box.clientWidth, h = box.clientHeight; renderer.setSize(w, h, false); camera.aspect = w / h; camera.updateProjectionMatrix(); } resize(); window.addEventListener("resize", resize); const mouse = { x: 0, y: 0 }; if (!reduceMotion) { box.addEventListener("pointermove", (e) => { const r = box.getBoundingClientRect(); mouse.x = ((e.clientX - r.left) / r.width - 0.5) * 2; mouse.y = ((e.clientY - r.top) / r.height - 0.5) * 2; }); box.addEventListener("pointerleave", () => { mouse.x = 0; mouse.y = 0; }); } const tmp = new THREE.Vector3(); const spin = new THREE.Clock(); let visible = true; new IntersectionObserver(([e]) => { visible = e.isIntersecting; }).observe(box); function frame() { const t = reduceMotion ? 0 : spin.getElapsedTime(); // turn gently with time and the pointer const swayY = Math.sin(t * 0.25) * 0.35 + mouse.x * 0.25; const swayX = -0.12 + mouse.y * 0.12; group.rotation.y += (swayY - group.rotation.y) * 0.06; group.rotation.x += (swayX - group.rotation.x) * 0.06; rings.forEach((r) => r.scale.setScalar(1 + 0.25 * Math.sin(t * 2.4))); renderer.render(scene, camera); const w = box.clientWidth, h = box.clientHeight; group.updateMatrixWorld(); labels.forEach((l) => { if (!l.el) return; tmp.copy(l.v).applyMatrix4(group.matrixWorld).project(camera); l.el.style.transform = `translate(${((tmp.x + 1) / 2) * w + 14}px, ${((1 - tmp.y) / 2) * h}px) translateY(-50%)`; l.el.classList.add("show"); }); } if (reduceMotion) { frame(); window.addEventListener("resize", frame); } else renderer.setAnimationLoop(() => { if (visible) frame(); }); }