Prompt specification
Build or customize the Three.js 3D scene "Linear and quadratic operation towers" 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: Linear and quadratic operation towers
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/linear-and-quadratic-operation-towers-x1841
Scene Description Prompt:
Build low-poly operation-count towers for explicit linear and quadratic algorithms across small input sizes. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (linear-and-quadratic-operation-towers-x1841):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Operation Towers</title>
<style>
:root {
color-scheme: dark;
--bg: #071218;
--panel: rgba(10, 23, 30, 0.9);
--line: rgba(157, 201, 211, 0.18);
--text: #e8f4f5;
--muted: #8ca6ae;
--linear: #59e2c7;
--quadratic: #ff806d;
}
* {
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;
}
canvas {
display: block;
outline: none;
}
button {
font: inherit;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
width: min(430px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 1px;
content: "";
background: var(--linear);
box-shadow: 0 0 8px rgba(89, 226, 199, 0.55);
}
h1 {
margin: 0;
font-size: clamp(28px, 3.4vw, 50px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.055em;
}
.brand p {
max-width: 390px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.inspector {
position: absolute;
top: 26px;
right: 26px;
width: 330px;
padding: 20px;
overflow: hidden;
pointer-events: auto;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(16px);
}
.inspector::before {
position: absolute;
top: 0;
left: 20px;
width: 64px;
height: 2px;
content: "";
background: var(--algorithm-color, var(--linear));
box-shadow: 0 0 16px var(--algorithm-color, var(--linear));
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.size-pill {
padding: 5px 9px;
color: var(--algorithm-color, var(--linear));
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 800;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--line);
border-radius: 999px;
}
.inspector h2 {
margin: 0 0 8px;
font-size: 21px;
font-weight: 650;
letter-spacing: -0.025em;
}
.description {
min-height: 54px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.metric {
display: flex;
align-items: flex-end;
gap: 10px;
margin: 18px 0 14px;
}
.metric strong {
color: var(--algorithm-color, var(--linear));
font-size: 45px;
font-weight: 600;
line-height: 0.9;
letter-spacing: -0.06em;
}
.metric span {
padding-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.formula {
padding: 10px 12px;
color: var(--algorithm-color, var(--linear));
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
background: rgba(255, 255, 255, 0.035);
border: 1px solid var(--line);
border-radius: 9px;
}
pre {
margin: 13px 0 16px;
padding: 13px;
overflow: auto;
color: #bdd0d5;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.65;
background: rgba(0, 0, 0, 0.22);
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 10px;
}
.reset {
width: 100%;
padding: 10px 12px;
cursor: pointer;
color: var(--text);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
background: rgba(255, 255, 255, 0.045);
border: 1px solid var(--line);
border-radius: 9px;
transition:
background 160ms ease,
border-color 160ms ease;
}
.reset:hover {
background: rgba(255, 255, 255, 0.08);
border-color: rgba(255, 255, 255, 0.28);
}
.legend {
position: absolute;
bottom: 28px;
left: 30px;
display: flex;
flex-wrap: wrap;
gap: 18px;
align-items: center;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #b9ccd1;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
transform: rotate(45deg);
border-radius: 2px;
}
.swatch.linear {
background: var(--linear);
box-shadow: 0 0 10px rgba(89, 226, 199, 0.45);
}
.swatch.quadratic {
background: var(--quadratic);
box-shadow: 0 0 10px rgba(255, 128, 109, 0.42);
}
.hint {
position: absolute;
right: 28px;
bottom: 29px;
color: #6f8a92;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.tower-label {
position: absolute;
min-width: 64px;
padding: 7px 9px 6px;
transform: translate(-50%, -100%);
text-align: center;
background: rgba(7, 18, 24, 0.9);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(8px);
transition:
opacity 120ms ease,
border-color 120ms ease,
transform 120ms ease;
}
.tower-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
content: "";
transform: translateX(-50%) rotate(45deg);
background: #09151b;
border-right: 1px solid rgba(255, 255, 255, 0.16);
border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}
.tower-label span {
display: block;
margin-bottom: 3px;
color: #849da5;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.tower-label strong {
color: var(--tower-color);
font-size: 14px;
font-weight: 700;
}
.tower-label.selected {
border-color: var(--tower-color);
box-shadow:
0 8px 24px rgba(0, 0, 0, 0.35),
0 0 18px color-mix(in srgb, var(--tower-color) 24%, transparent);
}
.loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
background: var(--bg);
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
max-width: 280px;
margin-top: 10px;
font-size: 11px;
}
.inspector {
top: auto;
right: 12px;
bottom: 54px;
left: 12px;
width: auto;
padding: 15px;
}
.description,
pre {
display: none;
}
.metric {
margin: 12px 0 10px;
}
.metric strong {
font-size: 34px;
}
.legend {
bottom: 18px;
left: 18px;
gap: 12px;
}
.hint {
right: 18px;
bottom: 18px;
max-width: 110px;
text-align: right;
line-height: 1.5;
}
.tower-label {
min-width: 52px;
padding: 5px 7px;
}
.tower-label strong {
font-size: 11px;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Constructing operation towers…</div>
<div id="labels" aria-hidden="true"></div>
<main class="hud">
<header class="brand">
<div class="eyebrow">Algorithm field notes · 01</div>
<h1>Operation<br />Towers</h1>
<p>
Every hexagonal floor is one measured comparison. Compare the height of
an explicit linear scan with an explicit pairwise quadratic scan.
</p>
</header>
<aside class="inspector" id="inspector">
<div class="panel-top">
<span class="panel-kicker">Selected algorithm</span>
<span class="size-pill" id="nValue">n = 8</span>
</div>
<h2 id="algoName">Linear search</h2>
<p class="description" id="algoDescription"></p>
<div class="metric">
<strong id="opCount">0</strong>
<span>comparison operations</span>
</div>
<div class="formula" id="formula"></div>
<pre id="code"></pre>
<button class="reset" id="resetView" type="button">Reset camera</button>
</aside>
<div class="legend">
<div class="legend-item">
<span class="swatch linear"></span>
Linear scan
</div>
<div class="legend-item">
<span class="swatch quadratic"></span>
Quadratic pair scan
</div>
<div class="legend-item">1 floor = 1 operation</div>
</div>
<div class="hint">Drag to orbit · wheel to zoom · click a tower</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071218);
scene.fog = new THREE.Fog(0x071218, 28, 58);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D visualization of linear and quadratic operation counts"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbcefff, 0x182326, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xdafaff, 3.1);
keyLight.position.set(-7, 18, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -22;
keyLight.shadow.camera.right = 22;
keyLight.shadow.camera.top = 22;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xff826f, 1.1);
rimLight.position.set(12, 9, -10);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x09151b,
roughness: 0.98,
metalness: 0,
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(62, 42),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(54, 27, 0x27454d, 0x142a31);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const SIZES = [4, 5, 6, 7, 8, 9, 10, 11, 12];
const SPACING = 2.12;
const STEP_HEIGHT = 0.24;
const BLOCK_HEIGHT = 0.205;
const BLOCK_RADIUS = 0.46;
const TOWER_BASE_Y = 0.38;
const families = [
{
key: "linear",
name: "Linear search",
color: 0x59e2c7,
z: -3.35,
description:
"A worst-case linear search inspects every element until the target is found at the final position.",
formula: "operations = n",
code: `linearSearch(a, target):\n for i = 0 to n - 1:\n compare a[i] with target\n return NOT_FOUND`,
},
{
key: "quadratic",
name: "Quadratic pair scan",
color: 0xff806d,
z: 3.35,
description:
"An all-pairs algorithm compares each item with every later item, producing a triangular operation count.",
formula: "operations = n(n − 1) / 2",
code: `pairScan(a):\n for i = 0 to n - 1:\n for j = i + 1 to n - 1:\n compare a[i] with a[j]`,
},
];
const laneWidth = SPACING * (SIZES.length - 1) + 2.4;
const blockGeometry = new THREE.CylinderGeometry(1, 1, 1, 6, 1, false);
const blockMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.06,
});
const towers = [];
const towerMeshes = [];
const dummy = new THREE.Object3D();
function createLane(family) {
const platform = new THREE.Mesh(
new THREE.BoxGeometry(laneWidth, 0.12, 2.45),
new THREE.MeshStandardMaterial({
color: 0x102129,
roughness: 0.9,
metalness: 0.03,
})
);
platform.position.set(0, 0.06, family.z);
platform.receiveShadow = true;
scene.add(platform);
const edge = new THREE.Mesh(
new THREE.BoxGeometry(laneWidth, 0.035, 0.065),
new THREE.MeshBasicMaterial({ color: family.color })
);
edge.position.set(0, 0.135, family.z - 1.18);
scene.add(edge);
}
function operationCount(family, n) {
return family.key === "linear" ? n : (n * (n - 1)) / 2;
}
function createTower(family, n, index) {
const count = operationCount(family, n);
const x = (index - (SIZES.length - 1) / 2) * SPACING;
const key = `${family.key}-${n}`;
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.64, 0.73, 0.24, 6),
new THREE.MeshStandardMaterial({
color: 0x263940,
roughness: 0.9,
metalness: 0.02,
})
);
pedestal.position.set(x, 0.24, family.z);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const mesh = new THREE.InstancedMesh(
blockGeometry,
blockMaterial,
count
);
mesh.position.set(x, 0, family.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
const baseColors = [];
for (let operation = 0; operation < count; operation++) {
dummy.position.set(
0,
TOWER_BASE_Y + operation * STEP_HEIGHT + BLOCK_HEIGHT / 2,
0
);
dummy.rotation.set(0, (operation % 2) * Math.PI / 6, 0);
dummy.scale.set(BLOCK_RADIUS, BLOCK_HEIGHT, BLOCK_RADIUS);
dummy.updateMatrix();
mesh.setMatrixAt(operation, dummy.matrix);
const color = new THREE.Color(family.color);
const stripe = operation % 6 === 0;
color.offsetHSL(0, stripe ? 0.02 : -0.02, stripe ? 0.1 : operation % 2 ? 0.015 : -0.055);
mesh.setColorAt(operation, color);
baseColors.push(color);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
scene.add(mesh);
const label = document.createElement("div");
label.className = "tower-label";
label.style.setProperty("--tower-color", `#${family.color.toString(16).padStart(6, "0")}`);
label.innerHTML = `
<span>n = ${n}</span>
<strong>${count} ops</strong>
`;
document.getElementById("labels").appendChild(label);
const tower = {
key,
family,
n,
count,
mesh,
baseColors,
label,
labelWorld: new THREE.Vector3(
x,
TOWER_BASE_Y + count * STEP_HEIGHT + 0.3,
family.z
),
topY: TOWER_BASE_Y + count * STEP_HEIGHT,
};
towers.push(tower);
towerMeshes.push(mesh);
}
families.forEach((family) => {
createLane(family);
SIZES.forEach((n, index) => createTower(family, n, index));
});
const selectionBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.69, 0.69, 1, 6, 1, true),
new THREE.MeshBasicMaterial({
color: 0x59e2c7,
transparent: true,
opacity: 0.09,
side: THREE.DoubleSide,
depthWrite: false,
})
);
scene.add(selectionBeam);
const selectionHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.7, 0.025, 6, 24),
new THREE.MeshBasicMaterial({
color: 0x59e2c7,
transparent: true,
opacity: 0.85,
})
);
selectionHalo.rotation.x = Math.PI / 2;
scene.add(selectionHalo);
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 34;
dustPositions[i * 3 + 1] = Math.random() * 18;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 25;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x86aeb8,
size: 0.035,
transparent: true,
opacity: 0.36,
depthWrite: false,
})
);
scene.add(dust);
const orbit = {
yaw: -0.31,
pitch: 0.27,
distance: innerWidth < 760 ? 39 : 31,
targetYaw: -0.31,
targetPitch: 0.27,
targetDistance: innerWidth < 760 ? 39 : 31,
target: new THREE.Vector3(0, 4.6, 0),
};
function updateCamera() {
const horizontalDistance =
orbit.distance * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + horizontalDistance * Math.sin(orbit.yaw),
orbit.target.y + orbit.distance * Math.sin(orbit.pitch),
orbit.target.z + horizontalDistance * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
updateCamera();
const inspector = document.getElementById("inspector");
const nValue = document.getElementById("nValue");
const algoName = document.getElementById("algoName");
const algoDescription = document.getElementById("algoDescription");
const opCount = document.getElementById("opCount");
const formula = document.getElementById("formula");
const code = document.getElementById("code");
let selectedTower = null;
let hoveredTower = null;
function refreshTowerColors() {
towers.forEach((tower) => {
tower.baseColors.forEach((baseColor, index) => {
const color = baseColor.clone();
if (tower === selectedTower) {
color.lerp(new THREE.Color(0xffffff), 0.2);
} else if (tower === hoveredTower) {
color.lerp(new THREE.Color(0xffffff), 0.12);
}
tower.mesh.setColorAt(index, color);
});
tower.mesh.instanceColor.needsUpdate = true;
});
}
function selectTower(tower) {
selectedTower = tower;
const cssColor = `#${tower.family.color.toString(16).padStart(6, "0")}`;
inspector.style.setProperty("--algorithm-color", cssColor);
nValue.textContent = `n = ${tower.n}`;
algoName.textContent = tower.family.name;
algoDescription.textContent = tower.family.description;
opCount.textContent = tower.count.toLocaleString();
formula.textContent = tower.family.formula;
code.textContent = tower.family.code;
selectionBeam.material.color.setHex(tower.family.color);
selectionHalo.material.color.setHex(tower.family.color);
const beamBottom = 0.37;
const beamHeight = Math.max(0.1, tower.topY - beamBottom);
selectionBeam.position.y = beamBottom + beamHeight / 2;
selectionBeam.scale.y = beamHeight;
selectionBeam.scale.x = 1;
selectionBeam.scale.z = 1;
selectionHalo.position.set(
tower.mesh.position.x,
0.39,
tower.family.z
);
towers.forEach((item) => {
item.label.classList.toggle("selected", item === tower);
});
refreshTowerColors();
}
selectTower(towers.find((tower) => tower.family.key === "linear" && tower.n === 8));
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function findTower(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(towerMeshes, false);
if (!intersections.length) return null;
const hit = intersections[0];
return towers.find((tower) => tower.mesh === hit.object);
}
let dragging = false;
let pointerStart = null;
let previousPointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { ...pointerStart };
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
orbit.targetYaw -= dx * 0.006;
orbit.targetPitch = THREE.MathUtils.clamp(
orbit.targetPitch + dy * 0.0045,
0.1,
1.05
);
previousPointer = { x: event.clientX, y: event.clientY };
return;
}
const tower = findTower(event.clientX, event.clientY);
const nextHover = tower ? tower.key : null;
renderer.domElement.style.cursor = tower ? "pointer" : "grab";
if (nextHover !== (hoveredTower ? hoveredTower.key : null)) {
hoveredTower = tower;
refreshTowerColors();
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
const movement = pointerStart
? Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
)
: 0;
if (movement < 6) {
const tower = findTower(event.clientX, event.clientY);
if (tower) selectTower(tower);
}
renderer.domElement.style.cursor = hoveredTower ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging && hoveredTower) {
hoveredTower = null;
refreshTowerColors();
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetDistance = THREE.MathUtils.clamp(
orbit.targetDistance * Math.exp(event.deltaY * 0.001),
17,
52
);
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
orbit.targetYaw = -0.31;
orbit.targetPitch = 0.27;
orbit.targetDistance = innerWidth < 760 ? 39 : 31;
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.targetYaw += 0.12;
if (event.key === "ArrowRight") orbit.targetYaw -= 0.12;
if (event.key === "ArrowUp") {
orbit.targetPitch = Math.min(1.05, orbit.targetPitch + 0.08);
}
if (event.key === "ArrowDown") {
orbit.targetPitch = Math.max(0.1, orbit.targetPitch - 0.08);
}
if (event.key === "+" || event.key === "=") {
orbit.targetDistance = Math.max(17, orbit.targetDistance - 2);
}
if (event.key === "-" || event.key === "_") {
orbit.targetDistance = Math.min(52, orbit.targetDistance + 2);
}
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
towers.forEach((tower) => {
projected.copy(tower.labelWorld).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
tower.label.style.opacity = visible ? "1" : "0";
tower.label.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
tower.label.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
});
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
orbit.yaw += (orbit.targetYaw - orbit.yaw) * 0.085;
orbit.pitch += (orbit.targetPitch - orbit.pitch) * 0.085;
orbit.distance += (orbit.targetDistance - orbit.distance) * 0.085;
updateCamera();
updateLabels();
dust.rotation.y = elapsed * 0.012;
dust.position.y = Math.sin(elapsed * 0.16) * 0.08;
const pulse = 1 + Math.sin(elapsed * 2.7) * 0.065;
selectionHalo.scale.setScalar(pulse);
selectionBeam.material.opacity = 0.075 + Math.sin(elapsed * 2.7) * 0.025;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```