Prompt specification
Build or customize the Three.js 3D scene "Every Dot Observes Separation Growth" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Every Dot Observes Separation Growth
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/every-dot-observes-separation-growth-x3770
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Animate uniform scale expansion and switch the reference dot. Show relative distance changes from each choice without presenting the display's center as a center of the universe.
Working Three.js Starter (every-dot-observes-separation-growth-x3770):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Local Frame — Relative Distance Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #061018;
--panel: rgba(11, 25, 36, 0.86);
--panel-border: rgba(180, 222, 255, 0.13);
--text: #edf8ff;
--muted: #91a8b9;
--accent: #67e8f9;
--accent-soft: rgba(103, 232, 249, 0.14);
--grid: rgba(151, 209, 230, 0.1);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
min-height: 100vh;
background:
radial-gradient(
circle at 18% 8%,
rgba(32, 100, 125, 0.22),
transparent 34rem
),
radial-gradient(
circle at 88% 90%,
rgba(80, 55, 125, 0.16),
transparent 38rem
),
#061018;
}
button {
font: inherit;
}
.app {
width: min(1500px, calc(100% - 32px));
margin: 0 auto;
padding: 26px 0 22px;
}
.page-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 32px;
margin-bottom: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin: 0 0 8px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
content: "";
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
h1 {
margin: 0;
font-size: clamp(1.9rem, 4vw, 3.4rem);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 1;
}
.header-note {
max-width: 560px;
margin: 0;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.6;
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
min-height: 650px;
height: min(790px, calc(100vh - 190px));
gap: 16px;
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 26px;
background:
radial-gradient(
circle at 48% 42%,
rgba(43, 105, 130, 0.12),
transparent 37%
),
linear-gradient(
145deg,
rgba(13, 31, 44, 0.9),
rgba(5, 13, 21, 0.96)
);
box-shadow:
0 30px 90px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.03);
isolation: isolate;
}
.stage::before {
position: absolute;
inset: 0;
z-index: 0;
pointer-events: none;
content: "";
opacity: 0.28;
background-image:
linear-gradient(var(--grid) 1px, transparent 1px),
linear-gradient(90deg, var(--grid) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: radial-gradient(circle at center, black, transparent 78%);
}
.webgl {
position: absolute;
inset: 0;
z-index: 1;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.webgl:focus-visible {
box-shadow: inset 0 0 0 2px var(--accent);
}
.stage-heading {
position: absolute;
top: 22px;
left: 24px;
z-index: 3;
max-width: 340px;
pointer-events: none;
}
.stage-heading .kicker {
color: var(--accent);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-heading h2 {
margin: 7px 0 5px;
font-size: 1.1rem;
font-weight: 650;
letter-spacing: -0.02em;
}
.stage-heading p {
margin: 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.45;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
z-index: 3;
display: flex;
align-items: center;
gap: 15px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(4, 12, 18, 0.55);
color: var(--muted);
font-size: 0.68rem;
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 19px;
height: 0;
border-top: 2px solid var(--accent);
}
.legend i.dashed {
border-top: 1px dashed #8da2af;
}
.control-dock {
position: absolute;
right: 20px;
bottom: 20px;
left: 20px;
z-index: 4;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 13px 14px 13px 18px;
border: 1px solid rgba(173, 220, 241, 0.12);
border-radius: 18px;
background: rgba(5, 14, 21, 0.78);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(18px);
}
.scale-readout {
min-width: 165px;
}
.scale-readout strong {
display: block;
font-size: 1.15rem;
letter-spacing: -0.02em;
}
.scale-readout small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.68rem;
}
.scale-track {
position: relative;
width: min(290px, 27vw);
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.scale-track span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #38bdf8, #67e8f9);
box-shadow: 0 0 12px rgba(103, 232, 249, 0.5);
}
.control-actions {
display: flex;
gap: 8px;
}
.action {
min-height: 40px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.action:hover {
transform: translateY(-1px);
border-color: rgba(103, 232, 249, 0.42);
background: rgba(103, 232, 249, 0.1);
}
.action:focus-visible,
.ref-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.action.primary {
border-color: rgba(103, 232, 249, 0.36);
background: var(--accent-soft);
color: #d9fbff;
font-weight: 700;
}
.camera-hint {
position: absolute;
bottom: 96px;
left: 24px;
z-index: 3;
color: rgba(202, 222, 233, 0.56);
font-size: 0.69rem;
pointer-events: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.node-label {
position: absolute;
min-width: 64px;
padding: 6px 8px;
transform: translate(-50%, -118%);
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 9px;
background: rgba(3, 10, 16, 0.82);
color: #eaf8ff;
font-size: 0.72rem;
font-weight: 800;
line-height: 1.1;
text-align: center;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(9px);
transition:
border-color 180ms ease,
opacity 120ms ease;
}
.node-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.58rem;
font-weight: 600;
letter-spacing: 0.04em;
}
.node-label.reference {
border-color: rgba(103, 232, 249, 0.68);
background: rgba(8, 32, 43, 0.93);
box-shadow:
0 8px 24px rgba(0, 0, 0, 0.28),
0 0 20px rgba(103, 232, 249, 0.12);
}
.panel {
min-width: 0;
overflow: auto;
padding: 22px;
border: 1px solid var(--panel-border);
border-radius: 26px;
background: var(--panel);
box-shadow:
0 30px 80px rgba(0, 0, 0, 0.22),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(20px);
scrollbar-width: thin;
scrollbar-color: rgba(103, 232, 249, 0.3) transparent;
}
.panel-section + .panel-section {
margin-top: 24px;
padding-top: 22px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.section-label {
display: block;
margin-bottom: 12px;
color: var(--muted);
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.reference-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 7px;
}
.ref-button {
position: relative;
min-height: 48px;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 12px;
background: rgba(255, 255, 255, 0.04);
color: var(--muted);
cursor: pointer;
transition:
transform 160ms ease,
color 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.ref-button:hover {
transform: translateY(-2px);
color: white;
border-color: rgba(255, 255, 255, 0.2);
}
.ref-button[aria-checked="true"] {
border-color: var(--c);
background: color-mix(in srgb, var(--c) 13%, transparent);
color: white;
box-shadow: 0 0 20px color-mix(in srgb, var(--c) 13%, transparent);
}
.ref-button i {
display: block;
width: 9px;
height: 9px;
margin: 0 auto 4px;
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 10px var(--c);
}
.ref-button span {
font-size: 0.72rem;
font-weight: 800;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.panel h2 {
margin: 0;
font-size: 1.25rem;
font-weight: 660;
letter-spacing: -0.025em;
}
.scale-badge {
padding: 6px 9px;
border: 1px solid rgba(103, 232, 249, 0.23);
border-radius: 999px;
background: var(--accent-soft);
color: #baf7ff;
font-size: 0.74rem;
font-weight: 800;
}
.panel-description {
margin: 8px 0 16px;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.5;
}
.metrics {
display: grid;
gap: 8px;
}
.metric {
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 14px;
background: rgba(255, 255, 255, 0.027);
transition:
border-color 180ms ease,
background 180ms ease;
}
.metric.is-reference {
border-color: rgba(103, 232, 249, 0.23);
background: rgba(103, 232, 249, 0.055);
}
.metric-head,
.metric-values,
.metric-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.metric-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.79rem;
}
.metric-name i {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 8px color-mix(in srgb, var(--c) 55%, transparent);
}
.metric-rank {
color: var(--muted);
font-size: 0.64rem;
font-weight: 650;
}
.metric-values {
margin-top: 9px;
color: var(--muted);
font-size: 0.66rem;
font-variant-numeric: tabular-nums;
}
.metric-values strong {
color: var(--text);
font-size: 0.92rem;
}
.meter {
position: relative;
height: 5px;
margin: 9px 0 7px;
overflow: visible;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.meter-fill {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(
90deg,
color-mix(in srgb, var(--c) 55%, #143847),
var(--c)
);
box-shadow: 0 0 10px color-mix(in srgb, var(--c) 28%, transparent);
}
.meter-base {
position: absolute;
top: -2px;
left: 0;
width: 2px;
height: 9px;
border-radius: 2px;
background: #a5b8c3;
opacity: 0.65;
}
.metric-foot {
color: var(--muted);
font-size: 0.64rem;
font-variant-numeric: tabular-nums;
}
.metric-change {
color: #67e8f9;
font-weight: 750;
}
.insight {
padding: 14px;
border: 1px solid rgba(103, 232, 249, 0.14);
border-radius: 14px;
background:
linear-gradient(
135deg,
rgba(103, 232, 249, 0.07),
rgba(103, 232, 249, 0.015)
);
}
.insight strong {
display: block;
margin-bottom: 6px;
color: #d9faff;
font-size: 0.78rem;
}
.insight p {
margin: 0;
color: var(--muted);
font-size: 0.7rem;
line-height: 1.55;
}
.page-footer {
display: flex;
justify-content: space-between;
gap: 24px;
margin-top: 13px;
padding: 0 4px;
color: rgba(183, 205, 218, 0.58);
font-size: 0.68rem;
line-height: 1.5;
}
.page-footer p {
margin: 0;
}
.page-footer p:last-child {
text-align: right;
}
@media (max-width: 1050px) {
.workspace {
grid-template-columns: minmax(0, 1fr) 330px;
}
.legend {
display: none;
}
.control-dock {
align-items: stretch;
flex-direction: column;
gap: 10px;
}
.scale-track {
width: 100%;
}
}
@media (max-width: 820px) {
.app {
width: min(100% - 20px, 700px);
padding-top: 18px;
}
.page-header {
align-items: flex-start;
flex-direction: column;
gap: 12px;
}
.workspace {
display: block;
height: auto;
min-height: 0;
}
.stage {
height: 650px;
}
.panel {
margin-top: 12px;
overflow: visible;
}
.page-footer {
flex-direction: column;
}
.page-footer p:last-child {
text-align: left;
}
}
@media (max-width: 500px) {
.stage {
height: 570px;
border-radius: 20px;
}
.panel {
padding: 17px;
border-radius: 20px;
}
.stage-heading {
top: 17px;
left: 17px;
}
.camera-hint {
bottom: 128px;
left: 17px;
}
.control-dock {
right: 12px;
bottom: 12px;
left: 12px;
}
.control-actions {
width: 100%;
}
.action {
flex: 1;
padding: 0 8px;
font-size: 0.72rem;
}
}
</style>
</head>
<body>
<main class="app">
<header class="page-header">
<div>
<p class="eyebrow">Local measurement frame</p>
<h1>Relative Distance Lab</h1>
</div>
<p class="header-note">
Choose any dot as the reference for comparison. Expansion is uniform
around that local reference; the viewport midpoint has no privileged
position.
</p>
</header>
<section class="workspace">
<div class="stage" id="stage">
<div class="stage-heading">
<span class="kicker">Reference-relative field</span>
<h2 id="stageReference">Reference A</h2>
<p>
Solid links show the current expansion. Dashed links preserve the
×1.00 baseline.
</p>
</div>
<div class="legend" aria-hidden="true">
<span><i></i> current</span>
<span><i class="dashed"></i> baseline</span>
</div>
<div id="labels" aria-hidden="true"></div>
<div class="camera-hint">
Drag to orbit · wheel/pinch to zoom · click a dot to change reference
</div>
<div class="control-dock">
<div class="scale-readout">
<strong id="scaleReadout">Uniform scale ×1.00</strong>
<small>Distance vectors expand from the selected reference</small>
<div class="scale-track" aria-hidden="true">
<span id="scaleTrackFill"></span>
</div>
</div>
<div class="control-actions">
<button class="action primary" id="expandButton" type="button">
Animate expansion
</button>
<button class="action" id="resetButton" type="button">
Reset to ×1.00
</button>
</div>
</div>
</div>
<aside class="panel" aria-label="Reference and distance measurements">
<section class="panel-section">
<span class="section-label">Reference dot</span>
<div
class="reference-grid"
id="referencePicker"
role="radiogroup"
aria-label="Choose a reference dot"
></div>
<p class="panel-description">
The selected dot acts only as a local measurement origin. Switching
it re-anchors the comparison without changing the viewer’s framing.
</p>
</section>
<section class="panel-section">
<div class="panel-title">
<h2 id="distanceTitle">Distances from A</h2>
<span class="scale-badge" id="scaleBadge">×1.00</span>
</div>
<p class="panel-description" id="distanceDescription">
Current distance, baseline distance, and change for every choice.
</p>
<div class="metrics" id="metrics"></div>
</section>
<section class="panel-section">
<div class="insight">
<strong id="insightTitle">Uniform scaling preserves ranking</strong>
<p id="insightText">
All non-reference distances change by the same multiplier while
their nearest-to-farthest order stays fixed.
</p>
</div>
</section>
</aside>
</section>
<footer class="page-footer">
<p>
The reference is a comparison convention—not a universal origin.
</p>
<p>
The screen midpoint is a camera-framing aid only, not a spatial center.
</p>
</footer>
<div id="status" aria-live="polite" style="position:absolute; left:-9999px;"></div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Data and shared state
// -------------------------------------------------------------------------
const choices = [
{
id: "A",
label: "Choice A",
color: 0xff6b6b,
css: "#ff6b6b",
position: new THREE.Vector3(-3.15, 1.55, 0.25)
},
{
id: "B",
label: "Choice B",
color: 0x60a5fa,
css: "#60a5fa",
position: new THREE.Vector3(-1.35, -2.35, -0.85)
},
{
id: "C",
label: "Choice C",
color: 0xfacc15,
css: "#facc15",
position: new THREE.Vector3(0.45, 2.65, 1.05)
},
{
id: "D",
label: "Choice D",
color: 0x4ade80,
css: "#4ade80",
position: new THREE.Vector3(3.05, -1.45, 0.15)
},
{
id: "E",
label: "Choice E",
color: 0xc084fc,
css: "#c084fc",
position: new THREE.Vector3(1.45, -0.05, -1.65)
}
];
const stage = document.querySelector("#stage");
const labelsLayer = document.querySelector("#labels");
const referencePicker = document.querySelector("#referencePicker");
const metricsLayer = document.querySelector("#metrics");
const expandButton = document.querySelector("#expandButton");
const resetButton = document.querySelector("#resetButton");
const scaleBadge = document.querySelector("#scaleBadge");
const scaleReadout = document.querySelector("#scaleReadout");
const scaleTrackFill = document.querySelector("#scaleTrackFill");
const stageReference = document.querySelector("#stageReference");
const distanceTitle = document.querySelector("#distanceTitle");
const insightTitle = document.querySelector("#insightTitle");
const insightText = document.querySelector("#insightText");
const status = document.querySelector("#status");
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let referenceIndex = 0;
let scale = 1;
let scaleTarget = 1;
let scaleAnimation = null;
const MAX_SCALE = 2.4;
const MIN_SCALE = 1;
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.domElement.className = "webgl";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional relative distance visualization"
);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
46,
1,
0.1,
200
);
const ambientLight = new THREE.HemisphereLight(
0xbdeeff,
0x18202c,
2.2
);
scene.add(ambientLight);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.4);
keyLight.position.set(4, 7, 8);
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x38bdf8, 18, 30);
rimLight.position.set(-5, 2, 4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xf59e0b, 12, 24);
warmLight.position.set(5, -3, 2);
scene.add(warmLight);
const nodes = [];
const currentLines = [];
const baselineLines = [];
const ghostRings = [];
const labelElements = [];
const pickables = [];
const currentPositions = choices.map((choice) =>
choice.position.clone()
);
// Baseline ghost rings show the original ×1.00 positions.
choices.forEach((choice) => {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.14, 0.17, 48),
new THREE.MeshBasicMaterial({
color: 0x8da2af,
transparent: true,
opacity: 0.22,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
ring.position.copy(choice.position);
ring.renderOrder = 1;
scene.add(ring);
ghostRings.push(ring);
});
// Choice dots.
choices.forEach((choice, index) => {
const group = new THREE.Group();
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 32, 20),
new THREE.MeshStandardMaterial({
color: choice.color,
emissive: choice.color,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.08
})
);
group.add(core);
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.27, 0.32, 56),
new THREE.MeshBasicMaterial({
color: choice.color,
transparent: true,
opacity: 0.3,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
group.add(halo);
// A larger invisible mesh makes small dots comfortable to click.
const hitArea = new THREE.Mesh(
new THREE.SphereGeometry(0.46, 16, 12),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
})
);
hitArea.userData.choiceIndex = index;
group.add(hitArea);
pickables.push(hitArea);
scene.add(group);
const label = document.createElement("div");
label.className = "node-label";
labelsLayer.appendChild(label);
nodes.push({ group, core, halo, hitArea });
labelElements.push(label);
});
// One solid line and one dashed baseline line per possible reference edge.
choices.forEach((choice) => {
const solidGeometry = new THREE.BufferGeometry();
solidGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const solidLine = new THREE.Line(
solidGeometry,
new THREE.LineBasicMaterial({
color: choice.color,
transparent: true,
opacity: 0.62,
depthWrite: false,
toneMapped: false
})
);
solidLine.frustumCulled = false;
scene.add(solidLine);
currentLines.push(solidLine);
const dashedGeometry = new THREE.BufferGeometry();
dashedGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const dashedLine = new THREE.Line(
dashedGeometry,
new THREE.LineDashedMaterial({
color: 0x91a8b9,
transparent: true,
opacity: 0.3,
dashSize: 0.14,
gapSize: 0.09,
depthWrite: false,
toneMapped: false
})
);
dashedLine.frustumCulled = false;
scene.add(dashedLine);
baselineLines.push(dashedLine);
});
// A small local coordinate triad attached to the selected reference.
// It communicates a local frame, not a privileged global center.
const localFrame = new THREE.Group();
localFrame.add(
new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(0, 0, 0),
0.9,
0xff6b6b,
0.17,
0.08
),
new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 0, 0),
0.9,
0x4ade80,
0.17,
0.08
),
new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(0, 0, 0),
0.9,
0x60a5fa,
0.17,
0.08
)
);
scene.add(localFrame);
// -------------------------------------------------------------------------
// UI construction
// -------------------------------------------------------------------------
choices.forEach((choice, index) => {
const button = document.createElement("button");
button.className = "ref-button";
button.type = "button";
button.setAttribute("role", "radio");
button.setAttribute("aria-checked", "false");
button.style.setProperty("--c", choice.css);
button.innerHTML = `<i aria-hidden="true"></i><span>${choice.id}</span>`;
button.addEventListener("click", () => setReference(index));
referencePicker.appendChild(button);
});
const metricElements = choices.map((choice, index) => {
const row = document.createElement("article");
row.className = "metric";
row.style.setProperty("--c", choice.css);
row.innerHTML = `
<div class="metric-head">
<div class="metric-name">
<i aria-hidden="true"></i>
<strong>${choice.label}</strong>
</div>
<span class="metric-rank"></span>
</div>
<div class="metric-values">
<span>now <strong class="metric-now">0.00 u</strong></span>
<span>base <span class="metric-base">0.00 u</span></span>
</div>
<div class="meter" aria-hidden="true">
<span class="meter-fill"></span>
<span class="meter-base"></span>
</div>
<div class="metric-foot">
<span class="metric-change"></span>
<span class="metric-ratio"></span>
</div>
`;
metricsLayer.appendChild(row);
return {
row,
now: row.querySelector(".metric-now"),
base: row.querySelector(".metric-base"),
rank: row.querySelector(".metric-rank"),
fill: row.querySelector(".meter-fill"),
baseTick: row.querySelector(".meter-base"),
change: row.querySelector(".metric-change"),
ratio: row.querySelector(".metric-ratio")
};
});
// -------------------------------------------------------------------------
// Reference and scale logic
// -------------------------------------------------------------------------
function setReference(index) {
if (index < 0 || index >= choices.length) return;
referenceIndex = index;
const choice = choices[index];
[...referencePicker.children].forEach((button, buttonIndex) => {
button.setAttribute(
"aria-checked",
String(buttonIndex === referenceIndex)
);
});
stageReference.textContent = `Reference ${choice.id}`;
distanceTitle.textContent = `Distances from ${choice.id}`;
localFrame.position.copy(choice.position);
status.textContent =
`Reference ${choice.id} selected. Measurements now use ${choice.id} ` +
`as a local comparison origin.`;
updatePositions();
updatePanel();
}
function animateScale(to, duration = 2600) {
scaleTarget = THREE.MathUtils.clamp(
to,
MIN_SCALE,
MAX_SCALE
);
const effectiveDuration = reducedMotion ? 1 : duration;
scaleAnimation = {
from: scale,
to: scaleTarget,
start: performance.now(),
duration: effectiveDuration
};
}
function replayExpansion() {
if (scale > MAX_SCALE - 0.05) {
animateScale(MIN_SCALE, 750);
window.setTimeout(
() => animateScale(MAX_SCALE, 3000),
reducedMotion ? 1 : 760
);
} else {
animateScale(MAX_SCALE, 3000);
}
}
function updateScaleAnimation(now) {
if (!scaleAnimation) return;
const elapsed = now - scaleAnimation.start;
const t = Math.min(
1,
Math.max(0, elapsed / scaleAnimation.duration)
);
// Smooth in-out cubic easing.
const eased =
t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
scale = THREE.MathUtils.lerp(
scaleAnimation.from,
scaleAnimation.to,
eased
);
if (t >= 1) {
scale = scaleAnimation.to;
scaleAnimation = null;
}
}
function updatePositions() {
const referencePosition = choices[referenceIndex].position;
choices.forEach((choice, index) => {
// Uniform expansion around the selected local reference.
currentPositions[index]
.copy(referencePosition)
.add(
choice.position
.clone()
.sub(referencePosition)
.multiplyScalar(scale)
);
nodes[index].group.position.copy(currentPositions[index]);
});
choices.forEach((choice, index) => {
const isReference = index === referenceIndex;
currentLines[index].visible = !isReference;
baselineLines[index].visible = !isReference;
if (isReference) return;
const currentAttribute =
currentLines[index].geometry.attributes.position;
currentAttribute.setXYZ(
0,
currentPositions[referenceIndex].x,
currentPositions[referenceIndex].y,
currentPositions[referenceIndex].z
);
currentAttribute.setXYZ(
1,
currentPositions[index].x,
currentPositions[index].y,
currentPositions[index].z
);
currentAttribute.needsUpdate = true;
currentLines[index].geometry.computeBoundingSphere();
const baselineAttribute =
baselineLines[index].geometry.attributes.position;
baselineAttribute.setXYZ(
0,
referencePosition.x,
referencePosition.y,
referencePosition.z
);
baselineAttribute.setXYZ(
1,
choice.position.x,
choice.position.y,
choice.position.z
);
baselineAttribute.needsUpdate = true;
baselineLines[index].geometry.computeBoundingSphere();
baselineLines[index].computeLineDistances();
});
}
// -------------------------------------------------------------------------
// Measurement panel
// -------------------------------------------------------------------------
function updatePanel() {
const referencePosition = choices[referenceIndex].position;
const baselineDistances = choices.map((choice) =>
choice.position.distanceTo(referencePosition)
);
// Because every vector is scaled uniformly around the reference,
// every non-reference distance is multiplied by the same factor.
const currentDistances = baselineDistances.map(
(distance) => distance * scale
);
const ranked = currentDistances
.map((distance, index) => ({ distance, index }))
.sort((a, b) => a.distance - b.distance);
const rankFor = new Map(
ranked.map((entry, rank) => [entry.index, rank + 1])
);
const maxDistance = Math.max(...currentDistances, 0.001);
metricElements.forEach((element, index) => {
const baseline = baselineDistances[index];
const current = currentDistances[index];
const change = current - baseline;
const isReference = index === referenceIndex;
element.row.classList.toggle("is-reference", isReference);
element.now.textContent = `${current.toFixed(2)} u`;
element.base.textContent = `${baseline.toFixed(2)} u`;
element.rank.textContent = isReference
? "selected reference"
: `rank ${rankFor.get(index)} of ${choices.length}`;
element.fill.style.width = `${(current / maxDistance) * 100}%`;
element.baseTick.style.left = `${(baseline / maxDistance) * 100}%`;
if (isReference) {
element.change.textContent = "Local origin for this comparison";
element.ratio.textContent = "0.00 u";
} else {
const percentage = baseline > 0 ? (change / baseline) * 100 : 0;
element.change.textContent =
`${change >= 0 ? "+" : ""}${change.toFixed(2)} u ` +
`(${percentage >= 0 ? "+" : ""}${percentage.toFixed(1)}%)`;
element.ratio.textContent = `ratio ×${scale.toFixed(2)}`;
}
});
const scaleText = `×${scale.toFixed(2)}`;
scaleBadge.textContent = scaleText;
scaleReadout.textContent = `Uniform scale ${scaleText}`;
scaleTrackFill.style.width =
`${((scale - MIN_SCALE) / (MAX_SCALE - MIN_SCALE)) * 100}%`;
expandButton.textContent =
scale >= MAX_SCALE - 0.03
? "Replay expansion"
: "Animate expansion";
const nonReferenceEntries = ranked.filter(
(entry) => entry.index !== referenceIndex
);
if (nonReferenceEntries.length) {
const nearest = nonReferenceEntries[0];
const farthest =
nonReferenceEntries[nonReferenceEntries.length - 1];
insightTitle.textContent = "Uniform scaling preserves ranking";
insightText.textContent =
`${choices[nearest.index].id} is nearest at ` +
`${nearest.distance.toFixed(2)} u; ` +
`${choices[farthest.index].id} is farthest at ` +
`${farthest.distance.toFixed(2)} u. ` +
`All non-reference distances changed by the same ×${scale.toFixed(2)} factor.`;
}
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: -0.58,
elevation: 0.43,
userZoom: 1,
target: new THREE.Vector3(),
radius: 10
};
const desiredTarget = new THREE.Vector3();
let viewportWidth = 1;
let viewportHeight = 1;
function updateCamera(dt) {
// The target is only a viewport fitting aid.
desiredTarget.set(0, 0, 0);
currentPositions.forEach((position) => {
desiredTarget.add(position);
});
desiredTarget.multiplyScalar(1 / currentPositions.length);
let maximumRadius = 0;
currentPositions.forEach((position) => {
maximumRadius = Math.max(
maximumRadius,
position.distanceTo(desiredTarget)
);
});
cameraState.target.lerp(
desiredTarget,
1 - Math.pow(0.001, dt)
);
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const fitDistance =
(maximumRadius / Math.sin(verticalFov / 2)) * 1.16;
const desiredRadius = fitDistance * cameraState.userZoom;
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredRadius,
1 - Math.pow(0.002, dt)
);
const phi = Math.PI / 2 - cameraState.elevation;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.cos(phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragDistance = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
cameraState.yaw -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.004,
0.08,
1.22
);
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (dragDistance > 6) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
pickables,
false
);
if (intersections.length) {
setReference(intersections[0].object.userData.choiceIndex);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.userZoom = THREE.MathUtils.clamp(
cameraState.userZoom * Math.exp(event.deltaY * 0.001),
0.65,
1.8
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key;
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "+", "-", "="].includes(key)) {
event.preventDefault();
}
if (key === "ArrowLeft") cameraState.yaw -= 0.12;
if (key === "ArrowRight") cameraState.yaw += 0.12;
if (key === "ArrowUp") {
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + 0.08,
0.08,
1.22
);
}
if (key === "ArrowDown") {
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation - 0.08,
0.08,
1.22
);
}
if (key === "+" || key === "=") {
cameraState.userZoom = Math.max(0.65, cameraState.userZoom - 0.08);
}
if (key === "-") {
cameraState.userZoom = Math.min(1.8, cameraState.userZoom + 0.08);
}
if (/^[1-5]$/.test(key)) {
setReference(Number(key) - 1);
}
if (key === " ") {
event.preventDefault();
replayExpansion();
}
});
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// Labels and rendering
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
currentPositions.forEach((position, index) => {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
const label = labelElements[index];
label.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * viewportWidth;
const y = (-projected.y * 0.5 + 0.5) * viewportHeight;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
});
}
function resize() {
const rect = stage.getBoundingClientRect();
viewportWidth = Math.max(1, rect.width);
viewportHeight = Math.max(1, rect.height);
renderer.setSize(viewportWidth, viewportHeight, false);
camera.aspect = viewportWidth / viewportHeight;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
expandButton.addEventListener("click", replayExpansion);
resetButton.addEventListener("click", () => {
animateScale(MIN_SCALE, 1100);
status.textContent = "Scale returned toward the ×1.00 baseline.";
});
let previousTime = performance.now();
let panelFrame = 0;
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
updateScaleAnimation(now);
updatePositions();
updateCamera(dt);
// Face the halos toward the camera.
ghostRings.forEach((ring) => {
ring.quaternion.copy(camera.quaternion);
});
nodes.forEach((node, index) => {
node.halo.quaternion.copy(camera.quaternion);
const isReference = index === referenceIndex;
const pulse = isReference
? 1 + Math.sin(now * 0.004) * 0.09
: 1;
node.halo.scale.setScalar(pulse);
node.halo.material.opacity = isReference ? 0.95 : 0.27;
node.halo.material.color.set(
isReference ? 0xe7fbff : choices[index].color
);
node.core.material.emissiveIntensity = isReference ? 1.55 : 0.55;
node.core.scale.setScalar(isReference ? 1.16 : 1);
const distance = choices[index].position.distanceTo(
choices[referenceIndex].position
);
const label = labelElements[index];
label.classList.toggle("reference", isReference);
label.style.borderColor = isReference
? "rgba(103, 232, 249, 0.68)"
: `${choices[index].css}55`;
label.innerHTML = isReference
? `${choices[index].id}<small>LOCAL REFERENCE</small>`
: `${choices[index].id}<small>${(
distance * scale
).toFixed(2)} u FROM REF</small>`;
});
updateLabels();
// The DOM panel does not need to update at the full display rate.
panelFrame += 1;
if (panelFrame % 2 === 0) updatePanel();
renderer.render(scene, camera);
}
// Initialize.
setReference(0);
updatePanel();
requestAnimationFrame(animate);
// Demonstrate the expansion once, unless reduced motion is requested.
if (!reducedMotion) {
window.setTimeout(() => animateScale(MAX_SCALE, 3600), 700);
}
</script>
</body>
</html>
```