Prompt specification
Build or customize the Three.js 3D scene "Conic shapes design gallery" 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: Conic shapes design gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/conic-shapes-design-gallery-x1687
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: conic shapes design gallery. Compose a reflector profile, elliptical opening, and hyperbolic outline beside their mathematical constructions; distinguish geometric similarity from claiming identical physical optical behavior.
Working Three.js Starter (conic-shapes-design-gallery-x1687):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Conic Forms — Voxel Design Gallery</title>
<style>
:root {
color-scheme: dark;
--bg: #0d131b;
--panel: rgba(13, 19, 27, 0.88);
--line: rgba(210, 226, 242, 0.16);
--text: #eef4fb;
--muted: #9eacbc;
--coral: #ff705d;
--gold: #f2c45e;
--mint: #4dd6c5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#labels {
position: fixed;
inset: 0;
}
#app canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#app canvas:active {
cursor: grabbing;
}
#labels {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.topbar {
position: fixed;
z-index: 5;
top: 26px;
left: 30px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #a9b8c9;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(31px, 3.7vw, 54px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.95;
}
.subtitle {
max-width: 480px;
margin-top: 12px;
color: #aebaca;
font-size: 13px;
line-height: 1.55;
}
.form-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(255, 112, 93, 0.34);
border-radius: 5px;
background: rgba(255, 112, 93, 0.08);
color: #ffc1b8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.form-badge::before {
width: 6px;
height: 6px;
border-radius: 1px;
background: var(--coral);
content: "";
box-shadow: 0 0 12px rgba(255, 112, 93, 0.7);
}
.legend {
position: fixed;
z-index: 5;
top: 28px;
right: 28px;
display: flex;
gap: 15px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(13, 19, 27, 0.72);
backdrop-filter: blur(12px);
pointer-events: none;
color: #aebaca;
font-size: 10px;
letter-spacing: 0.04em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
display: inline-block;
width: 9px;
height: 9px;
border-radius: 2px;
}
.swatch.form {
background: linear-gradient(135deg, var(--coral), var(--gold), var(--mint));
}
.swatch.focus {
background: #fff5df;
box-shadow: 0 0 6px rgba(255, 245, 223, 0.45);
}
.swatch.guide {
background: #40566d;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
min-width: 142px;
padding: 8px 10px 9px;
border: 1px solid rgba(211, 228, 246, 0.15);
border-left: 3px solid var(--accent, #ffffff);
border-radius: 5px;
background: rgba(10, 16, 23, 0.78);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(8px);
white-space: nowrap;
pointer-events: none;
will-change: transform, opacity;
}
.scene-label .kicker {
display: block;
margin-bottom: 3px;
color: var(--accent, #ffffff);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
color: #f4f8fc;
font-size: 11px;
font-weight: 720;
letter-spacing: -0.01em;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #96a6b8;
font-size: 8px;
letter-spacing: 0.02em;
}
.scene-label.mini {
min-width: 0;
padding: 2px 5px;
border: 0;
border-radius: 3px;
background: rgba(9, 14, 20, 0.82);
color: #fff5df;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
box-shadow: none;
}
.disclaimer {
position: fixed;
z-index: 5;
left: 28px;
bottom: 27px;
width: min(445px, calc(100vw - 56px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
pointer-events: none;
}
.note-kicker {
color: var(--coral);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.note-title {
margin-top: 6px;
font-size: 15px;
font-weight: 750;
letter-spacing: -0.015em;
}
.disclaimer p {
margin: 9px 0 0;
color: #aebaca;
font-size: 11px;
line-height: 1.55;
}
.disclaimer b {
color: #e7eef6;
font-weight: 700;
}
.controls {
position: fixed;
z-index: 6;
right: 28px;
bottom: 27px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
}
.button-row {
display: flex;
gap: 7px;
}
button {
border: 1px solid rgba(210, 226, 242, 0.18);
border-radius: 5px;
padding: 8px 11px;
background: rgba(16, 24, 33, 0.88);
color: #d9e4ef;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
border-color 150ms ease,
background 150ms ease,
color 150ms ease;
}
button:hover,
button:focus-visible {
border-color: rgba(210, 226, 242, 0.42);
background: rgba(29, 40, 53, 0.95);
color: #ffffff;
outline: none;
}
button[aria-pressed="true"] {
border-color: rgba(77, 214, 197, 0.42);
color: #a5f1e7;
}
.hint {
color: #7f8fa2;
font-size: 9px;
letter-spacing: 0.03em;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #0d131b;
color: #aebaca;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 18px;
left: 18px;
}
h1 {
font-size: 34px;
}
.subtitle,
.legend {
display: none;
}
.form-badge {
margin-top: 10px;
}
.disclaimer {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 13px 14px;
}
.disclaimer p {
font-size: 10px;
}
.controls {
right: 12px;
bottom: 178px;
}
.hint {
display: none;
}
.scene-label {
min-width: 112px;
padding: 6px 8px;
}
.scene-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<header class="topbar">
<div class="eyebrow">Design Gallery / 01</div>
<h1>Conic Forms</h1>
<div class="subtitle">
A voxel study of a parabolic reflector profile, an elliptical opening,
and a hyperbolic outline—each paired with its mathematical locus.
</div>
<div class="form-badge">Form study · not an optical simulation</div>
</header>
<div class="legend" aria-hidden="true">
<span><i class="swatch form"></i>scaled form</span>
<span><i class="swatch focus"></i>focal marker</span>
<span><i class="swatch guide"></i>construction guide</span>
</div>
<aside class="disclaimer">
<div class="note-kicker">Important distinction</div>
<div class="note-title">Similar form ≠ identical optics</div>
<p>
The left-hand objects are uniformly scaled copies of the right-hand
mathematical loci. That is <b>geometric similarity</b>, not a claim of
equivalent physical behavior. Only the parabola is treated as a reflector
family; the ellipse and hyperbola are geometric studies here. Real optical
performance also depends on focal length, aperture, curvature, surface
finish, material or coating, alignment, and mounting.
</p>
</aside>
<div class="controls">
<div class="button-row">
<button id="guides" type="button" aria-pressed="true">Guides on</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · wheel to zoom · shift-drag to pan</div>
</div>
<div id="loading">Building voxel gallery…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const labelLayer = document.getElementById("labels");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel gallery of conic sections"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d131b);
scene.fog = new THREE.Fog(0x0d131b, 25, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const root = new THREE.Group();
scene.add(root);
const hemisphere = new THREE.HemisphereLight(0xc9e2ff, 0x17202b, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 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 = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x668dff, 1.35);
rimLight.position.set(-10, 7, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(52, 34),
new THREE.MeshStandardMaterial({
color: 0x0d131b,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.13;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x2b3949, 0x1a2531);
grid.position.y = -0.115;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// -------------------------------------------------------------------------
// Voxel materials and helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
platform: new THREE.MeshStandardMaterial({
color: 0x202a36,
roughness: 0.82,
metalness: 0.08
}),
inset: new THREE.MeshStandardMaterial({
color: 0x17212c,
roughness: 0.9,
metalness: 0.04
}),
board: new THREE.MeshStandardMaterial({
color: 0x152330,
roughness: 0.88,
metalness: 0.05
}),
border: new THREE.MeshStandardMaterial({
color: 0x49657d,
roughness: 0.55,
metalness: 0.2
}),
support: new THREE.MeshStandardMaterial({
color: 0x354555,
roughness: 0.72,
metalness: 0.16
}),
guide: new THREE.MeshStandardMaterial({
color: 0x536a80,
roughness: 0.7,
metalness: 0.08
}),
focus: new THREE.MeshStandardMaterial({
color: 0xfff4dc,
emissive: 0x5a4320,
emissiveIntensity: 0.22,
roughness: 0.38,
metalness: 0.18
})
};
const coral = new THREE.MeshStandardMaterial({
color: 0xff705d,
emissive: 0xff705d,
emissiveIntensity: 0.075,
roughness: 0.48,
metalness: 0.16
});
const gold = new THREE.MeshStandardMaterial({
color: 0xf2c45e,
emissive: 0xf2c45e,
emissiveIntensity: 0.065,
roughness: 0.5,
metalness: 0.14
});
const mint = new THREE.MeshStandardMaterial({
color: 0x4dd6c5,
emissive: 0x4dd6c5,
emissiveIntensity: 0.07,
roughness: 0.47,
metalness: 0.16
});
const guideGroup = new THREE.Group();
root.add(guideGroup);
const focusMeshes = [];
const projectedLabels = [];
function voxel(parent, material, x, y, z, sx, sy, sz) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function focusVoxel(parent, x, y, z, size = 0.18) {
const mesh = voxel(parent, materials.focus, x, y, z, size, size, size);
mesh.userData.baseScale = mesh.scale.clone();
focusMeshes.push(mesh);
return mesh;
}
function dashedX(parent, start, end, y, z, material = materials.guide) {
const step = 0.14;
const dash = 0.075;
for (let x = start; x <= end; x += step) {
voxel(parent, material, x, y, z, dash, 0.035, 0.035);
}
}
function dashedY(parent, x, start, end, z, material = materials.guide) {
const step = 0.14;
const dash = 0.075;
for (let y = start; y <= end; y += step) {
voxel(parent, material, x, y, z, 0.035, dash, 0.035);
}
}
function mathBoard(station) {
// A dark, voxel-proportioned display board behind each construction.
voxel(station, materials.board, 1.1, 1.45, -0.59, 2.16, 2.75, 0.08);
voxel(station, materials.border, 1.1, 2.84, -0.525, 2.20, 0.04, 0.05);
voxel(station, materials.border, 1.1, 0.06, -0.525, 2.20, 0.04, 0.05);
voxel(station, materials.border, 0.02, 1.45, -0.525, 0.04, 2.80, 0.05);
voxel(station, materials.border, 2.18, 1.45, -0.525, 0.04, 2.80, 0.05);
}
function addSceneLabel(
station,
position,
kicker,
title,
detail,
accent,
options = {}
) {
const element = document.createElement("div");
element.className = `scene-label${options.mini ? " mini" : ""}`;
if (options.mini) {
element.textContent = title;
} else {
element.innerHTML = `
<span class="kicker">${kicker}</span>
<strong>${title}</strong>
<small>${detail}</small>
`;
}
element.style.setProperty("--accent", accent);
labelLayer.appendChild(element);
station.updateWorldMatrix(true, false);
const anchor = station.localToWorld(
new THREE.Vector3(position.x, position.y, position.z)
);
projectedLabels.push({
element,
anchor,
mini: Boolean(options.mini),
guideOnly: Boolean(options.guideOnly)
});
}
// -------------------------------------------------------------------------
// Station 1: parabola
// -------------------------------------------------------------------------
function createStation(x, accentMaterial, accentHex) {
const station = new THREE.Group();
station.position.x = x;
root.add(station);
voxel(station, materials.platform, 0, 0.01, 0, 4.45, 0.18, 2.90);
voxel(station, materials.inset, 0, 0.13, 0, 4.18, 0.08, 2.62);
voxel(station, accentMaterial, 0, 0.19, 1.37, 3.86, 0.055, 0.075);
voxel(station, materials.border, 0, 0.19, -1.37, 3.86, 0.04, 0.05);
const tint = new THREE.PointLight(accentHex, 11, 7, 2);
tint.position.set(0, 3.7, 2.6);
station.add(tint);
return station;
}
function buildParabola(station) {
const physicalX = -1.15;
const constructionX = 1.1;
// Uniformly scaled voxel copy of y = ax².
const physicalA = 0.55 * 1.242;
for (let i = 0; i <= 66; i++) {
const x = -1.18 + (2.36 * i) / 66;
const y = 0.36 + physicalA * x * x;
voxel(station, coral, physicalX + x, y, 0.05, 0.145, 0.145, 0.38);
}
// Quiet support ribs behind the profile.
for (const side of [-1, 1]) {
const x = side * 0.91;
const top = 0.36 + physicalA * x * x;
for (let y = 0.20; y < top; y += 0.14) {
voxel(
station,
materials.support,
physicalX + x,
y,
-0.22,
0.075,
0.13,
0.09
);
}
}
mathBoard(station);
// Mathematical construction: y = ax².
const a = 0.55;
for (let i = 0; i <= 76; i++) {
const x = -0.95 + (1.90 * i) / 76;
const y = 1.0 + a * x * x;
voxel(station, coral, constructionX + x, y, -0.43, 0.095, 0.095, 0.12);
}
// Focus and directrix.
const focusY = 1.0 + 1 / (4 * a);
const directrixY = 1.0 - 1 / (4 * a);
focusVoxel(guideGroup, constructionX, focusY, -0.36);
dashedX(
guideGroup,
constructionX - 0.95,
constructionX + 0.95,
directrixY,
-0.38,
materials.focus
);
// Construction axes.
dashedY(guideGroup, constructionX, 0.35, 2.55, -0.39);
dashedX(guideGroup, constructionX - 0.95, constructionX + 0.95, 0.27, -0.40);
addSceneLabel(
station,
{ x: physicalX, y: 1.64, z: 0.1 },
"01A / Scaled form",
"Reflector profile",
"uniformly scaled parabolic family",
"#ff705d"
);
addSceneLabel(
station,
{ x: constructionX, y: 3.03, z: -0.35 },
"01B / Mathematical locus",
"Parabola construction",
"y = ax² · focus + directrix",
"#ff705d"
);
addSceneLabel(
station,
{ x: constructionX + 0.10, y: focusY + 0.10, z: -0.30 },
"",
"F",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
addSceneLabel(
station,
{ x: constructionX - 0.67, y: directrixY + 0.09, z: -0.30 },
"",
"directrix",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
}
// -------------------------------------------------------------------------
// Station 2: ellipse
// -------------------------------------------------------------------------
function buildEllipse(station) {
const physicalX = -1.15;
const constructionX = 1.1;
const scale = 1.35;
// Uniformly scaled voxel ellipse: a² / b² is unchanged.
const physicalA = 0.82 * scale;
const physicalB = 0.58 * scale;
const physicalY = 1.50;
for (let i = 0; i < 78; i++) {
const theta = (Math.PI * 2 * i) / 78;
const x = physicalX + physicalA * Math.cos(theta);
const y = physicalY + physicalB * Math.sin(theta);
voxel(station, gold, x, y, 0.06, 0.145, 0.145, 0.34);
}
// Two understated support columns behind the opening.
for (const side of [-1, 1]) {
const x = side * 0.66;
const attachmentY =
physicalY -
physicalB * Math.sqrt(1 - Math.pow(x / physicalA, 2));
for (let y = 0.20; y < attachmentY; y += 0.14) {
voxel(
station,
materials.support,
physicalX + x,
y,
-0.16,
0.075,
0.13,
0.09
);
}
}
mathBoard(station);
// Mathematical construction: x²/a² + y²/b² = 1.
const a = 0.82;
const b = 0.58;
const cy = 1.50;
for (let i = 0; i < 72; i++) {
const theta = (Math.PI * 2 * i) / 72;
const x = constructionX + a * Math.cos(theta);
const y = cy + b * Math.sin(theta);
voxel(station, gold, x, y, -0.43, 0.095, 0.095, 0.12);
}
const c = Math.sqrt(a * a - b * b);
focusVoxel(guideGroup, constructionX - c, cy, -0.36);
focusVoxel(guideGroup, constructionX + c, cy, -0.36);
// Axes and focal segment.
dashedY(guideGroup, constructionX, 0.30, 2.55, -0.39);
dashedX(guideGroup, constructionX - 0.95, constructionX + 0.95, cy, -0.40);
dashedX(guideGroup, constructionX - c, constructionX + c, cy - 0.18, -0.38);
addSceneLabel(
station,
{ x: physicalX, y: 2.57, z: 0.1 },
"02A / Scaled form",
"Elliptical opening",
"uniformly scaled elliptical rim",
"#f2c45e"
);
addSceneLabel(
station,
{ x: constructionX, y: 3.03, z: -0.35 },
"02B / Mathematical locus",
"Ellipse + foci",
"x²/a² + y²/b² = 1",
"#f2c45e"
);
addSceneLabel(
station,
{ x: constructionX - c - 0.10, y: cy + 0.14, z: -0.30 },
"",
"F₁",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
addSceneLabel(
station,
{ x: constructionX + c - 0.08, y: cy + 0.14, z: -0.30 },
"",
"F₂",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
}
// -------------------------------------------------------------------------
// Station 3: hyperbola
// -------------------------------------------------------------------------
function buildHyperbola(station) {
const physicalX = -1.15;
const constructionX = 1.1;
const scale = 1.25;
const cy = 1.50;
// Uniformly scaled hyperbola: a/b remains constant.
const physicalA = 0.48 * scale;
const physicalB = 0.68 * scale;
const physicalY = 1.375;
for (const side of [-1, 1]) {
for (let i = 0; i <= 58; i++) {
const y = -physicalY + (2 * physicalY * i) / 58;
const x =
side * physicalA * Math.sqrt(1 + Math.pow(y / physicalB, 2));
voxel(
station,
mint,
physicalX + x,
cy + y,
0.05,
0.14,
0.14,
0.34
);
}
}
mathBoard(station);
// Mathematical construction: x²/a² − y²/b² = 1.
const a = 0.48;
const b = 0.68;
const constructionY = 1.10;
for (const side of [-1, 1]) {
for (let i = 0; i <= 50; i++) {
const y = -constructionY + (2 * constructionY * i) / 50;
const x = side * a * Math.sqrt(1 + Math.pow(y / b, 2));
voxel(
station,
mint,
constructionX + x,
cy + y,
-0.43,
0.095,
0.095,
0.12
);
}
}
const c = Math.sqrt(a * a + b * b);
focusVoxel(guideGroup, constructionX - c, cy, -0.36);
focusVoxel(guideGroup, constructionX + c, cy, -0.36);
// Transverse axis and focal segment.
dashedX(guideGroup, constructionX - 0.97, constructionX + 0.97, cy, -0.40);
dashedY(guideGroup, constructionX, 0.30, 2.55, -0.39);
dashedX(guideGroup, constructionX - c, constructionX + c, cy - 0.18, -0.38);
addSceneLabel(
station,
{ x: physicalX, y: 3.12, z: 0.1 },
"03A / Scaled form",
"Hyperbolic outline",
"uniformly scaled branching form",
"#4dd6c5"
);
addSceneLabel(
station,
{ x: constructionX, y: 3.03, z: -0.35 },
"03B / Mathematical locus",
"Hyperbola + foci",
"x²/a² − y²/b² = 1",
"#4dd6c5"
);
addSceneLabel(
station,
{ x: constructionX - c - 0.10, y: cy + 0.14, z: -0.30 },
"",
"F₁",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
addSceneLabel(
station,
{ x: constructionX + c - 0.08, y: cy + 0.14, z: -0.30 },
"",
"F₂",
"",
"#fff4dc",
{ mini: true, guideOnly: true }
);
}
const parabolaStation = createStation(-6.1, coral, 0xff705d);
const ellipseStation = createStation(0, gold, 0xf2c45e);
const hyperbolaStation = createStation(6.1, mint, 0x4dd6c5);
buildParabola(parabolaStation);
buildEllipse(ellipseStation);
buildHyperbola(hyperbolaStation);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and shift-drag pan
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.045,
phi: 1.27,
radius: 21,
target: new THREE.Vector3(0, 1.25, 0)
};
function preferredRadius() {
const verticalHalfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
const horizontalHalfFov = Math.atan(
Math.tan(verticalHalfFov) * camera.aspect
);
return THREE.MathUtils.clamp(9.3 / horizontalHalfFov, 20.5, 48);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.045;
cameraState.phi = 1.27;
cameraState.radius = preferredRadius();
cameraState.target.set(0, 1.25, 0);
updateCamera();
}
let dragging = false;
let dragPointerId = null;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragPointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== dragPointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const panScale = cameraState.radius * 0.00145;
cameraState.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-8,
8
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
0.4,
4.5
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-3,
3
);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.004,
0.48,
1.49
);
}
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== dragPointerId) return;
dragging = false;
dragPointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
48
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const guidesButton = document.getElementById("guides");
const resetButton = document.getElementById("reset");
let guidesVisible = true;
guidesButton.addEventListener("click", () => {
guidesVisible = !guidesVisible;
guideGroup.visible = guidesVisible;
guidesButton.setAttribute("aria-pressed", String(guidesVisible));
guidesButton.textContent = guidesVisible ? "Guides on" : "Guides off";
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
} else if (key === "g") {
guidesButton.click();
} else if (key === "arrowleft") {
cameraState.theta += 0.08;
updateCamera();
} else if (key === "arrowright") {
cameraState.theta -= 0.08;
updateCamera();
} else if (key === "arrowup") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - 0.05,
0.48,
1.49
);
updateCamera();
} else if (key === "arrowdown") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + 0.05,
0.48,
1.49
);
updateCamera();
} else if (key === "+" || key === "=") {
cameraState.radius = Math.max(12, cameraState.radius - 1);
updateCamera();
} else if (key === "-") {
cameraState.radius = Math.min(48, cameraState.radius + 1);
updateCamera();
}
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of projectedLabels) {
if (item.guideOnly && !guidesVisible) {
item.element.style.display = "none";
continue;
}
const projected = item.anchor.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const inView =
projected.z > -1 &&
projected.z < 1 &&
x > -120 &&
x < width + 120 &&
y > -80 &&
y < height + 80;
item.element.style.display = inView ? "block" : "none";
item.element.style.opacity = item.mini ? "0.95" : "1";
item.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
resetCamera();
let firstFrame = true;
renderer.setAnimationLoop((time) => {
// A restrained pulse makes the focal markers easy to locate.
focusMeshes.forEach((mesh, index) => {
const base = mesh.userData.baseScale;
const pulse = 1 + 0.075 * Math.sin(time * 0.002 + index * 1.35);
mesh.scale.set(base.x * pulse, base.y * pulse, base.z * pulse);
});
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
}
});
</script>
</body>
</html>
```