/* Cartesian Corp — Three.js hero: an animated 3D surface plot on Cartesian axes with a floating network of "agent" nodes. Falls back silently if WebGL/Three is unavailable. */ (function () { const canvas = document.getElementById('heroCanvas'); if (!canvas || typeof THREE === 'undefined') return; let renderer; try { renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance' }); } catch (e) { return; } const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches; renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); renderer.setClearColor(0x000000, 0); const scene = new THREE.Scene(); scene.fog = new THREE.FogExp2(0xffffff, 0.04); const camera = new THREE.PerspectiveCamera(45, 1, 0.1, 100); camera.position.set(9, 6.5, 12); const root = new THREE.Group(); scene.add(root); const ACCENT = new THREE.Color('#ff5a36'); const ACCENT2 = new THREE.Color('#0b1d2e'); const ACCENT3 = new THREE.Color('#2b4cff'); /* ---------- surface of points z = f(x, y, t) ---------- */ const N = 90, SIZE = 16; const count = N * N; const positions = new Float32Array(count * 3); const colors = new Float32Array(count * 3); for (let i = 0; i < N; i++) { for (let j = 0; j < N; j++) { const k = (i * N + j) * 3; positions[k] = (i / (N - 1) - 0.5) * SIZE; positions[k + 1] = 0; positions[k + 2] = (j / (N - 1) - 0.5) * SIZE; } } const surfGeo = new THREE.BufferGeometry(); surfGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3)); surfGeo.setAttribute('color', new THREE.BufferAttribute(colors, 3)); const dotTex = (() => { const c = document.createElement('canvas'); c.width = c.height = 64; const g = c.getContext('2d'); const grd = g.createRadialGradient(32, 32, 0, 32, 32, 32); grd.addColorStop(0, 'rgba(255,255,255,1)'); grd.addColorStop(0.35, 'rgba(255,255,255,.6)'); grd.addColorStop(1, 'rgba(255,255,255,0)'); g.fillStyle = grd; g.fillRect(0, 0, 64, 64); return new THREE.CanvasTexture(c); })(); const surfMat = new THREE.PointsMaterial({ size: 0.08, map: dotTex, vertexColors: true, transparent: true, depthWrite: false, opacity: 0.95 }); const surface = new THREE.Points(surfGeo, surfMat); root.add(surface); /* ---------- axes with ticks ---------- */ const axisMat = new THREE.LineBasicMaterial({ color: 0x0b1d2e, transparent: true, opacity: 0.45 }); const L = SIZE / 2 + 1; const axesGeo = new THREE.BufferGeometry().setFromPoints([ new THREE.Vector3(-L, 0, 0), new THREE.Vector3(L, 0, 0), new THREE.Vector3(0, -1, 0), new THREE.Vector3(0, 3, 0), new THREE.Vector3(0, 0, -L), new THREE.Vector3(0, 0, L) ]); root.add(new THREE.LineSegments(axesGeo, axisMat)); const tickPts = []; for (let v = -8; v <= 8; v += 2) { if (v === 0) continue; tickPts.push(new THREE.Vector3(v, 0, -0.15), new THREE.Vector3(v, 0, 0.15)); tickPts.push(new THREE.Vector3(-0.15, 0, v), new THREE.Vector3(0.15, 0, v)); } root.add(new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(tickPts), new THREE.LineBasicMaterial({ color: 0x0b1d2e, transparent: true, opacity: 0.35 }))); // faint grid floor const grid = new THREE.GridHelper(SIZE, 16, 0x2b4cff, 0xc9d2e3); grid.position.y = -1.6; grid.material.transparent = true; grid.material.opacity = 0.5; root.add(grid); /* ---------- floating agent network ---------- */ const NODES = 0; // surface plot only — calmer for an enterprise audience const nodes = []; const nodeGroup = new THREE.Group(); root.add(nodeGroup); const nodeGeo = new THREE.SphereGeometry(0.07, 16, 16); for (let i = 0; i < NODES; i++) { const c = i % 5 === 0 ? ACCENT : (i % 2 ? ACCENT3 : ACCENT2); const m = new THREE.Mesh(nodeGeo, new THREE.MeshBasicMaterial({ color: c })); const halo = new THREE.Sprite(new THREE.SpriteMaterial({ map: dotTex, color: c, transparent: true, opacity: 0.18, depthWrite: false })); halo.scale.set(0.8, 0.8, 0.8); const base = new THREE.Vector3(-1 + Math.random() * 8, 1.6 + Math.random() * 2.4, (Math.random() - 0.5) * 10); m.position.copy(base); m.userData = { base, phase: Math.random() * Math.PI * 2, speed: 0.4 + Math.random() * 0.6 }; nodeGroup.add(m); nodes.push(m); } const MAX_LINKS = NODES * NODES; const linkPos = new Float32Array(MAX_LINKS * 6); const linkGeo = new THREE.BufferGeometry(); linkGeo.setAttribute('position', new THREE.BufferAttribute(linkPos, 3)); const links = new THREE.LineSegments(linkGeo, new THREE.LineBasicMaterial({ color: 0x2b4cff, transparent: true, opacity: 0.25 })); nodeGroup.add(links); // data "pulses" travelling from nodes down to the surface const pulses = []; const pulseMat = new THREE.SpriteMaterial({ map: dotTex, color: 0xff5a36, transparent: true, depthWrite: false }); for (let i = 0; i < 0; i++) { const s = new THREE.Sprite(pulseMat.clone()); s.scale.set(0.35, 0.35, 0.35); s.userData = { t: Math.random(), from: nodes[i % NODES] }; root.add(s); pulses.push(s); } /* ---------- interaction ---------- */ const mouse = { x: 0, y: 0, tx: 0, ty: 0 }; window.addEventListener('pointermove', (e) => { mouse.tx = (e.clientX / window.innerWidth) * 2 - 1; mouse.ty = (e.clientY / window.innerHeight) * 2 - 1; }, { passive: true }); let scrollY = 0; window.addEventListener('scroll', () => { scrollY = window.scrollY; }, { passive: true }); function resize() { const w = canvas.clientWidth, h = canvas.clientHeight; if (!w || !h) return; renderer.setSize(w, h, false); camera.aspect = w / h; // push the plot right on wide screens so text stays readable camera.setViewOffset(w, h, w > 900 ? -w * 0.14 : 0, 0, w, h); camera.fov = w < 700 ? 60 : 45; camera.updateProjectionMatrix(); } window.addEventListener('resize', resize); resize(); const cxEl = document.getElementById('cx'); const cyEl = document.getElementById('cy'); /* ---------- loop ---------- */ const clock = new THREE.Clock(); let visible = true; new IntersectionObserver(([e]) => { visible = e.isIntersecting; }, { threshold: 0 }).observe(canvas); const tmp = new THREE.Color(); function f(x, z, t) { const r = Math.sqrt(x * x + z * z); return Math.sin(r * 0.9 - t * 1.4) * 0.6 * Math.exp(-r * 0.08) + Math.sin(x * 0.45 + t * 0.6) * Math.cos(z * 0.4 - t * 0.5) * 0.45; } function frame() { requestAnimationFrame(frame); if (!visible) return; const t = reduced ? 0 : clock.getElapsedTime(); const pos = surfGeo.attributes.position.array; const col = surfGeo.attributes.color.array; for (let k = 0; k < count * 3; k += 3) { const y = f(pos[k], pos[k + 2], t); pos[k + 1] = y; const m = (y + 1.05) / 2.1; tmp.copy(ACCENT3).lerp(ACCENT2, Math.max(0, 0.6 - m)).lerp(ACCENT, Math.max(0, m * 2.2 - 1.6)); const fade = Math.min(1, Math.sqrt(pos[k] * pos[k] + pos[k + 2] * pos[k + 2]) / (SIZE * 0.62)); col[k] = tmp.r + (1 - tmp.r) * fade; col[k + 1] = tmp.g + (1 - tmp.g) * fade; col[k + 2] = tmp.b + (1 - tmp.b) * fade; } surfGeo.attributes.position.needsUpdate = true; surfGeo.attributes.color.needsUpdate = true; // nodes drift for (const n of nodes) { const d = n.userData; n.position.set( d.base.x + Math.sin(t * d.speed + d.phase) * 0.6, d.base.y + Math.cos(t * d.speed * 0.8 + d.phase) * 0.4, d.base.z + Math.cos(t * d.speed + d.phase) * 0.6 ); } let li = 0; for (let i = 0; i < NODES; i++) { for (let j = i + 1; j < NODES; j++) { if (nodes[i].position.distanceToSquared(nodes[j].position) < 12) { const a = nodes[i].position, b = nodes[j].position; linkPos[li++] = a.x; linkPos[li++] = a.y; linkPos[li++] = a.z; linkPos[li++] = b.x; linkPos[li++] = b.y; linkPos[li++] = b.z; } } } linkGeo.setDrawRange(0, li / 3); linkGeo.attributes.position.needsUpdate = true; // pulses fall from node to surface for (const p of pulses) { p.userData.t += 0.006; if (p.userData.t > 1) { p.userData.t = 0; p.userData.from = nodes[(Math.random() * NODES) | 0]; } const src = p.userData.from.position, u = p.userData.t; const ty = f(src.x, src.z, t); p.position.set(src.x, src.y + (ty - src.y) * u * u, src.z); p.material.opacity = Math.sin(u * Math.PI); } // camera parallax + scroll dolly mouse.x += (mouse.tx - mouse.x) * 0.04; mouse.y += (mouse.ty - mouse.y) * 0.04; root.rotation.y = t * 0.04 + mouse.x * 0.25; const s = Math.min(scrollY / window.innerHeight, 1.2); camera.position.set(9 + mouse.x * 1.2, 6.5 - mouse.y * 1.2 + s * 3, 12 - s * 2); camera.lookAt(0, 0.5 - s * 1.5, 0); if (cxEl && !reduced) { cxEl.textContent = (mouse.x * 8).toFixed(3); cyEl.textContent = f(mouse.x * 8, mouse.y * 8, t).toFixed(3); } renderer.render(scene, camera); } frame(); document.documentElement.classList.add('has-3d'); })();