Prompt specification
Build or customize the Three.js 3D scene "Rotating platform with radial masses" 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: Rotating platform with radial masses
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rotating-platform-with-radial-masses-x1361
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: rotating platform with radial masses. Build a turntable with two sliding masses and a rotation axis; show the calculated moment of inertia from their positions under a simple point-mass model. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (rotating-platform-with-radial-masses-x1361):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Radial Mass Turntable</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: rgba(10, 22, 36, 0.86);
--panel-edge: rgba(157, 194, 220, 0.16);
--text: #edf6fb;
--muted: #8fa9bb;
--cyan: #52d7c8;
--orange: #ff9b62;
--gold: #f2ca78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 43% 34%, #172c40 0%, #091624 43%, #050c15 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 43% 42%, transparent 38%, rgba(3, 8, 15, 0.28) 100%);
z-index: 1;
}
header {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
margin-bottom: 10px;
}
h1 {
margin: 0;
font-size: clamp(34px, 4.2vw, 62px);
line-height: 0.96;
letter-spacing: -0.055em;
font-weight: 780;
text-wrap: balance;
}
header p {
margin: 17px 0 0;
max-width: 330px;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.panel {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
width: 326px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 18px;
border: 1px solid var(--panel-edge);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.34),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #31485d transparent;
}
.panel-head {
display: flex;
justify-content: space-between;
align-items: center;
color: #b6c9d8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
align-items: end;
margin-top: 17px;
padding-bottom: 14px;
border-bottom: 1px solid var(--panel-edge);
}
.metric-label {
grid-column: 1 / -1;
color: var(--muted);
font-size: 12px;
margin-bottom: 3px;
}
.metric strong {
font-size: 40px;
line-height: 1;
letter-spacing: -0.055em;
font-variant-numeric: tabular-nums;
}
.metric em {
color: var(--muted);
font-style: normal;
font-size: 12px;
padding-bottom: 4px;
}
.equation {
min-height: 38px;
padding: 12px 0 9px;
color: #c9d8e4;
font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.contribution {
margin: 4px 0 10px;
}
.contribution-row {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: #b9cad6;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.bar {
height: 4px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.07);
}
.bar span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 160ms ease;
}
.bar.one span {
background: var(--cyan);
box-shadow: 0 0 12px rgba(82, 215, 200, 0.4);
}
.bar.two span {
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 155, 98, 0.4);
}
.control-section {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--panel-edge);
}
.section-title {
margin-bottom: 12px;
color: #819caf;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
}
.control {
margin: 0 0 12px;
}
.control label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 7px;
color: #c7d6e1;
font-size: 12px;
}
.control label span {
display: inline-flex;
align-items: center;
gap: 8px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 2px;
display: inline-block;
}
.dot.cyan {
background: var(--cyan);
}
.dot.orange {
background: var(--orange);
}
output {
color: #eef8fc;
font-variant-numeric: tabular-nums;
font-size: 11px;
}
input[type="range"] {
--fill: 50%;
appearance: none;
width: 100%;
height: 4px;
margin: 4px 0;
border-radius: 10px;
outline: none;
background:
linear-gradient(90deg, #5f7d92 var(--fill), rgba(255,255,255,.09) var(--fill));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
border: 3px solid #102233;
border-radius: 50%;
background: #e9f8ff;
box-shadow: 0 0 0 1px rgba(255,255,255,.25);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #102233;
border-radius: 50%;
background: #e9f8ff;
box-shadow: 0 0 0 1px rgba(255,255,255,.25);
}
#speed {
--fill: 30%;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
button {
min-height: 38px;
border: 1px solid var(--panel-edge);
border-radius: 10px;
color: #dcebf4;
background: rgba(255, 255, 255, 0.045);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 140ms ease, transform 140ms ease, border-color 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(157, 194, 220, 0.3);
}
button:active {
transform: translateY(1px);
}
button.primary {
color: #09201f;
background: var(--cyan);
border-color: var(--cyan);
}
button.primary:hover {
background: #6ce5d8;
}
.note {
margin: 13px 2px 0;
color: #718a9d;
font-size: 10px;
line-height: 1.5;
}
.world-label {
position: fixed;
z-index: 4;
left: 0;
top: 0;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 100ms linear;
white-space: nowrap;
}
.mass-label {
padding: 7px 9px;
border: 1px solid rgba(255,255,255,.14);
border-radius: 8px;
color: #f2fbff;
background: rgba(6, 15, 26, 0.82);
box-shadow: 0 8px 24px rgba(0,0,0,.25);
font-size: 10px;
font-weight: 750;
letter-spacing: .03em;
backdrop-filter: blur(8px);
}
.mass-label::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 2px;
background: var(--dot-color);
}
.axis-label {
padding: 5px 8px;
border-radius: 20px;
color: #f8dda1;
background: rgba(8, 18, 28, 0.76);
border: 1px solid rgba(242, 202, 120, 0.24);
font-size: 9px;
font-weight: 750;
letter-spacing: .11em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 4;
left: 34px;
bottom: 25px;
display: flex;
align-items: center;
gap: 10px;
color: #71899a;
font-size: 10px;
letter-spacing: .06em;
pointer-events: none;
}
.hint svg {
opacity: .65;
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
}
header p {
display: none;
}
h1 {
font-size: 32px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
border-radius: 16px;
padding: 14px;
}
.metric strong {
font-size: 33px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="vignette"></div>
<header>
<div class="eyebrow">ROTATIONAL INERTIA LAB</div>
<h1>Radial Mass<br />Turntable</h1>
<p>
Slide two point masses away from the rotation axis. Their squared radial
distances determine the combined moment of inertia.
</p>
</header>
<aside class="panel">
<div class="panel-head">
<span>POINT-MASS MODEL</span>
<span class="live">LIVE</span>
</div>
<div class="metric" aria-live="polite">
<span class="metric-label">Total moment of inertia</span>
<strong id="inertiaValue">0.00</strong>
<em>kg·m²</em>
</div>
<div class="equation" id="equation"></div>
<div class="contribution">
<div class="contribution-row">
<span>Mass 1 contribution</span>
<span id="contribution1"></span>
</div>
<div class="bar one"><span id="bar1"></span></div>
</div>
<div class="contribution">
<div class="contribution-row">
<span>Mass 2 contribution</span>
<span id="contribution2"></span>
</div>
<div class="bar two"><span id="bar2"></span></div>
</div>
<section class="control-section">
<div class="section-title">MASS 1</div>
<div class="control">
<label for="m1">
<span><i class="dot cyan"></i>Point mass</span>
<output id="m1Value"></output>
</label>
<input id="m1" type="range" min="0.5" max="5" step="0.1" value="2" />
</div>
<div class="control">
<label for="r1">
<span><i class="dot cyan"></i>Radius from axis</span>
<output id="r1Value"></output>
</label>
<input id="r1" type="range" min="0.4" max="2.7" step="0.05" value="1.45" />
</div>
</section>
<section class="control-section">
<div class="section-title">MASS 2</div>
<div class="control">
<label for="m2">
<span><i class="dot orange"></i>Point mass</span>
<output id="m2Value"></output>
</label>
<input id="m2" type="range" min="0.5" max="5" step="0.1" value="2.5" />
</div>
<div class="control">
<label for="r2">
<span><i class="dot orange"></i>Radius from axis</span>
<output id="r2Value"></output>
</label>
<input id="r2" type="range" min="0.4" max="2.7" step="0.05" value="2.15" />
</div>
</section>
<section class="control-section">
<div class="section-title">MOTION</div>
<div class="control">
<label for="speed">
<span>Angular speed</span>
<output id="speedValue">0.35 rad/s</output>
</label>
<input id="speed" type="range" min="0" max="1.2" step="0.05" value="0.35" />
</div>
</section>
<div class="buttons">
<button id="toggleRotation" class="primary" type="button">Pause rotation</button>
<button id="resetMasses" type="button">Reset masses</button>
<button id="resetCamera" type="button">Reset camera</button>
<button id="resetAll" type="button">Reset all</button>
</div>
<p class="note">
I = m₁r₁² + m₂r₂². The turntable structure and axle are excluded;
only the two sliding point masses are included.
</p>
</aside>
<div id="label1" class="world-label mass-label"></div>
<div id="label2" class="world-label mass-label"></div>
<div id="axisLabel" class="world-label axis-label">Rotation axis</div>
<div class="hint">
<svg width="26" height="16" viewBox="0 0 26 16" fill="none" aria-hidden="true">
<path d="M3 8h20M3 8l4-4M3 8l4 4M23 8l-4-4M23 8l-4 4"
stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
DRAG TO ORBIT · 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 canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x081421, 13, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.72,
phi: 1.03,
radius: 10.7,
target: new THREE.Vector3(0, 0.55, 0)
};
const spherical = new THREE.Spherical();
function updateCamera() {
spherical.set(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xcce7ff, 0x08111c, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff0d2, 3.3);
keyLight.position.set(5, 8, 4);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x54dacd, 18, 11, 2);
cyanLight.position.set(-4, 2.8, 3);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xff9360, 13, 10, 2);
orangeLight.position.set(4, 1.8, -3);
scene.add(orangeLight);
// Ground
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({
color: 0x07131f,
roughness: 0.96,
metalness: 0.04
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x44647c, 0x20374b);
grid.position.y = -0.382;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
const groundHalo = new THREE.Mesh(
new THREE.CylinderGeometry(4.35, 4.35, 0.045, 48),
new THREE.MeshStandardMaterial({
color: 0x102537,
roughness: 0.8,
metalness: 0.2
})
);
groundHalo.position.y = -0.355;
groundHalo.receiveShadow = true;
scene.add(groundHalo);
const turntable = new THREE.Group();
turntable.rotation.y = -0.48;
scene.add(turntable);
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x26384b,
roughness: 0.58,
metalness: 0.52,
flatShading: true
});
const topMetal = new THREE.MeshStandardMaterial({
color: 0x3a5064,
roughness: 0.5,
metalness: 0.48,
flatShading: true
});
const rimMetal = new THREE.MeshStandardMaterial({
color: 0xb59154,
roughness: 0.36,
metalness: 0.72,
flatShading: true
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x182a3a,
roughness: 0.42,
metalness: 0.72,
flatShading: true
});
// Main platform
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(3.25, 3.25, 0.32, 24),
darkMetal
);
platform.castShadow = true;
platform.receiveShadow = true;
turntable.add(platform);
const topPlate = new THREE.Mesh(
new THREE.CylinderGeometry(3.1, 3.1, 0.08, 24),
topMetal
);
topPlate.position.y = 0.185;
topPlate.receiveShadow = true;
turntable.add(topPlate);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(3.19, 0.075, 8, 48),
rimMetal
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.17;
rim.castShadow = true;
turntable.add(rim);
// Radial ruler rings
[0.5, 1, 1.5, 2, 2.5].forEach((radius) => {
const points = [];
for (let i = 0; i < 72; i++) {
const a = (i / 72) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(a) * radius,
0.232,
Math.sin(a) * radius
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0x8ba7b9,
transparent: true,
opacity: 0.13
});
turntable.add(new THREE.LineLoop(geometry, material));
});
// Outer tick marks
const tickGeometry = new THREE.BoxGeometry(0.075, 0.055, 0.34);
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
const tick = new THREE.Mesh(tickGeometry, rimMetal);
tick.position.set(Math.cos(a) * 2.99, 0.255, Math.sin(a) * 2.99);
tick.rotation.y = Math.PI / 2 - a;
turntable.add(tick);
}
// Visible pointer attached to the rotating platform
const pointer = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.3, 3),
new THREE.MeshStandardMaterial({
color: 0xf2ca78,
emissive: 0x5c3a0d,
emissiveIntensity: 0.4,
roughness: 0.45,
metalness: 0.45,
flatShading: true
})
);
pointer.position.set(2.8, 0.36, 0);
pointer.rotation.z = -Math.PI / 2;
pointer.castShadow = true;
turntable.add(pointer);
// Static central axis and bearing
const axisMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c56c,
emissive: 0x6f4411,
emissiveIntensity: 0.35,
roughness: 0.3,
metalness: 0.7,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 2.72, 10),
axisMaterial
);
shaft.position.y = 0.96;
shaft.castShadow = true;
scene.add(shaft);
const bearing = new THREE.Mesh(
new THREE.CylinderGeometry(0.26, 0.31, 0.2, 12),
darkMetal
);
bearing.position.y = 0.27;
bearing.castShadow = true;
scene.add(bearing);
const axisCap = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.3, 8),
axisMaterial
);
axisCap.position.y = 2.47;
axisCap.castShadow = true;
scene.add(axisCap);
const axisHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.026, 6, 40),
axisMaterial
);
axisHalo.rotation.x = Math.PI / 2;
axisHalo.position.y = 0.34;
scene.add(axisHalo);
const axisAnchor = new THREE.Object3D();
axisAnchor.position.set(0, 2.76, 0);
scene.add(axisAnchor);
// Two opposite radial rails
const angle1 = 0.55;
const angle2 = angle1 + Math.PI;
const railStart = 0.26;
const railLength = 2.62;
function createRail(angle) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.075, railLength),
railMaterial
);
const midRadius = railStart + railLength / 2;
rail.position.set(
Math.cos(angle) * midRadius,
0.285,
Math.sin(angle) * midRadius
);
rail.rotation.y = Math.PI / 2 - angle;
rail.castShadow = true;
rail.receiveShadow = true;
turntable.add(rail);
const edge = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.025, railLength),
rimMetal
);
edge.position.set(
Math.cos(angle) * midRadius + Math.sin(angle) * 0.052,
0.333,
Math.sin(angle) * midRadius - Math.cos(angle) * 0.052
);
edge.rotation.y = rail.rotation.y;
turntable.add(edge);
}
createRail(angle1);
createRail(angle2);
const massColors = [0x52d7c8, 0xff9b62];
const massAngles = [angle1, angle2];
const massGroups = [];
const massBodies = [];
const massAnchors = [];
const radiusLines = [];
function createMass(color) {
const group = new THREE.Group();
const carriage = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.14, 0.5),
new THREE.MeshStandardMaterial({
color: 0x172635,
roughness: 0.38,
metalness: 0.68,
flatShading: true
})
);
carriage.position.y = 0.34;
carriage.castShadow = true;
group.add(carriage);
const bodyGeometry = new THREE.DodecahedronGeometry(0.43, 0);
const body = new THREE.Mesh(
bodyGeometry,
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.36,
metalness: 0.22,
flatShading: true
})
);
body.position.y = 0.76;
body.castShadow = true;
body.receiveShadow = true;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry, 15),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.3
})
);
body.add(edges);
group.add(body);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.27, 0.038, 5, 14),
rimMetal
);
collar.position.y = 0.42;
collar.rotation.x = Math.PI / 2;
collar.castShadow = true;
group.add(collar);
const anchor = new THREE.Object3D();
anchor.position.set(0, 1.36, 0);
group.add(anchor);
turntable.add(group);
return { group, body, anchor };
}
for (let i = 0; i < 2; i++) {
const mass = createMass(massColors[i]);
massGroups.push(mass.group);
massBodies.push(mass.body);
massAnchors.push(mass.anchor);
const line = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 1, 6),
new THREE.MeshBasicMaterial({
color: massColors[i],
transparent: true,
opacity: 0.72
})
);
turntable.add(line);
radiusLines.push(line);
}
const yAxis = new THREE.Vector3(0, 1, 0);
function placeRadialLine(mesh, radius, angle) {
const start = new THREE.Vector3(0, 0.305, 0);
const end = new THREE.Vector3(
Math.cos(angle) * radius,
0.305,
Math.sin(angle) * radius
);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
}
// UI state
const state = {
m1: 2,
r1: 1.45,
m2: 2.5,
r2: 2.15,
speed: 0.35,
playing: true
};
const defaults = { ...state };
const ui = {
m1: document.getElementById("m1"),
r1: document.getElementById("r1"),
m2: document.getElementById("m2"),
r2: document.getElementById("r2"),
speed: document.getElementById("speed"),
m1Value: document.getElementById("m1Value"),
r1Value: document.getElementById("r1Value"),
m2Value: document.getElementById("m2Value"),
r2Value: document.getElementById("r2Value"),
speedValue: document.getElementById("speedValue"),
inertiaValue: document.getElementById("inertiaValue"),
equation: document.getElementById("equation"),
contribution1: document.getElementById("contribution1"),
contribution2: document.getElementById("contribution2"),
bar1: document.getElementById("bar1"),
bar2: document.getElementById("bar2"),
label1: document.getElementById("label1"),
label2: document.getElementById("label2"),
toggle: document.getElementById("toggleRotation")
};
ui.label1.style.setProperty("--dot-color", "#52d7c8");
ui.label2.style.setProperty("--dot-color", "#ff9b62");
function setRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateModel() {
state.m1 = Number(ui.m1.value);
state.r1 = Number(ui.r1.value);
state.m2 = Number(ui.m2.value);
state.r2 = Number(ui.r2.value);
state.speed = Number(ui.speed.value);
const i1 = state.m1 * state.r1 * state.r1;
const i2 = state.m2 * state.r2 * state.r2;
const total = i1 + i2;
massGroups[0].position.set(
Math.cos(massAngles[0]) * state.r1,
0,
Math.sin(massAngles[0]) * state.r1
);
massGroups[1].position.set(
Math.cos(massAngles[1]) * state.r2,
0,
Math.sin(massAngles[1]) * state.r2
);
const massScale1 = 0.76 + Math.cbrt(state.m1) * 0.19;
const massScale2 = 0.76 + Math.cbrt(state.m2) * 0.19;
massBodies[0].scale.setScalar(massScale1);
massBodies[1].scale.setScalar(massScale2);
placeRadialLine(radiusLines[0], state.r1, massAngles[0]);
placeRadialLine(radiusLines[1], state.r2, massAngles[1]);
ui.m1Value.textContent = `${state.m1.toFixed(1)} kg`;
ui.r1Value.textContent = `${state.r1.toFixed(2)} m`;
ui.m2Value.textContent = `${state.m2.toFixed(1)} kg`;
ui.r2Value.textContent = `${state.r2.toFixed(2)} m`;
ui.speedValue.textContent = `${state.speed.toFixed(2)} rad/s`;
ui.inertiaValue.textContent = total.toFixed(2);
ui.equation.textContent =
`I = ${state.m1.toFixed(1)}(${state.r1.toFixed(2)})² + ` +
`${state.m2.toFixed(1)}(${state.r2.toFixed(2)})²`;
ui.contribution1.textContent = `${i1.toFixed(2)} kg·m²`;
ui.contribution2.textContent = `${i2.toFixed(2)} kg·m²`;
ui.bar1.style.width = `${total > 0 ? (i1 / total) * 100 : 0}%`;
ui.bar2.style.width = `${total > 0 ? (i2 / total) * 100 : 0}%`;
ui.label1.textContent = `M1 · ${i1.toFixed(2)} kg·m²`;
ui.label2.textContent = `M2 · ${i2.toFixed(2)} kg·m²`;
[ui.m1, ui.r1, ui.m2, ui.r2, ui.speed].forEach(setRangeFill);
}
[ui.m1, ui.r1, ui.m2, ui.r2].forEach((input) => {
input.addEventListener("input", updateModel);
});
ui.speed.addEventListener("input", updateModel);
ui.toggle.addEventListener("click", () => {
state.playing = !state.playing;
ui.toggle.textContent = state.playing ? "Pause rotation" : "Start rotation";
});
function resetMasses() {
ui.m1.value = defaults.m1;
ui.r1.value = defaults.r1;
ui.m2.value = defaults.m2;
ui.r2.value = defaults.r2;
updateModel();
}
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 1.03;
cameraState.radius = 10.7;
cameraState.target.set(0, 0.55, 0);
updateCamera();
}
document.getElementById("resetMasses").addEventListener("click", resetMasses);
document.getElementById("resetCamera").addEventListener("click", resetCamera);
document.getElementById("resetAll").addEventListener("click", () => {
resetMasses();
resetCamera();
state.speed = defaults.speed;
ui.speed.value = defaults.speed;
state.playing = true;
ui.toggle.textContent = "Pause rotation";
updateModel();
});
// Direct camera controls: no external controls module.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.32,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
6.2,
17
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// Project HTML annotations from their 3D anchors.
const projected = new THREE.Vector3();
function placeLabel(element, anchor) {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
updateModel();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
turntable.rotation.y += delta * state.speed;
}
// Subtle light motion reinforces the low-poly mechanical mood.
cyanLight.position.x = -4 + Math.sin(turntable.rotation.y * 0.4) * 0.6;
orangeLight.position.z = -3 + Math.cos(turntable.rotation.y * 0.4) * 0.6;
scene.updateMatrixWorld();
placeLabel(ui.label1, massAnchors[0]);
placeLabel(ui.label2, massAnchors[1]);
placeLabel(document.getElementById("axisLabel"), axisAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```