Prompt specification
Build or customize the Three.js 3D scene "Spinning Ball With Separate Axis Arrow" 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: Spinning Ball With Separate Axis Arrow
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/spinning-ball-with-separate-axis-arrow-x3657
Scene Description Prompt:
A low-poly spinning ball with separate arrows for its rotation axis and forward velocity. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (spinning-ball-with-separate-axis-arrow-x3657):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spin & Motion — Three.js</title>
<style>
:root {
color-scheme: dark;
--axis: #65b8ff;
--velocity: #ffae57;
--panel: rgba(9, 18, 32, 0.76);
--border: rgba(159, 205, 255, 0.16);
--muted: #8ba2ba;
--text: #eef7ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07101c;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 18px;
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
#info {
top: 22px;
left: 22px;
width: 330px;
padding: 22px;
pointer-events: none;
}
.eyebrow {
color: var(--axis);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: 34px;
font-weight: 750;
letter-spacing: -0.045em;
}
#info p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 18px;
}
.stat {
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.stat span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
}
.stat b {
font-size: 15px;
font-variant-numeric: tabular-nums;
}
#controls {
top: 22px;
right: 22px;
width: 290px;
padding: 18px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
color: #c9d9e9;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 18px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 10px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.2);
}
button:active {
transform: translateY(1px);
}
#playButton {
border-color: rgba(101, 184, 255, 0.35);
background: rgba(101, 184, 255, 0.12);
}
.control {
margin-top: 16px;
}
.control-header {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 8px;
color: #a9bdd0;
font-size: 11px;
}
.control-header output {
color: var(--text);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 99px;
background: #26384d;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #dff3ff;
border-radius: 50%;
background: var(--axis);
box-shadow: 0 0 0 4px rgba(101, 184, 255, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #dff3ff;
border-radius: 50%;
background: var(--axis);
box-shadow: 0 0 0 4px rgba(101, 184, 255, 0.12);
}
#spinSpeed {
accent-color: var(--velocity);
}
.divider {
height: 1px;
margin: 19px 0 14px;
background: rgba(255, 255, 255, 0.08);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
padding: 7px 0;
color: #b9cada;
font-size: 12px;
cursor: pointer;
}
.toggle span {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 18px;
height: 3px;
border-radius: 99px;
}
.swatch.axis {
background: var(--axis);
box-shadow: 0 0 12px rgba(101, 184, 255, 0.65);
}
.swatch.velocity {
background: var(--velocity);
box-shadow: 0 0 12px rgba(255, 174, 87, 0.6);
}
.toggle input {
width: 17px;
height: 17px;
accent-color: var(--axis);
cursor: pointer;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.vector-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid;
border-radius: 9px;
background: rgba(6, 14, 25, 0.82);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
white-space: nowrap;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 100ms linear;
}
.vector-label b {
font-size: 12px;
font-style: italic;
}
#axisLabel {
border-color: rgba(101, 184, 255, 0.42);
color: var(--axis);
}
#velocityLabel {
border-color: rgba(255, 174, 87, 0.42);
color: var(--velocity);
}
#hint {
position: fixed;
z-index: 10;
bottom: 20px;
left: 50%;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 99px;
background: rgba(7, 15, 27, 0.6);
color: #7f96ad;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
@media (max-width: 720px) {
#info {
top: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 16px;
}
h1 {
margin-bottom: 0;
font-size: 25px;
}
#info p,
.stats {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
width: calc(100% - 24px);
padding: 14px;
}
.button-row {
margin-bottom: 10px;
}
.control {
margin-top: 11px;
}
.divider {
margin: 12px 0 8px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels">
<div id="axisLabel" class="vector-label">
ROTATION AXIS <b>ω</b>
</div>
<div id="velocityLabel" class="vector-label">
FORWARD VELOCITY <b>v</b>
</div>
</div>
<section id="info" class="panel">
<div class="eyebrow">Kinematics Study / 01</div>
<h1>Spin & Motion</h1>
<p>
A faceted body translates along a circular path while rotating around
its own tilted axis. The blue and orange vectors remain independent.
</p>
<div class="stats">
<div class="stat">
<span>LINEAR SPEED</span>
<b id="speedStat">4.2 m/s</b>
</div>
<div class="stat">
<span>ANGULAR SPEED</span>
<b id="spinStat">2.4 rad/s</b>
</div>
</div>
</section>
<section id="controls" class="panel">
<div class="panel-title">
<span>Simulation</span>
<button id="viewButton" title="Reset camera">Reset view</button>
</div>
<div class="button-row">
<button id="playButton" aria-pressed="true">Pause</button>
<button id="resetButton">Reset motion</button>
</div>
<div class="control">
<div class="control-header">
<span>Forward speed</span>
<output id="speedOutput">4.2 m/s</output>
</div>
<input id="speed" type="range" min="0.5" max="8" step="0.1" value="4.2" />
</div>
<div class="control">
<div class="control-header">
<span>Spin rate</span>
<output id="spinOutput">2.4 rad/s</output>
</div>
<input id="spinSpeed" type="range" min="0" max="8" step="0.1" value="2.4" />
</div>
<div class="divider"></div>
<label class="toggle">
<span><i class="swatch axis"></i>Rotation axis</span>
<input id="axisToggle" type="checkbox" checked />
</label>
<label class="toggle">
<span><i class="swatch velocity"></i>Forward velocity</span>
<input id="velocityToggle" type="checkbox" checked />
</label>
</section>
<div id="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
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.12;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101c);
scene.fog = new THREE.FogExp2(0x07101c, 0.026);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const TAU = Math.PI * 2;
const PATH_RADIUS = 5.5;
const BALL_HEIGHT = 1.55;
const LOCAL_AXIS = new THREE.Vector3(0, 1, 0);
const AXIS_WORLD = new THREE.Vector3(0.24, 1, 0.07).normalize();
// Camera state and a small custom orbit/pan/zoom implementation.
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const orbit = {
theta: 0.76,
phi: 1.04,
radius: 15.5,
targetTheta: 0.76,
targetPhi: 1.04,
targetRadius: 15.5
};
function updateCamera(dt, instant = false) {
const damping = instant ? 1 : 1 - Math.exp(-10 * dt);
orbit.theta += (orbit.targetTheta - orbit.theta) * damping;
orbit.phi += (orbit.targetPhi - orbit.phi) * damping;
orbit.radius += (orbit.targetRadius - orbit.radius) * damping;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera(0, true);
const dragState = {
active: false,
pointerId: null,
x: 0,
y: 0,
pan: false
};
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragState.active = true;
dragState.pointerId = event.pointerId;
dragState.x = event.clientX;
dragState.y = event.clientY;
dragState.pan = event.shiftKey || event.button === 2;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragState.active || event.pointerId !== dragState.pointerId) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
if (dragState.pan) {
cameraRight.setFromMatrixColumn(camera.matrix, 0).normalize();
cameraUp.setFromMatrixColumn(camera.matrix, 1).normalize();
const panScale = orbit.radius * 0.00125;
cameraTarget.addScaledVector(cameraRight, -dx * panScale);
cameraTarget.addScaledVector(cameraUp, dy * panScale);
} else {
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi - dy * 0.005,
0.2,
Math.PI - 0.2
);
}
});
function stopDragging(event) {
if (!dragState.active) return;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(dragState.pointerId)
) {
renderer.domElement.releasePointerCapture(dragState.pointerId);
}
dragState.active = false;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
7,
29
);
},
{ passive: false }
);
function resetCamera() {
orbit.targetTheta = 0.76;
orbit.targetPhi = 1.04;
orbit.targetRadius = 15.5;
cameraTarget.set(0, 1.05, 0);
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// Lighting.
scene.add(new THREE.HemisphereLight(0xaadfff, 0x101827, 1.55));
const keyLight = new THREE.DirectionalLight(0xe6f8ff, 3.4);
keyLight.position.set(6, 12, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x36c9ff, 32, 22, 2);
cyanLight.position.set(-6, 5, 4);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xff8738, 28, 20, 2);
orangeLight.position.set(7, 4, -5);
scene.add(orangeLight);
// Floor and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x08131f,
roughness: 0.92,
metalness: 0.06
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(50, 50, 0x25475d, 0x10283a);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.58;
scene.add(grid);
// Circular travel path.
const path = new THREE.Mesh(
new THREE.TorusGeometry(PATH_RADIUS, 0.025, 8, 160),
new THREE.MeshBasicMaterial({
color: 0x3fc9ef,
transparent: true,
opacity: 0.35
})
);
path.rotation.x = Math.PI / 2;
path.position.y = 0.035;
scene.add(path);
const markerGeometry = new THREE.SphereGeometry(0.045, 8, 6);
const markerMaterial = new THREE.MeshBasicMaterial({ color: 0x59d7ff });
const markers = new THREE.InstancedMesh(
markerGeometry,
markerMaterial,
40
);
const markerTransform = new THREE.Object3D();
for (let i = 0; i < 40; i++) {
const angle = (i / 40) * TAU;
markerTransform.position.set(
Math.cos(angle) * PATH_RADIUS,
0.055,
Math.sin(angle) * PATH_RADIUS
);
markerTransform.updateMatrix();
markers.setMatrixAt(i, markerTransform.matrix);
}
markers.instanceMatrix.needsUpdate = true;
scene.add(markers);
// Subtle background points.
const starPositions = [];
for (let i = 0; i < 180; i++) {
starPositions.push(
(Math.random() - 0.5) * 34,
1 + Math.random() * 12,
(Math.random() - 0.5) * 34
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0x8dc7e8,
size: 0.035,
transparent: true,
opacity: 0.42,
sizeAttenuation: true
})
);
scene.add(stars);
// Low-poly ball.
const ballGroup = new THREE.Group();
scene.add(ballGroup);
const ballGeometry = new THREE.IcosahedronGeometry(1.35, 2);
const ballMaterial = new THREE.MeshStandardMaterial({
color: 0x35c9eb,
roughness: 0.32,
metalness: 0.24,
flatShading: true
});
const ball = new THREE.Mesh(ballGeometry, ballMaterial);
ball.castShadow = true;
ball.receiveShadow = true;
ballGroup.add(ball);
const ballEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(ballGeometry, 1),
new THREE.LineBasicMaterial({
color: 0xc2f5ff,
transparent: true,
opacity: 0.25
})
);
ballEdges.scale.setScalar(1.003);
ballGroup.add(ballEdges);
const axisRing = new THREE.Mesh(
new THREE.TorusGeometry(1.53, 0.018, 6, 64),
new THREE.MeshBasicMaterial({
color: 0x65b8ff,
transparent: true,
opacity: 0.35
})
);
axisRing.rotation.x = Math.PI / 2;
ballGroup.add(axisRing);
const baseQuaternion = new THREE.Quaternion().setFromUnitVectors(
LOCAL_AXIS,
AXIS_WORLD
);
const spinQuaternion = new THREE.Quaternion();
const spinAxis = LOCAL_AXIS.clone();
// Thick custom arrows pointing along their group's local +Y axis.
function createVectorArrow(color, shaftRadius = 0.045, headRadius = 0.16) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.5,
roughness: 0.3,
metalness: 0.12
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(shaftRadius, shaftRadius, 1, 12),
material
);
const headLength = 0.42;
const head = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, headLength, 18),
material
);
group.add(shaft, head);
group.userData.setLength = (length) => {
const shaftLength = Math.max(0.01, length - headLength);
shaft.scale.y = shaftLength;
shaft.position.y = shaftLength / 2;
head.position.y = shaftLength + headLength / 2;
};
group.userData.setLength(3.8);
return group;
}
const axisArrow = createVectorArrow(0x65b8ff, 0.045, 0.16);
const velocityArrow = createVectorArrow(0xffae57, 0.052, 0.19);
scene.add(axisArrow, velocityArrow);
const ballLight = new THREE.PointLight(0x53d8ff, 9, 8, 2);
scene.add(ballLight);
// Simulation state.
let playing = true;
let orbitAngle = 0.68;
let spinPhase = 0;
let forwardSpeed = 4.2;
let spinRate = 2.4;
const tangent = new THREE.Vector3();
const axisLabelPosition = new THREE.Vector3();
const velocityLabelPosition = new THREE.Vector3();
function updateSimulation() {
ballGroup.position.set(
Math.cos(orbitAngle) * PATH_RADIUS,
BALL_HEIGHT,
Math.sin(orbitAngle) * PATH_RADIUS
);
tangent.set(-Math.sin(orbitAngle), 0, Math.cos(orbitAngle)).normalize();
spinQuaternion.setFromAxisAngle(spinAxis, spinPhase);
ballGroup.quaternion.copy(baseQuaternion).multiply(spinQuaternion);
const axisLength = 3.45 + spinRate * 0.17;
const velocityLength = 3.45 + forwardSpeed * 0.18;
axisArrow.position.copy(ballGroup.position);
axisArrow.quaternion.copy(ballGroup.quaternion);
axisArrow.userData.setLength(axisLength);
velocityArrow.position.copy(ballGroup.position);
velocityArrow.quaternion.setFromUnitVectors(LOCAL_AXIS, tangent);
velocityArrow.userData.setLength(velocityLength);
ballLight.position.copy(ballGroup.position);
ballLight.position.y += 1.8;
axisLabelPosition
.copy(ballGroup.position)
.addScaledVector(AXIS_WORLD, axisLength + 0.48);
velocityLabelPosition
.copy(ballGroup.position)
.addScaledVector(tangent, velocityLength + 0.48);
velocityLabelPosition.y += 0.48;
}
// UI.
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const viewButton = document.getElementById("viewButton");
const speedInput = document.getElementById("speed");
const spinInput = document.getElementById("spinSpeed");
const speedOutput = document.getElementById("speedOutput");
const spinOutput = document.getElementById("spinOutput");
const speedStat = document.getElementById("speedStat");
const spinStat = document.getElementById("spinStat");
const axisToggle = document.getElementById("axisToggle");
const velocityToggle = document.getElementById("velocityToggle");
const axisLabel = document.getElementById("axisLabel");
const velocityLabel = document.getElementById("velocityLabel");
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
playButton.setAttribute("aria-pressed", String(playing));
});
resetButton.addEventListener("click", () => {
orbitAngle = 0.68;
spinPhase = 0;
});
viewButton.addEventListener("click", resetCamera);
speedInput.addEventListener("input", () => {
forwardSpeed = Number(speedInput.value);
speedOutput.textContent = `${forwardSpeed.toFixed(1)} m/s`;
speedStat.textContent = `${forwardSpeed.toFixed(1)} m/s`;
});
spinInput.addEventListener("input", () => {
spinRate = Number(spinInput.value);
spinOutput.textContent = `${spinRate.toFixed(1)} rad/s`;
spinStat.textContent = `${spinRate.toFixed(1)} rad/s`;
});
axisToggle.addEventListener("change", () => {
axisArrow.visible = axisToggle.checked;
});
velocityToggle.addEventListener("change", () => {
velocityArrow.visible = velocityToggle.checked;
});
// Project vector labels into screen space.
const projected = new THREE.Vector3();
const toPoint = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
function updateLabel(element, worldPosition, enabled) {
if (!enabled) {
element.style.opacity = "0";
return;
}
toPoint.copy(worldPosition).sub(camera.position);
camera.getWorldDirection(cameraDirection);
const inFront = toPoint.dot(cameraDirection) > 0;
projected.copy(worldPosition).project(camera);
if (!inFront || projected.z < -1 || projected.z > 1) {
element.style.opacity = "0";
return;
}
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = "1";
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
orbitAngle =
(orbitAngle + (forwardSpeed / PATH_RADIUS) * dt) % TAU;
spinPhase = (spinPhase + spinRate * dt) % TAU;
}
updateSimulation();
updateCamera(dt);
renderer.render(scene, camera);
updateLabel(axisLabel, axisLabelPosition, axisArrow.visible);
updateLabel(
velocityLabel,
velocityLabelPosition,
velocityArrow.visible
);
});
</script>
</body>
</html>
```