Prompt specification
Build or customize the Three.js 3D scene "Aperture and magnification comparison" 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: Aperture and magnification comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/aperture-and-magnification-comparison-x1594
Scene Description Prompt:
Place two telescope models with independently varied aperture and focal lengths; show separate light-collection and angular-magnification indicators rather than conflating larger size with greater zoom. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (aperture-and-magnification-comparison-x1594):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Optics Lab — Aperture vs. Magnification</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: #0b1727;
--panel-2: #101e30;
--line: rgba(160, 191, 220, 0.16);
--text: #eef5ff;
--muted: #91a4ba;
--a: #35d0ba;
--b: #ff9f43;
--light: #65e6ad;
--zoom: #b49cff;
}
* {
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 {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
width: 100%;
height: 100vh;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 36%, #142843 0%, #07111f 58%, #040a13 100%);
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.hero {
position: absolute;
top: 28px;
left: 30px;
max-width: 580px;
pointer-events: none;
z-index: 3;
}
.eyebrow {
color: #7cdcca;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 9px 0 10px;
font-size: clamp(30px, 3.6vw, 52px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.hero p {
max-width: 530px;
margin: 0;
color: #a9bbce;
font-size: 14px;
line-height: 1.6;
}
.identity-legend {
display: flex;
gap: 16px;
margin-top: 15px;
color: #c6d3e1;
font-size: 12px;
}
.identity-legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.identity-legend i {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--a);
box-shadow: 0 0 14px var(--a);
}
.identity-legend .b-dot {
background: var(--b);
box-shadow: 0 0 14px var(--b);
}
.toolbar {
position: absolute;
top: 26px;
right: 24px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
z-index: 5;
}
.toolbar button,
.scenario button {
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(12, 26, 43, 0.84);
padding: 9px 12px;
color: #cbd8e6;
font-size: 11px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.toolbar button:hover,
.scenario button:hover {
border-color: rgba(124, 220, 202, 0.55);
background: rgba(24, 48, 67, 0.92);
transform: translateY(-1px);
}
.toolbar button:focus-visible,
.scenario button:focus-visible,
input:focus-visible {
outline: 2px solid #7cdcca;
outline-offset: 3px;
}
.model-label {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(6, 15, 27, 0.8);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
color: #dce8f4;
font-size: 10px;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.model-label b {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border-radius: 50%;
color: #04111a;
background: var(--a);
font-size: 10px;
}
#label-b b {
background: var(--b);
}
.stage-note {
position: absolute;
right: 24px;
bottom: 22px;
z-index: 3;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 17, 31, 0.72);
color: #8fa4ba;
font-size: 10px;
line-height: 1.5;
text-align: right;
pointer-events: none;
backdrop-filter: blur(10px);
}
aside {
position: relative;
z-index: 8;
height: 100vh;
overflow-y: auto;
padding: 24px 20px 34px;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(16, 30, 48, 0.96), rgba(8, 20, 34, 0.98));
box-shadow: -20px 0 50px rgba(0, 0, 0, 0.16);
scrollbar-width: thin;
scrollbar-color: #294159 transparent;
}
.panel-heading {
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 5px 0 6px;
font-size: 21px;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.instrument-card {
--identity: var(--a);
margin-bottom: 14px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(17, 32, 50, 0.76);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
}
.instrument-card.b {
--identity: var(--b);
}
.instrument-title {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
}
.instrument-title .letter {
display: grid;
width: 28px;
height: 28px;
place-items: center;
border-radius: 9px;
background: var(--identity);
color: #07111f;
font-size: 13px;
font-weight: 900;
box-shadow: 0 0 20px color-mix(in srgb, var(--identity), transparent 60%);
}
.instrument-title h3 {
margin: 0;
font-size: 14px;
}
.instrument-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.control {
margin-top: 13px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: #d8e3ee;
font-size: 11px;
font-weight: 700;
}
.control-label output {
color: var(--identity);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 0;
border-radius: 999px;
accent-color: var(--identity);
cursor: pointer;
}
.control-hint {
margin-top: 5px;
color: #6f849a;
font-size: 9px;
}
.metrics {
display: grid;
gap: 9px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.metric {
padding: 11px;
border: 1px solid rgba(160, 191, 220, 0.11);
border-radius: 11px;
background: rgba(5, 13, 23, 0.4);
}
.metric-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.metric-name {
color: #dce8f4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.metric-source {
display: block;
margin-top: 3px;
color: #6f849a;
font-size: 9px;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
}
.metric-value {
color: var(--light);
font-size: 16px;
font-weight: 850;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.metric.magnification .metric-value {
color: var(--zoom);
}
.bar {
height: 5px;
margin-top: 10px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.bar span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #2f9d76, var(--light));
box-shadow: 0 0 12px rgba(101, 230, 173, 0.35);
transition: width 180ms ease;
}
.magnification .bar span {
background: linear-gradient(90deg, #7159c6, var(--zoom));
box-shadow: 0 0 12px rgba(180, 156, 255, 0.35);
}
.metric-foot {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 6px;
color: #6f849a;
font-size: 9px;
}
.ratio-row {
display: flex;
justify-content: space-between;
margin-top: 10px;
color: #8196ab;
font-size: 10px;
}
.ratio-row strong {
color: #dce8f4;
font-variant-numeric: tabular-nums;
}
.scenario {
margin-top: 17px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.scenario h3 {
margin: 0 0 5px;
font-size: 12px;
}
.scenario > p {
margin: 0 0 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.scenario-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.scenario-buttons button:last-child {
grid-column: 1 / -1;
}
.formula-card {
margin-top: 16px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 17, 31, 0.58);
}
.formula-card h3 {
margin: 0 0 10px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.formula {
display: grid;
grid-template-columns: 100px 1fr;
gap: 8px;
padding: 8px 0;
border-top: 1px solid rgba(160, 191, 220, 0.1);
font-size: 10px;
line-height: 1.45;
}
.formula:first-of-type {
border-top: 0;
}
.formula strong {
color: var(--light);
}
.formula.mag strong {
color: var(--zoom);
}
.formula span {
color: var(--muted);
}
.takeaway {
margin-top: 12px;
padding: 11px 12px;
border-left: 3px solid #7cdcca;
border-radius: 4px 10px 10px 4px;
background: rgba(124, 220, 202, 0.07);
color: #c9d8e6;
font-size: 11px;
line-height: 1.55;
}
.takeaway strong {
color: #eef8ff;
}
@media (max-width: 1100px) {
.hero {
max-width: 430px;
}
.toolbar {
top: auto;
right: 18px;
bottom: 62px;
max-width: 310px;
}
.stage-note {
max-width: 300px;
}
}
@media (max-width: 860px) {
body {
overflow: auto;
}
#app {
display: block;
height: auto;
}
#stage {
height: 62vh;
min-height: 480px;
}
aside {
height: auto;
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.hero {
top: 20px;
left: 20px;
max-width: calc(100% - 40px);
}
.hero h1 {
font-size: 32px;
}
.hero p {
max-width: 440px;
font-size: 12px;
}
.toolbar {
top: auto;
right: 16px;
bottom: 58px;
max-width: 250px;
}
.toolbar button {
padding: 8px 10px;
font-size: 9px;
}
.stage-note {
right: 16px;
bottom: 15px;
max-width: 220px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app">
<main id="stage">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D comparison of two telescopes. Drag to orbit, scroll to zoom, and use arrow keys to rotate."
></canvas>
<header class="hero">
<div class="eyebrow">Interactive optics lab · 02</div>
<h1>Bigger is not the same as better.</h1>
<p>
Aperture controls how much light is collected. Focal length controls
angular magnification. Adjust both properties independently.
</p>
<div class="identity-legend">
<span><i></i> Telescope A</span>
<span><i class="b-dot"></i> Telescope B</span>
</div>
</header>
<nav class="toolbar" aria-label="Comparison presets">
<button id="match-apertures" type="button">Match apertures</button>
<button id="match-focal-lengths" type="button">Match focal lengths</button>
<button id="reset-view" type="button">Reset view</button>
</nav>
<div id="label-a" class="model-label">
<b>A</b><span id="label-a-text"></span>
</div>
<div id="label-b" class="model-label">
<b>B</b><span id="label-b-text"></span>
</div>
<div class="stage-note">
Common physical scale · 1 scene unit ≈ 222 mm<br>
Drag to orbit · scroll to zoom · arrow keys to rotate
</div>
</main>
<aside aria-label="Telescope controls and measurements">
<div class="panel-heading">
<div class="eyebrow">Instrument controls</div>
<h2>Two variables, two outcomes</h2>
<p>
Both telescopes use the same 25 mm eyepiece, so magnification changes
only when focal length changes.
</p>
</div>
<section class="instrument-card" aria-labelledby="title-a">
<div class="instrument-title">
<span class="letter">A</span>
<div>
<h3 id="title-a">Telescope A</h3>
<small>Compact aperture · moderate focal length</small>
</div>
</div>
<div class="control">
<label class="control-label" for="a-aperture">
<span>Aperture</span>
<output id="a-aperture-out" for="a-aperture">200 mm</output>
</label>
<input id="a-aperture" type="range" min="80" max="300" step="5" value="200">
<div class="control-hint">Objective diameter — changes light-gathering area</div>
</div>
<div class="control">
<label class="control-label" for="a-focal">
<span>Focal length</span>
<output id="a-focal-out" for="a-focal">1000 mm</output>
</label>
<input id="a-focal" type="range" min="400" max="2400" step="25" value="1000">
<div class="control-hint">Tube length — changes angular magnification</div>
</div>
<div class="metrics">
<div class="metric collection">
<div class="metric-heading">
<div class="metric-name">
Light collection
<span class="metric-source">Driven by aperture area</span>
</div>
<strong id="a-light-value" class="metric-value">314 cm²</strong>
</div>
<div class="bar"><span id="a-light-bar"></span></div>
<div class="metric-foot">
<span id="a-light-relative">3.14× a Ø100 mm aperture</span>
<span>Area ∝ D²</span>
</div>
</div>
<div class="metric magnification">
<div class="metric-heading">
<div class="metric-name">
Angular magnification
<span class="metric-source">Driven by focal length</span>
</div>
<strong id="a-mag-value" class="metric-value">40.0×</strong>
</div>
<div class="bar"><span id="a-mag-bar"></span></div>
<div class="metric-foot">
<span>25 mm eyepiece</span>
<span>M = F ÷ 25</span>
</div>
</div>
<div class="ratio-row">
<span>Focal ratio</span>
<strong id="a-ratio-value">f/5.0</strong>
</div>
</div>
</section>
<section class="instrument-card b" aria-labelledby="title-b">
<div class="instrument-title">
<span class="letter">B</span>
<div>
<h3 id="title-b">Telescope B</h3>
<small>Narrow aperture · long focal length</small>
</div>
</div>
<div class="control">
<label class="control-label" for="b-aperture">
<span>Aperture</span>
<output id="b-aperture-out" for="b-aperture">120 mm</output>
</label>
<input id="b-aperture" type="range" min="80" max="300" step="5" value="120">
<div class="control-hint">Objective diameter — changes light-gathering area</div>
</div>
<div class="control">
<label class="control-label" for="b-focal">
<span>Focal length</span>
<output id="b-focal-out" for="b-focal">1600 mm</output>
</label>
<input id="b-focal" type="range" min="400" max="2400" step="25" value="1600">
<div class="control-hint">Tube length — changes angular magnification</div>
</div>
<div class="metrics">
<div class="metric collection">
<div class="metric-heading">
<div class="metric-name">
Light collection
<span class="metric-source">Driven by aperture area</span>
</div>
<strong id="b-light-value" class="metric-value">113 cm²</strong>
</div>
<div class="bar"><span id="b-light-bar"></span></div>
<div class="metric-foot">
<span id="b-light-relative">1.13× a Ø100 mm aperture</span>
<span>Area ∝ D²</span>
</div>
</div>
<div class="metric magnification">
<div class="metric-heading">
<div class="metric-name">
Angular magnification
<span class="metric-source">Driven by focal length</span>
</div>
<strong id="b-mag-value" class="metric-value">64.0×</strong>
</div>
<div class="bar"><span id="b-mag-bar"></span></div>
<div class="metric-foot">
<span>25 mm eyepiece</span>
<span>M = F ÷ 25</span>
</div>
</div>
<div class="ratio-row">
<span>Focal ratio</span>
<strong id="b-ratio-value">f/13.3</strong>
</div>
</div>
</section>
<section class="scenario" aria-labelledby="scenario-title">
<h3 id="scenario-title">Try controlled comparisons</h3>
<p>
Change one shared property while leaving the other independent.
</p>
<div class="scenario-buttons">
<button id="scenario-apertures" type="button">Same light collection</button>
<button id="scenario-focal" type="button">Same magnification</button>
<button id="scenario-reset" type="button">Restore starting models</button>
</div>
</section>
<section class="formula-card" aria-label="Measurement formulas">
<h3>Read the indicators separately</h3>
<div class="formula">
<strong>Light</strong>
<span>Collection area = π(D / 2)². Twice the diameter means four times the area.</span>
</div>
<div class="formula mag">
<strong>Magnification</strong>
<span>Angular magnification = telescope focal length ÷ eyepiece focal length.</span>
</div>
<div class="takeaway" id="takeaway">
<strong>Current comparison:</strong>
A collects more light, while B produces greater angular magnification.
</div>
</section>
</aside>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const canvas = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 20, 43);
const camera = new THREE.PerspectiveCamera(
39,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
// All dimensions use the same scale so the models preserve real relative size.
const SCALE = 0.0045;
const EYEPIECE_FOCAL_LENGTH = 25;
const REFERENCE_APERTURE = 100;
const configs = [
{
id: "A",
aperture: 200,
focal: 1000,
color: 0x35d0ba,
bodyColor: 0x126b69,
x: -3.35
},
{
id: "B",
aperture: 120,
focal: 1600,
color: 0xff9f43,
bodyColor: 0x934818,
x: 3.35
}
];
const cameraHome = {
theta: 0.58,
phi: 1.03,
radius: 19
};
const desiredCamera = { ...cameraHome };
const currentCamera = { ...cameraHome };
const cameraTarget = new THREE.Vector3(0, 2.65, -0.3);
function addMesh(parent, geometry, material, position, rotation) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x081321,
roughness: 0.95,
metalness: 0.05
});
const floor = addMesh(
scene,
new THREE.PlaneGeometry(70, 70),
floorMaterial,
[0, 0, 0],
[-Math.PI / 2, 0, 0]
);
floor.castShadow = false;
const grid = new THREE.GridHelper(44, 44, 0x28445d, 0x142a3d);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const hemisphere = new THREE.HemisphereLight(0xa9d8ff, 0x101826, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xf4f8ff, 3.2);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanRim = new THREE.PointLight(0x35d0ba, 28, 18, 2);
cyanRim.position.set(-7, 4.5, -4);
scene.add(cyanRim);
const amberRim = new THREE.PointLight(0xff9f43, 26, 18, 2);
amberRim.position.set(7, 5.5, -3);
scene.add(amberRim);
const commonMaterials = {
dark: new THREE.MeshStandardMaterial({
color: 0x172331,
roughness: 0.55,
metalness: 0.55
}),
darker: new THREE.MeshStandardMaterial({
color: 0x0b121b,
roughness: 0.7,
metalness: 0.35
}),
metal: new THREE.MeshStandardMaterial({
color: 0x9aabb8,
roughness: 0.32,
metalness: 0.78
}),
platform: new THREE.MeshStandardMaterial({
color: 0x142234,
roughness: 0.72,
metalness: 0.25
})
};
function createInstrument(config, index) {
const root = new THREE.Group();
root.position.set(config.x, 0, 1.25);
scene.add(root);
const accentMaterial = new THREE.MeshStandardMaterial({
color: config.color,
roughness: 0.38,
metalness: 0.42,
emissive: config.color,
emissiveIntensity: 0.08
});
const bodyMaterial = new THREE.MeshStandardMaterial({
color: config.bodyColor,
roughness: 0.4,
metalness: 0.38,
emissive: config.bodyColor,
emissiveIntensity: 0.055
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x6bbbe7,
emissive: 0x176790,
emissiveIntensity: 0.5,
roughness: 0.2,
metalness: 0.12,
side: THREE.DoubleSide
});
addMesh(
root,
new THREE.CylinderGeometry(1.25, 1.4, 0.22, 48),
commonMaterials.platform,
[0, 0.11, 0]
);
const platformRing = addMesh(
root,
new THREE.TorusGeometry(1.22, 0.025, 8, 64),
accentMaterial,
[0, 0.225, 0],
[Math.PI / 2, 0, 0]
);
platformRing.castShadow = false;
const mountGroup = new THREE.Group();
const tubeGroup = new THREE.Group();
root.add(mountGroup, tubeGroup);
return {
root,
mountGroup,
tubeGroup,
accentMaterial,
bodyMaterial,
glassMaterial
};
}
function clearGeometry(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
while (group.children.length) {
group.remove(group.children[0]);
}
}
function buildInstrument(config, instrument) {
clearGeometry(instrument.mountGroup);
clearGeometry(instrument.tubeGroup);
const radius = (config.aperture * SCALE) / 2;
const length = config.focal * SCALE;
// Pedestal and fork mount.
addMesh(
instrument.mountGroup,
new THREE.CylinderGeometry(0.43, 0.56, 0.72, 32),
commonMaterials.dark,
[0, 0.58, 0]
);
addMesh(
instrument.mountGroup,
new THREE.CylinderGeometry(0.49, 0.49, 0.09, 32),
instrument.accentMaterial,
[0, 0.91, 0]
);
addMesh(
instrument.mountGroup,
new THREE.BoxGeometry(0.36, 0.48, 0.36),
commonMaterials.dark,
[0, 1.15, 0]
);
addMesh(
instrument.mountGroup,
new THREE.SphereGeometry(0.29, 24, 16),
commonMaterials.metal,
[0, 1.43, 0.06]
);
const armX = radius + 0.16;
for (const side of [-1, 1]) {
addMesh(
instrument.mountGroup,
new THREE.BoxGeometry(0.13, 0.72, 0.22),
commonMaterials.dark,
[side * armX, 1.22, 0.08]
);
addMesh(
instrument.mountGroup,
new THREE.CylinderGeometry(0.14, 0.14, 0.26, 24),
commonMaterials.metal,
[side * armX, 1.5, 0.08],
[0, 0, Math.PI / 2]
);
}
// Tube group is elevated and aimed toward the upper-left of the scene.
instrument.tubeGroup.position.set(0, 1.5, 0.08);
instrument.tubeGroup.rotation.x = 0.64;
const tube = addMesh(
instrument.tubeGroup,
new THREE.CylinderGeometry(radius, radius * 0.985, length, 40, 1, true),
instrument.bodyMaterial,
[0, 0, -length / 2],
[Math.PI / 2, 0, 0]
);
tube.receiveShadow = true;
// Structural rings make the changing diameter easy to read.
const ribRadius = Math.max(0.032, radius * 0.065);
for (const z of [-0.13, -length * 0.34, -length + 0.13]) {
addMesh(
instrument.tubeGroup,
new THREE.TorusGeometry(radius * 1.01, ribRadius, 10, 40),
z === -length + 0.13
? instrument.accentMaterial
: commonMaterials.dark,
[0, 0, z]
);
}
// Solid objective lens.
addMesh(
instrument.tubeGroup,
new THREE.CircleGeometry(radius * 0.91, 48),
instrument.glassMaterial,
[0, 0, -length + 0.012]
);
addMesh(
instrument.tubeGroup,
new THREE.TorusGeometry(radius * 1.015, ribRadius * 1.12, 12, 48),
instrument.accentMaterial,
[0, 0, -length]
);
// Rear focuser and eyepiece.
addMesh(
instrument.tubeGroup,
new THREE.CylinderGeometry(radius * 0.3, radius * 0.26, 0.42, 28),
commonMaterials.dark,
[0, 0, 0.26],
[Math.PI / 2, 0, 0]
);
addMesh(
instrument.tubeGroup,
new THREE.TorusGeometry(radius * 0.3, 0.035, 8, 32),
instrument.accentMaterial,
[0, 0, 0.19]
);
addMesh(
instrument.tubeGroup,
new THREE.CylinderGeometry(0.15, 0.18, 0.5, 28),
commonMaterials.darker,
[0, 0, 0.7],
[Math.PI / 2, 0, 0]
);
addMesh(
instrument.tubeGroup,
new THREE.CylinderGeometry(0.19, 0.19, 0.12, 28),
commonMaterials.metal,
[0, 0, 0.97],
[Math.PI / 2, 0, 0]
);
// Small finder scope.
const finderZ = -length * 0.56;
const finderY = radius + 0.095;
addMesh(
instrument.tubeGroup,
new THREE.CylinderGeometry(0.065, 0.065, Math.min(1.15, length * 0.42), 20),
commonMaterials.darker,
[0, finderY, finderZ],
[Math.PI / 2, 0, 0]
);
for (const z of [finderZ - 0.35, finderZ + 0.35]) {
addMesh(
instrument.tubeGroup,
new THREE.BoxGeometry(0.11, radius * 0.28, 0.1),
commonMaterials.metal,
[0, radius * 0.78, z]
);
}
// The lens brightness responds only to aperture-derived collection.
const collectionNormalized = Math.pow(config.aperture / 300, 2);
instrument.glassMaterial.emissiveIntensity = 0.28 + collectionNormalized * 0.95;
instrument.glassMaterial.color.setHSL(
0.55,
0.58,
0.38 + collectionNormalized * 0.13
);
}
const instruments = configs.map(createInstrument);
function formatNumber(value, digits = 0) {
return value.toLocaleString("en-US", {
minimumFractionDigits: digits,
maximumFractionDigits: digits
});
}
function collectionAreaCm2(apertureMm) {
const radiusMeters = apertureMm / 2000;
return Math.PI * radiusMeters * radiusMeters * 10000;
}
function updateMetrics(config, prefix) {
const area = collectionAreaCm2(config.aperture);
const relativeCollection =
Math.pow(config.aperture / REFERENCE_APERTURE, 2);
const magnification = config.focal / EYEPIECE_FOCAL_LENGTH;
const focalRatio = config.focal / config.aperture;
document.getElementById(`${prefix}-aperture-out`).textContent =
`${config.aperture} mm`;
document.getElementById(`${prefix}-focal-out`).textContent =
`${formatNumber(config.focal)} mm`;
document.getElementById(`${prefix}-light-value`).textContent =
`${formatNumber(area, 0)} cm²`;
document.getElementById(`${prefix}-light-relative`).textContent =
`${relativeCollection.toFixed(2)}× a Ø100 mm aperture`;
document.getElementById(`${prefix}-mag-value`).textContent =
`${magnification.toFixed(1)}×`;
document.getElementById(`${prefix}-ratio-value`).textContent =
`f/${focalRatio.toFixed(1)}`;
document.getElementById(`${prefix}-light-bar`).style.width =
`${(area / collectionAreaCm2(300)) * 100}%`;
document.getElementById(`${prefix}-mag-bar`).style.width =
`${(magnification / (2400 / EYEPIECE_FOCAL_LENGTH)) * 100}%`;
document.getElementById(`label-${prefix.toLowerCase()}-text`).textContent =
`Ø ${config.aperture} mm · ${formatNumber(config.focal)} mm`;
}
function updateTakeaway() {
const [a, b] = configs;
const areaA = collectionAreaCm2(a.aperture);
const areaB = collectionAreaCm2(b.aperture);
const magA = a.focal / EYEPIECE_FOCAL_LENGTH;
const magB = b.focal / EYEPIECE_FOCAL_LENGTH;
let text;
if (Math.abs(areaA - areaB) < 0.01 && Math.abs(magA - magB) < 0.01) {
text = "Both instruments currently have the same light collection and angular magnification.";
} else if (areaA > areaB && magA > magB) {
text = "A collects more light and provides greater angular magnification than B.";
} else if (areaA > areaB && magA < magB) {
text = "A collects more light, while B provides greater angular magnification.";
} else if (areaA < areaB && magA > magB) {
text = "B collects more light, while A provides greater angular magnification.";
} else {
text = "B collects more light and provides greater angular magnification than A.";
}
document.getElementById("takeaway").innerHTML =
`<strong>Current comparison:</strong> ${text}`;
}
function syncInputs() {
for (const config of configs) {
const prefix = config.id.toLowerCase();
document.getElementById(`${prefix}-aperture`).value = config.aperture;
document.getElementById(`${prefix}-focal`).value = config.focal;
}
}
function updateAll() {
configs.forEach((config, index) => {
buildInstrument(config, instruments[index]);
updateMetrics(config, config.id.toLowerCase());
});
updateTakeaway();
}
for (const config of configs) {
const prefix = config.id.toLowerCase();
document.getElementById(`${prefix}-aperture`).addEventListener("input", (event) => {
config.aperture = Number(event.target.value);
buildInstrument(config, instruments[configs.indexOf(config)]);
updateMetrics(config, prefix);
updateTakeaway();
});
document.getElementById(`${prefix}-focal`).addEventListener("input", (event) => {
config.focal = Number(event.target.value);
buildInstrument(config, instruments[configs.indexOf(config)]);
updateMetrics(config, prefix);
updateTakeaway();
});
}
function setApertures(value) {
configs.forEach((config) => {
config.aperture = value;
});
syncInputs();
updateAll();
}
function setFocalLengths(value) {
configs.forEach((config) => {
config.focal = value;
});
syncInputs();
updateAll();
}
document.getElementById("match-apertures").addEventListener("click", () => {
setApertures(configs[0].aperture);
});
document.getElementById("match-focal-lengths").addEventListener("click", () => {
setFocalLengths(configs[0].focal);
});
document.getElementById("scenario-apertures").addEventListener("click", () => {
setApertures(configs[0].aperture);
});
document.getElementById("scenario-focal").addEventListener("click", () => {
setFocalLengths(configs[0].focal);
});
document.getElementById("scenario-reset").addEventListener("click", () => {
configs[0].aperture = 200;
configs[0].focal = 1000;
configs[1].aperture = 120;
configs[1].focal = 1600;
syncInputs();
updateAll();
});
document.getElementById("reset-view").addEventListener("click", () => {
desiredCamera.theta = cameraHome.theta;
desiredCamera.phi = cameraHome.phi;
desiredCamera.radius = cameraHome.radius;
});
// Camera controls are implemented directly, without Three.js addons.
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.42,
1.42
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
9.5,
31
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") desiredCamera.theta -= 0.08;
else if (key === "ArrowRight") desiredCamera.theta += 0.08;
else if (key === "ArrowUp") {
desiredCamera.phi = Math.max(0.42, desiredCamera.phi - 0.06);
} else if (key === "ArrowDown") {
desiredCamera.phi = Math.min(1.42, desiredCamera.phi + 0.06);
} else if (key === "+" || key === "=") {
desiredCamera.radius = Math.max(9.5, desiredCamera.radius - 1);
} else if (key === "-") {
desiredCamera.radius = Math.min(31, desiredCamera.radius + 1);
} else return;
event.preventDefault();
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
const projected = new THREE.Vector3();
function updateModelLabels() {
for (const config of configs) {
const label = document.getElementById(`label-${config.id.toLowerCase()}`);
projected.set(config.x, 2.25, 1.25).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.style.opacity = visible ? "1" : "0";
label.style.left = `${(projected.x * 0.5 + 0.5) * stage.clientWidth}px`;
label.style.top = `${(-projected.y * 0.5 + 0.5) * stage.clientHeight}px`;
}
}
function animate() {
const damping = 0.11;
currentCamera.theta +=
(desiredCamera.theta - currentCamera.theta) * damping;
currentCamera.phi +=
(desiredCamera.phi - currentCamera.phi) * damping;
currentCamera.radius +=
(desiredCamera.radius - currentCamera.radius) * damping;
const sinPhi = Math.sin(currentCamera.phi);
const cosPhi = Math.cos(currentCamera.phi);
camera.position.set(
cameraTarget.x + currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
cameraTarget.y + currentCamera.radius * cosPhi,
cameraTarget.z + currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(cameraTarget);
scene.updateMatrixWorld();
updateModelLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateAll();
animate();
</script>
</body>
</html>
```