Prompt specification
Build or customize the Three.js 3D scene "Stacked environmental timescale rings" 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: Stacked environmental timescale rings
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stacked-environmental-timescale-rings-x1209
Scene Description Prompt:
Stacked environmental timescale rings. Create concentric labeled rings for day, season, decade, and geological intervals; use schematic proportions and separate cyclic changes from long-term directional trends. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (stacked-environmental-timescale-rings-x1209):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Nested Environmental Timescales</title>
<style>
:root {
color-scheme: dark;
--ink: #e7f5f7;
--muted: #8da8b3;
--cyan: #58e2d2;
--amber: #ffb454;
--violet: #8d83e8;
--panel: rgba(7, 18, 26, 0.72);
--line: rgba(137, 184, 201, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, #102735 0%, #08131d 38%, #040a10 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::before {
position: fixed;
inset: 0;
pointer-events: none;
content: "";
opacity: 0.22;
background-image:
linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: radial-gradient(circle at center, black, transparent 78%);
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
width: min(430px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(27px, 3.2vw, 46px);
font-weight: 720;
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 5;
top: 28px;
right: 30px;
width: 255px;
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
color: #b8ccd4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 23px 1fr;
align-items: center;
gap: 9px;
margin: 9px 0;
color: #d5e7ec;
font-size: 11px;
}
.legend-row small {
display: block;
margin-top: 2px;
color: #78919d;
font-size: 9.5px;
}
.swatch {
display: block;
width: 19px;
height: 19px;
border: 1px solid rgba(255,255,255,.14);
}
.swatch.cycle {
border-radius: 50%;
background:
linear-gradient(90deg, transparent 38%, var(--cyan) 39% 61%, transparent 62%),
radial-gradient(circle, transparent 0 26%, #17433f 27% 100%);
box-shadow: 0 0 12px rgba(88,226,210,.18);
}
.swatch.trend {
color: var(--amber);
font-size: 21px;
font-weight: 800;
line-height: 17px;
text-align: center;
}
.swatch.interval {
border-radius: 4px 10px 4px 10px;
background: linear-gradient(135deg, #9a8ff0, #4d598e);
}
.caption {
position: fixed;
z-index: 5;
left: 32px;
bottom: 28px;
width: min(440px, calc(100vw - 64px));
color: #78929e;
font-size: 11px;
line-height: 1.55;
pointer-events: none;
}
.caption strong {
color: #aac2cb;
font-weight: 650;
}
.hint {
position: fixed;
z-index: 5;
right: 30px;
bottom: 28px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: #829ba6;
background: rgba(7, 18, 26, .62);
font-size: 10px;
letter-spacing: .03em;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.legend {
top: auto;
right: 16px;
bottom: 58px;
width: 205px;
padding: 11px 13px;
}
.legend-row {
margin: 7px 0;
font-size: 10px;
}
.caption {
display: none;
}
.hint {
right: 16px;
bottom: 16px;
}
}
@media (max-width: 460px) {
.subtitle {
max-width: 270px;
font-size: 11px;
}
.legend {
width: 180px;
}
.legend-row small {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional diagram of nested environmental timescales"></main>
<header class="header">
<div class="eyebrow">Earth systems / nested clocks</div>
<h1>Environmental<br />Timescales</h1>
<p class="subtitle">
Four concentric clocks organize environmental change from hours to deep time.
Recurring cycles and directional trends occupy separate visual lanes.
</p>
</header>
<aside class="legend" aria-label="Diagram legend">
<div class="legend-title">Visual encoding</div>
<div class="legend-row">
<span class="swatch cycle"></span>
<span>
Recurring / cyclic
<small>Faceted pulse profile and phase marker</small>
</span>
</div>
<div class="legend-row">
<span class="swatch trend">→</span>
<span>
Directional drift
<small>Single non-repeating arrow along each clock</small>
</span>
</div>
<div class="legend-row">
<span class="swatch interval"></span>
<span>
Geological interval
<small>Broad sectors within the outer clock</small>
</span>
</div>
</aside>
<div class="caption">
<strong>Schematic, not to scale.</strong>
Ring spacing and interval widths communicate hierarchy rather than exact duration.
Teal facets repeat; amber arrows indicate a sustained direction.
</div>
<div class="hint">Drag to orbit · scroll to zoom · double-click to reset</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.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
renderer.setClearColor(0x000000, 0);
renderer.domElement.setAttribute(
"aria-label",
"Concentric rings representing day, season, decade, and geological timescales"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const diagram = new THREE.Group();
scene.add(diagram);
const hemi = new THREE.HemisphereLight(0xaeefff, 0x10202a, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffffff, 2.8);
key.position.set(4, 6, 9);
scene.add(key);
const rim = new THREE.PointLight(0x43d8d1, 25, 18, 2);
rim.position.set(-5, -2, 6);
scene.add(rim);
const warmRim = new THREE.PointLight(0xffa74e, 16, 15, 2);
warmRim.position.set(5, 3, 4);
scene.add(warmRim);
const palette = {
cyan: 0x58e2d2,
cyanDim: 0x2b8f91,
amber: 0xffb454,
violet: 0x8d83e8,
guide: 0x254452,
muted: 0x142c38
};
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
metalness: 0.12,
flatShading: true,
...options
});
}
const cyanMaterial = standardMaterial(palette.cyan, {
emissive: palette.cyan,
emissiveIntensity: 0.16,
roughness: 0.48
});
const cyanSecondary = standardMaterial(0x75d9dc, {
emissive: 0x2c9b9b,
emissiveIntensity: 0.1
});
const amberMaterial = standardMaterial(palette.amber, {
emissive: 0xa84e12,
emissiveIntensity: 0.18
});
const guideMaterial = standardMaterial(palette.guide, {
roughness: 0.72,
metalness: 0.04
});
// Subtle backplate and radial construction lines.
const backplate = new THREE.Mesh(
new THREE.CircleGeometry(5.02, 48),
new THREE.MeshBasicMaterial({
color: 0x071620,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
backplate.position.z = -0.28;
diagram.add(backplate);
const spokePositions = [];
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
spokePositions.push(
Math.cos(a) * 0.62, Math.sin(a) * 0.62, -0.235,
Math.cos(a) * 5.0, Math.sin(a) * 5.0, -0.235
);
}
const spokeGeometry = new THREE.BufferGeometry();
spokeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(spokePositions, 3)
);
diagram.add(
new THREE.LineSegments(
spokeGeometry,
new THREE.LineBasicMaterial({
color: 0x315463,
transparent: true,
opacity: 0.13,
depthWrite: false
})
)
);
function addGuideCircle(radius, opacity = 0.28, z = -0.2) {
const points = [];
const segments = 96;
for (let i = 0; i <= segments; i++) {
const a = (i / segments) * Math.PI * 2;
points.push(new THREE.Vector3(
Math.cos(a) * radius,
Math.sin(a) * radius,
z
));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: palette.guide,
transparent: true,
opacity
});
const line = new THREE.Line(geometry, material);
diagram.add(line);
return line;
}
addGuideCircle(1.02, 0.34, -0.12);
addGuideCircle(1.62, 0.32, -0.12);
addGuideCircle(2.31, 0.32, -0.12);
addGuideCircle(3.00, 0.32, -0.12);
addGuideCircle(4.64, 0.45, -0.12);
addGuideCircle(5.00, 0.28, -0.19);
function addLowPolyTrack(radius, tube, color = palette.guide) {
const geometry = new THREE.TorusGeometry(radius, tube, 4, 64);
const mesh = new THREE.Mesh(
geometry,
standardMaterial(color, {
roughness: 0.64,
metalness: 0.16
})
);
mesh.position.z = -0.035;
diagram.add(mesh);
return mesh;
}
addLowPolyTrack(1.02, 0.032);
addLowPolyTrack(1.62, 0.032);
addLowPolyTrack(2.31, 0.032);
const pulseMarkers = [];
function addPulseRing({
baseRadius,
count,
values,
width,
minLength,
maxLength,
speed,
phase = -Math.PI / 2
}) {
const unitBox = new THREE.BoxGeometry(1, 1, 1);
for (let i = 0; i < count; i++) {
const angle = phase + (i / count) * Math.PI * 2;
const value = values[i % values.length];
const length = minLength + value * maxLength;
const mesh = new THREE.Mesh(
unitBox,
i % 2 === 0 ? cyanMaterial : cyanSecondary
);
mesh.scale.set(length, width, 0.085);
mesh.position.set(
Math.cos(angle) * (baseRadius + length / 2),
Math.sin(angle) * (baseRadius + length / 2),
0.095
);
mesh.rotation.z = angle;
diagram.add(mesh);
}
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.075, 0),
standardMaterial(0xc5fff6, {
emissive: palette.cyan,
emissiveIntensity: 0.8,
roughness: 0.28
})
);
marker.position.z = 0.235;
diagram.add(marker);
pulseMarkers.push({
marker,
radius: baseRadius + 0.035,
speed,
phase
});
const points = [];
for (let i = 0; i <= 96; i++) {
const a = (i / 96) * Math.PI * 2;
points.push(new THREE.Vector3(
Math.cos(a) * (baseRadius + minLength + maxLength + 0.045),
Math.sin(a) * (baseRadius + minLength + maxLength + 0.045),
0.02
));
}
const envelope = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: palette.cyan,
transparent: true,
opacity: 0.16,
dashSize: 0.07,
gapSize: 0.09,
depthWrite: false
})
);
envelope.computeLineDistances();
diagram.add(envelope);
}
addPulseRing({
baseRadius: 1.05,
count: 12,
values: [
0.25, 0.48, 0.72, 0.94, 0.76, 0.44,
0.20, 0.34, 0.66, 0.91, 0.69, 0.39
],
width: 0.25,
minLength: 0.08,
maxLength: 0.24,
speed: 0.72
});
addPulseRing({
baseRadius: 1.65,
count: 4,
values: [0.52, 0.92, 0.64, 0.78],
width: 0.78,
minLength: 0.10,
maxLength: 0.31,
speed: 0.34
});
addPulseRing({
baseRadius: 2.34,
count: 10,
values: [
0.32, 0.48, 0.71, 0.52, 0.29,
0.41, 0.86, 0.64, 0.47, 0.58
],
width: 0.46,
minLength: 0.09,
maxLength: 0.34,
speed: 0.14
});
function addTrendArrow(radius, start, end, z = 0.17) {
const dashCount = 10;
const arcLength = radius * (end - start);
const dashLength = (arcLength / dashCount) * 0.55;
const unitBox = new THREE.BoxGeometry(1, 1, 1);
for (let i = 0; i < dashCount; i++) {
const a = start + ((i + 0.5) / dashCount) * (end - start);
const dash = new THREE.Mesh(unitBox, amberMaterial);
dash.scale.set(0.045, dashLength, 0.04);
dash.position.set(
Math.cos(a) * radius,
Math.sin(a) * radius,
z
);
dash.rotation.z = a;
diagram.add(dash);
}
const tangent = new THREE.Vector3(
-Math.sin(end),
Math.cos(end),
0
).normalize();
const arrowhead = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.24, 4),
amberMaterial
);
arrowhead.position.set(
Math.cos(end) * radius,
Math.sin(end) * radius,
z
);
arrowhead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
diagram.add(arrowhead);
const startMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055, 0),
amberMaterial
);
startMarker.position.set(
Math.cos(start) * radius,
Math.sin(start) * radius,
z
);
diagram.add(startMarker);
}
// Directional trends are deliberately single, non-repeating arrows.
addTrendArrow(0.68, -2.05, -0.40, 0.18);
addTrendArrow(1.28, -2.05, -0.40, 0.18);
addTrendArrow(2.00, -2.05, -0.40, 0.18);
addTrendArrow(2.91, -2.05, -0.40, 0.18);
function makeAnnularSector(inner, outer, start, end, depth, steps = 12) {
const shape = new THREE.Shape();
shape.absarc(0, 0, outer, start, end, false);
shape.lineTo(
Math.cos(end) * inner,
Math.sin(end) * inner
);
shape.absarc(0, 0, inner, end, start, true);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: steps,
steps: 1
});
geometry.translate(0, 0, -depth / 2);
return geometry;
}
const geologicalIntervals = [
{
name: "CENOZOIC",
width: 0.18,
color: 0x9b8ef1,
note: "recent life"
},
{
name: "MESOZOIC",
width: 0.22,
color: 0x7776ce,
note: "dinosaurs"
},
{
name: "PALEOZOIC",
width: 0.23,
color: 0x58699f,
note: "complex life"
},
{
name: "PRECAMBRIAN",
width: 0.37,
color: 0x3e527c,
note: "early Earth"
}
];
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function createTextSprite({
title,
subtitle = "",
color = "#e7f5f7",
accent = "#58e2d2",
height = 0.65,
panel = true
}) {
const canvas = document.createElement("canvas");
canvas.width = 960;
canvas.height = 320;
const ctx = canvas.getContext("2d");
if (panel) {
roundedRect(ctx, 12, 12, 936, 296, 28);
ctx.fillStyle = "rgba(5, 16, 24, 0.72)";
ctx.fill();
ctx.strokeStyle = "rgba(112, 162, 180, 0.35)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(12, 12, 9, 296);
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.shadowColor = "rgba(0,0,0,0.8)";
ctx.shadowBlur = 15;
ctx.fillStyle = color;
ctx.font = '800 78px Inter, Arial, sans-serif';
ctx.fillText(title, canvas.width / 2, subtitle ? 112 : 160);
if (subtitle) {
ctx.shadowBlur = 8;
ctx.fillStyle = accent;
ctx.font = '600 39px Inter, Arial, sans-serif';
ctx.fillText(subtitle, canvas.width / 2, 218);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const aspect = canvas.width / canvas.height;
sprite.scale.set(height * aspect, height, 1);
sprite.renderOrder = 30;
return sprite;
}
function createIntervalSprite(name, color) {
const canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 150;
const ctx = canvas.getContext("2d");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.shadowColor = "rgba(0,0,0,0.95)";
ctx.shadowBlur = 14;
ctx.fillStyle = color;
ctx.font = '800 58px Inter, Arial, sans-serif';
ctx.fillText(name, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
const aspect = canvas.width / canvas.height;
sprite.scale.set(0.29 * aspect, 0.29, 1);
sprite.renderOrder = 25;
return sprite;
}
let intervalAngle = -Math.PI / 2;
for (const interval of geologicalIntervals) {
const gap = 0.018;
const start = intervalAngle + gap / 2;
const end = intervalAngle + interval.width - gap / 2;
const middle = (start + end) / 2;
const mesh = new THREE.Mesh(
makeAnnularSector(3.02, 4.61, start, end, 0.11, 10),
standardMaterial(interval.color, {
roughness: 0.72,
metalness: 0.05,
emissive: interval.color,
emissiveIntensity: 0.035
})
);
mesh.position.z = -0.015;
diagram.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
new THREE.LineBasicMaterial({
color: 0xc0c5ff,
transparent: true,
opacity: 0.24
})
);
edges.position.copy(mesh.position);
diagram.add(edges);
const label = createIntervalSprite(
interval.name,
`#${interval.color.toString(16).padStart(6, "0")}`
);
label.position.set(
Math.cos(middle) * 3.82,
Math.sin(middle) * 3.82,
0.26
);
diagram.add(label);
intervalAngle += interval.width;
}
const outerBoundary = new THREE.Mesh(
new THREE.TorusGeometry(4.64, 0.015, 3, 96),
standardMaterial(0x59689b, {
roughness: 0.75,
metalness: 0.08
})
);
outerBoundary.position.z = 0.05;
diagram.add(outerBoundary);
function addCallout(anchor, position, title, subtitle, accent) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(...anchor),
new THREE.Vector3(...position)
]);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x557987,
transparent: true,
opacity: 0.6
})
);
diagram.add(line);
const label = createTextSprite({
title,
subtitle,
accent,
height: 0.66
});
label.position.set(...position);
diagram.add(label);
}
addCallout(
[-1.02, 0.00, 0.12],
[-1.78, 0.00, 0.28],
"DAY",
"24-hour forcing",
"#58e2d2"
);
addCallout(
[-0.89, 1.37, 0.12],
[-2.00, 1.62, 0.28],
"SEASON",
"annual window",
"#58e2d2"
);
addCallout(
[-1.20, -1.98, 0.12],
[-2.24, -1.90, 0.28],
"DECADE",
"slow memory",
"#58e2d2"
);
addCallout(
[4.61, 0.00, 0.12],
[5.03, 0.00, 0.28],
"GEOLOGICAL",
"deep-time regimes",
"#a295f3"
);
// Low-poly reference Earth at the center.
const earth = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 1),
standardMaterial(0x3d9fa9, {
emissive: 0x164f5a,
emissiveIntensity: 0.22,
roughness: 0.7
})
);
earth.position.z = 0.02;
diagram.add(earth);
const earthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(earth.geometry, 18),
new THREE.LineBasicMaterial({
color: 0xa7fff2,
transparent: true,
opacity: 0.28
})
);
earthEdges.position.copy(earth.position);
diagram.add(earthEdges);
const earthLabel = createTextSprite({
title: "EARTH",
subtitle: "reference state",
accent: "#58e2d2",
height: 0.43
});
earthLabel.position.set(0, -0.68, 0.32);
diagram.add(earthLabel);
// Direct camera controls: no external control modules are used.
let yaw = 0.035;
let pitch = -0.075;
let distance = 13.4;
let userAdjusted = false;
let dragging = false;
let previousX = 0;
let previousY = 0;
function baseDistance() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.65) return 19.5;
if (aspect < 0.95) return 17.5;
if (aspect < 1.35) return 15.2;
return 13.4;
}
function updateCamera() {
const cosPitch = Math.cos(pitch);
camera.position.set(
Math.sin(yaw) * cosPitch * distance,
Math.sin(pitch) * distance,
Math.cos(yaw) * cosPitch * distance
);
camera.lookAt(0, 0, 0);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
const minimum = baseDistance();
distance = userAdjusted
? Math.max(distance, minimum)
: minimum;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
userAdjusted = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
yaw -= dx * 0.0045;
pitch += dy * 0.0045;
pitch = THREE.MathUtils.clamp(pitch, -0.46, 0.46);
yaw = THREE.MathUtils.clamp(yaw, -0.72, 0.72);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event?.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
userAdjusted = true;
const minimum = baseDistance() * 0.92;
const maximum = baseDistance() * 1.45;
distance *= Math.exp(event.deltaY * 0.001);
distance = THREE.MathUtils.clamp(distance, minimum, maximum);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
userAdjusted = false;
yaw = 0.035;
pitch = -0.075;
distance = baseDistance();
updateCamera();
});
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") yaw += step;
else if (event.key === "ArrowRight") yaw -= step;
else if (event.key === "ArrowUp") pitch += step;
else if (event.key === "ArrowDown") pitch -= step;
else if (event.key === "+" || event.key === "=") distance -= 0.6;
else if (event.key === "-") distance += 0.6;
else if (event.key.toLowerCase() === "r") {
userAdjusted = false;
yaw = 0.035;
pitch = -0.075;
distance = baseDistance();
} else {
return;
}
event.preventDefault();
userAdjusted = true;
pitch = THREE.MathUtils.clamp(pitch, -0.46, 0.46);
yaw = THREE.MathUtils.clamp(yaw, -0.72, 0.72);
distance = THREE.MathUtils.clamp(
distance,
baseDistance() * 0.92,
baseDistance() * 1.45
);
updateCamera();
});
window.addEventListener("resize", resize);
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (!reduceMotion) {
for (const item of pulseMarkers) {
const angle = item.phase + elapsed * item.speed;
item.marker.position.x = Math.cos(angle) * item.radius;
item.marker.position.y = Math.sin(angle) * item.radius;
item.marker.rotation.z = elapsed * 0.7;
}
}
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```