Prompt specification
Build or customize the Three.js 3D scene "Arms-in and arms-out spinner" 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: Arms-in and arms-out spinner
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/arms-in-and-arms-out-spinner-x1362
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: arms-in and arms-out spinner. Animate a stylized skater changing arm extension while preserving modeled angular momentum in the torque-free phase; distinguish angular speed from rotational kinetic energy.
Working Three.js Starter (arms-in-and-arms-out-spinner-x1362):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Arms In / Arms Out — Angular Momentum Spinner</title>
<style>
:root {
--ink: #102238;
--panel: rgba(10, 26, 43, 0.86);
--panel-border: rgba(255, 255, 255, 0.13);
--muted: #a9bdcc;
--white: #f6fbff;
--cyan: #43d9d0;
--orange: #ff7959;
--phase: #43d9d0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dceff5;
color: var(--white);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
user-select: none;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(8, 25, 40, 0.18);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
#brand {
top: 18px;
left: 18px;
width: 350px;
padding: 18px 20px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 6px 0 7px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status-row {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-top: 13px;
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
color: #dcecf5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
#metrics {
top: 18px;
right: 18px;
display: grid;
grid-template-columns: repeat(3, minmax(170px, 1fr));
gap: 9px;
width: 630px;
}
.metric {
min-height: 86px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 14px;
background: rgba(10, 26, 43, 0.83);
box-shadow: 0 12px 34px rgba(8, 25, 40, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
pointer-events: none;
}
.metric-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
margin-top: 5px;
font-size: 23px;
font-weight: 780;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.metric-unit {
margin-left: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0;
}
.metric-note {
margin-top: 3px;
color: #8099aa;
font-size: 9px;
}
.metric.fixed .metric-value {
color: var(--cyan);
}
.metric.speed .metric-value {
color: var(--orange);
}
.metric.energy .metric-value {
color: #5ee2d8;
}
.meter {
height: 3px;
margin-top: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
.meter > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 80ms linear;
}
#speedFill {
background: var(--orange);
}
#energyFill {
background: #5ee2d8;
}
#phasePanel {
top: 132px;
left: 18px;
width: 350px;
padding: 17px 19px;
border-left: 4px solid var(--phase);
}
#phaseTitle {
margin: 5px 0 7px;
color: var(--phase);
font-size: 17px;
font-weight: 850;
letter-spacing: -0.02em;
}
#phaseCopy {
margin: 0;
color: #c4d4df;
font-size: 12px;
line-height: 1.55;
}
#controls {
top: 292px;
left: 18px;
width: 350px;
padding: 14px 16px;
}
.control-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
padding: 8px 10px;
background: rgba(255, 255, 255, 0.08);
color: var(--white);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
pointer-events: auto;
transition:
background 140ms ease,
transform 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.15);
transform: translateY(-1px);
}
.camera-hint {
margin-top: 10px;
color: #7f98a9;
font-size: 9px;
line-height: 1.5;
}
#story {
bottom: 18px;
left: 18px;
width: 370px;
padding: 17px 19px;
}
#story h2,
#chartPanel h2 {
margin: 0 0 8px;
font-size: 13px;
letter-spacing: -0.01em;
}
#story p {
margin: 0;
color: #afc2d0;
font-size: 11px;
line-height: 1.55;
}
.equations {
margin-top: 12px;
padding: 10px 12px;
border-radius: 11px;
background: rgba(0, 0, 0, 0.18);
color: #e8f6ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.65;
}
.change-list {
display: grid;
gap: 6px;
margin-top: 11px;
font-size: 10px;
font-weight: 750;
}
.change-list div {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 7px 9px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.055);
}
.pull {
color: #ff9a80;
}
.push {
color: #c9adff;
}
.model-note {
margin-top: 10px !important;
color: #718b9d !important;
font-size: 9px !important;
}
#chartPanel {
right: 18px;
bottom: 18px;
width: 390px;
padding: 15px 17px 13px;
}
#chartPanel h2 {
display: flex;
justify-content: space-between;
gap: 12px;
}
.chart-legend {
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
#chart {
display: block;
width: 100%;
height: 155px;
}
.chart-caption {
margin-top: 6px;
color: #839cac;
font-size: 9px;
line-height: 1.45;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dceff5;
color: #183449;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1100px) {
#metrics {
grid-template-columns: repeat(2, minmax(170px, 1fr));
width: 430px;
}
#chartPanel {
width: 350px;
}
}
@media (max-width: 820px) {
#brand {
top: 12px;
left: 12px;
right: 12px;
width: auto;
}
#metrics {
top: 142px;
left: 12px;
right: 12px;
width: auto;
}
#phasePanel {
top: 330px;
left: 12px;
width: min(350px, calc(100vw - 24px));
}
#controls {
top: auto;
bottom: 12px;
left: 12px;
width: auto;
}
#story,
#chartPanel {
display: none;
}
}
@media (max-width: 520px) {
#brand {
padding: 14px 16px;
}
h1 {
font-size: 20px;
}
#metrics {
grid-template-columns: repeat(2, 1fr);
}
.metric {
min-height: 76px;
padding: 10px 11px;
}
.metric-value {
font-size: 19px;
}
#phasePanel {
top: 330px;
}
#phaseCopy {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="loading">Loading the ice…</div>
<header id="brand" class="panel">
<div class="eyebrow">Angular momentum studio</div>
<h1>Arms In / Arms Out</h1>
<p class="subtitle">
A stylized one-axis skater changes shape while total angular momentum
remains conserved.
</p>
<div class="status-row">
<div id="liveBadge" class="badge">Live · no external torque</div>
<div class="badge">L<sub>z</sub> = constant</div>
</div>
</header>
<section id="metrics" aria-label="Physical measurements">
<div class="metric fixed">
<div class="metric-label">Angular momentum</div>
<div class="metric-value">
<span id="lVal">8.00</span><span class="metric-unit">kg·m²/s</span>
</div>
<div class="metric-note">Conserved: τ<sub>ext</sub> = 0</div>
</div>
<div class="metric speed">
<div class="metric-label">Angular speed</div>
<div class="metric-value">
<span id="omegaVal">2.46</span><span class="metric-unit">rad/s</span>
</div>
<div class="metric-note"><span id="rpmVal">23.5</span> revolutions/min</div>
<div class="meter"><span id="speedFill"></span></div>
</div>
<div class="metric energy">
<div class="metric-label">Rotational kinetic energy</div>
<div class="metric-value">
<span id="energyVal">9.85</span><span class="metric-unit">J</span>
</div>
<div class="metric-note">
Δ vs arms out: <span id="deltaVal">+0.00</span> J
</div>
<div class="meter"><span id="energyFill"></span></div>
</div>
<div class="metric">
<div class="metric-label">Moment of inertia</div>
<div class="metric-value">
<span id="inertiaVal">3.25</span><span class="metric-unit">kg·m²</span>
</div>
<div class="metric-note">Variable arm contribution</div>
</div>
<div class="metric">
<div class="metric-label">Inertia model</div>
<div class="metric-value" style="font-size: 17px">
I = 1.05 + 2.20q²
</div>
<div class="metric-note">q = 0 arms in, q = 1 arms out</div>
</div>
<div class="metric">
<div class="metric-label">Model state</div>
<div class="metric-value" style="font-size: 17px">
1-DOF / vertical axis
</div>
<div class="metric-note">Body + arms treated as one system</div>
</div>
</section>
<section id="phasePanel" class="panel" aria-live="polite">
<div class="eyebrow">Current phase</div>
<div id="phaseTitle">Arms out — torque-free coast</div>
<p id="phaseCopy">
With the shape fixed, angular speed and rotational kinetic energy remain constant.
</p>
</section>
<section id="controls" class="panel">
<div class="control-title">Playback and view</div>
<div class="buttons">
<button id="pauseBtn" type="button">Pause</button>
<button id="rateBtn" type="button">Speed: 1×</button>
<button id="phaseBtn" type="button">Next phase</button>
<button id="restartBtn" type="button">Restart</button>
<button id="cameraBtn" type="button">Reset camera</button>
</div>
<div class="camera-hint">
Drag to orbit · scroll to zoom · Space: pause · C: next phase · R: reset view
</div>
</section>
<section id="story" class="panel">
<h2>Same momentum does not mean same speed or energy</h2>
<p>
The modeled body and arms have zero external torque. Changing arm extension
changes the moment of inertia. At fixed angular momentum, pulling inward
makes the skater rotate faster and raises rotational kinetic energy;
extending lowers both.
</p>
<div class="equations">
L<sub>z</sub> = Iω = constant<br />
ω = L<sub>z</sub> / I<br />
K<sub>rot</sub> = ½Iω² = L<sub>z</sub>² / 2I
</div>
<div class="change-list">
<div><span class="pull">Pull arms in</span><span>I ↓ → ω ↑ → K ↑</span></div>
<div><span class="push">Extend arms out</span><span>I ↑ → ω ↓ → K ↓</span></div>
</div>
<p class="model-note">
During fixed-shape coasts, ω and K are constant. During arm transitions,
internal actuation changes the shape and exchanges work while total angular
momentum remains fixed. This reduced model omits limb deformation and
metabolic losses.
</p>
</section>
<section id="chartPanel" class="panel">
<h2>
<span>Live motion trace</span>
<span class="chart-legend">
<span style="color:#ff7959">● ω</span>
<span style="color:#5ee2d8">● K</span>
</span>
</h2>
<canvas id="chart"></canvas>
<div class="chart-caption">
Separate scales: angular speed is rad/s; rotational kinetic energy is joules.
They are related here, but they are not interchangeable quantities.
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and reduced one-degree-of-freedom model
// -------------------------------------------------------------------------
const TAU = Math.PI * 2;
const I_BODY = 1.05; // kg m²
const I_ARM = 2.20; // kg m² at full arm extension
const L_Z = 8.00; // kg m²/s, conserved for body + arms
const I_ARMS_OUT = I_BODY + I_ARM;
const K_ARMS_OUT = (L_Z * L_Z) / (2 * I_ARMS_OUT);
const OMEGA_MAX = 8.5;
const ENERGY_MAX = 32.0;
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: 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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D scene of a skater changing arm extension"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdceff5);
scene.fog = new THREE.Fog(0xdceff5, 13, 28);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
// Custom orbit camera controls: no addons.
const orbit = {
azimuth: 0.62,
elevation: 0.30,
distance: 7.25,
target: new THREE.Vector3(0, 1.25, 0)
};
function updateCamera() {
const horizontal = Math.cos(orbit.elevation) * orbit.distance;
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.azimuth),
orbit.target.y + Math.sin(orbit.elevation) * orbit.distance,
orbit.target.z + horizontal * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.azimuth = 0.62;
orbit.elevation = 0.30;
orbit.distance = 7.25;
orbit.target.set(0, 1.25, 0);
updateCamera();
}
updateCamera();
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.azimuth -= deltaX * 0.006;
orbit.elevation = THREE.MathUtils.clamp(
orbit.elevation + deltaY * 0.005,
0.10,
1.08
);
updateCamera();
});
function endPointerDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.006,
4.7,
10.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Lighting and stylized environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf1fcff, 0x70889b, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x74dedb, 1.1);
rimLight.position.set(5, 3.5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8b70, 18, 9, 2);
warmLight.position.set(-2.5, 3.5, 2.5);
scene.add(warmLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xb7d5df,
roughness: 0.94
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.19;
ground.receiveShadow = true;
scene.add(ground);
const rinkBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x8dc3d2,
roughness: 0.65,
metalness: 0.05
});
const rinkBase = new THREE.Mesh(
new THREE.CylinderGeometry(5.35, 5.5, 0.18, 96),
rinkBaseMaterial
);
rinkBase.position.y = -0.09;
rinkBase.receiveShadow = true;
scene.add(rinkBase);
const iceMaterial = new THREE.MeshStandardMaterial({
color: 0xdff8ff,
roughness: 0.25,
metalness: 0.06,
transparent: true,
opacity: 0.93
});
const ice = new THREE.Mesh(
new THREE.CircleGeometry(5.22, 96),
iceMaterial
);
ice.rotation.x = -Math.PI / 2;
ice.position.y = 0.005;
ice.receiveShadow = true;
scene.add(ice);
const rinkRingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.45,
metalness: 0.12
});
const rinkRing = new THREE.Mesh(
new THREE.TorusGeometry(5.22, 0.045, 8, 128),
rinkRingMaterial
);
rinkRing.rotation.x = Math.PI / 2;
rinkRing.position.y = 0.025;
rinkRing.castShadow = true;
scene.add(rinkRing);
// Deterministic scratches, so the scene does not flicker between reloads.
let randomSeed = 91827;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const scratchMaterial = new THREE.LineBasicMaterial({
color: 0x7bb8ca,
transparent: true,
opacity: 0.17
});
for (let i = 0; i < 42; i++) {
const angle = random() * TAU;
const radius = Math.sqrt(random()) * 4.7;
const length = 0.25 + random() * 1.15;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.018, z),
new THREE.Vector3(
x + Math.cos(angle + 0.12) * length,
0.018,
z + Math.sin(angle + 0.12) * length
)
]);
scene.add(new THREE.Line(geometry, scratchMaterial));
}
// Low-poly trees in the distance.
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x6d7181,
roughness: 1
});
const treeMaterials = [
new THREE.MeshStandardMaterial({ color: 0x8db9b4, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x789fae, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xa1c6bd, roughness: 1 })
];
for (let i = 0; i < 20; i++) {
const angle = (i / 20) * TAU + random() * 0.12;
const radius = 11.4 + random() * 2.0;
const height = 1.8 + random() * 2.5;
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.12, height * 0.34, 6),
trunkMaterial
);
trunk.position.y = height * 0.17;
tree.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(height * 0.32, height * 0.78, 6),
treeMaterials[i % treeMaterials.length]
);
crown.position.y = height * 0.62;
tree.add(crown);
tree.position.set(
Math.cos(angle) * radius,
-0.18,
Math.sin(angle) * radius
);
tree.rotation.y = random() * TAU;
scene.add(tree);
}
// A graphic spin ring and radial ticks under the skater.
const spinRingMaterial = new THREE.MeshStandardMaterial({
color: 0x43d9d0,
emissive: 0x1a6e72,
emissiveIntensity: 0.3,
roughness: 0.4,
transparent: true,
opacity: 0.72
});
const spinRing = new THREE.Mesh(
new THREE.TorusGeometry(1.72, 0.022, 8, 96),
spinRingMaterial
);
spinRing.rotation.x = Math.PI / 2;
spinRing.position.y = 0.035;
scene.add(spinRing);
const tickMaterial = new THREE.MeshBasicMaterial({
color: 0x43d9d0,
transparent: true,
opacity: 0.35
});
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * TAU;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.012, 0.028),
tickMaterial
);
tick.position.set(
Math.cos(angle) * 1.72,
0.038,
Math.sin(angle) * 1.72
);
tick.rotation.y = -angle;
scene.add(tick);
}
// Small vertical-axis annotation above the skater.
const axisArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 2.62, 0),
0.60,
0x52758a,
0.14,
0.08
);
scene.add(axisArrow);
// -------------------------------------------------------------------------
// Stylized skater
// -------------------------------------------------------------------------
const skater = new THREE.Group();
scene.add(skater);
const spinGroup = new THREE.Group();
skater.add(spinGroup);
const jacketMaterial = new THREE.MeshStandardMaterial({
color: 0xff7154,
roughness: 0.64
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x43d9d0,
roughness: 0.48
});
const pantsMaterial = new THREE.MeshStandardMaterial({
color: 0x172a40,
roughness: 0.8
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xf2bf9e,
roughness: 0.72
});
const helmetMaterial = new THREE.MeshStandardMaterial({
color: 0x20394d,
roughness: 0.44
});
const gloveMaterial = new THREE.MeshStandardMaterial({
color: 0x14283c,
roughness: 0.86
});
const bootMaterial = new THREE.MeshStandardMaterial({
color: 0x172335,
roughness: 0.7
});
const bladeMaterial = new THREE.MeshStandardMaterial({
color: 0xdce9ee,
metalness: 0.88,
roughness: 0.22
});
const UP = new THREE.Vector3(0, 1, 0);
function makeMesh(parent, geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLimb(parent, radius, material) {
return makeMesh(
parent,
new THREE.CylinderGeometry(radius, radius, 1, 10),
material
);
}
function placeLimb(mesh, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.multiplyScalar(1 / length));
mesh.scale.set(1, length, 1);
}
// Torso.
const torso = makeMesh(
spinGroup,
new THREE.CylinderGeometry(0.34, 0.42, 0.92, 12),
jacketMaterial,
new THREE.Vector3(0, 1.50, 0)
);
torso.scale.z = 0.72;
const belt = makeMesh(
spinGroup,
new THREE.CylinderGeometry(0.405, 0.415, 0.105, 12),
pantsMaterial,
new THREE.Vector3(0, 1.115, 0)
);
belt.scale.z = 0.72;
const zipper = makeMesh(
spinGroup,
new THREE.BoxGeometry(0.025, 0.66, 0.018),
trimMaterial,
new THREE.Vector3(0, 1.56, 0.302)
);
const collar = makeMesh(
spinGroup,
new THREE.TorusGeometry(0.17, 0.045, 8, 28),
trimMaterial,
new THREE.Vector3(0, 1.995, 0)
);
collar.rotation.x = Math.PI / 2;
const neck = makeMesh(
spinGroup,
new THREE.CylinderGeometry(0.105, 0.115, 0.17, 10),
skinMaterial,
new THREE.Vector3(0, 2.025, 0)
);
const head = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.25, 20, 16),
skinMaterial,
new THREE.Vector3(0, 2.21, 0)
);
head.scale.set(0.92, 1.08, 0.94);
const helmet = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.29, 20, 14),
helmetMaterial,
new THREE.Vector3(0, 2.31, -0.015)
);
helmet.scale.set(1, 0.70, 1);
const goggles = makeMesh(
spinGroup,
new THREE.BoxGeometry(0.43, 0.105, 0.10),
trimMaterial,
new THREE.Vector3(0, 2.245, 0.218)
);
// Canvas-generated race number, avoiding external image assets.
const bibCanvas = document.createElement("canvas");
bibCanvas.width = 256;
bibCanvas.height = 256;
const bibContext = bibCanvas.getContext("2d");
bibContext.clearRect(0, 0, 256, 256);
bibContext.fillStyle = "#f8fcff";
bibContext.fillRect(28, 28, 200, 200);
bibContext.fillStyle = "#ff7154";
bibContext.beginPath();
bibContext.arc(128, 100, 64, 0, Math.PI * 2);
bibContext.fill();
bibContext.fillStyle = "#102238";
bibContext.font = "900 96px sans-serif";
bibContext.textAlign = "center";
bibContext.textBaseline = "middle";
bibContext.fillText("07", 128, 102);
const bibTexture = new THREE.CanvasTexture(bibCanvas);
bibTexture.colorSpace = THREE.SRGBColorSpace;
bibTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const bib = new THREE.Mesh(
new THREE.PlaneGeometry(0.38, 0.38),
new THREE.MeshBasicMaterial({
map: bibTexture,
transparent: true,
depthWrite: false
})
);
bib.position.set(0, 1.51, 0.316);
spinGroup.add(bib);
// Static skating legs and skates.
const leftHip = new THREE.Vector3(-0.15, 1.07, 0);
const leftKnee = new THREE.Vector3(-0.24, 0.59, 0.12);
const leftAnkle = new THREE.Vector3(-0.31, 0.17, 0.25);
const rightHip = new THREE.Vector3(0.15, 1.07, 0);
const rightKnee = new THREE.Vector3(0.28, 0.61, -0.05);
const rightAnkle = new THREE.Vector3(0.60, 0.17, -0.19);
const leftUpperLeg = makeLimb(spinGroup, 0.12, pantsMaterial);
const leftLowerLeg = makeLimb(spinGroup, 0.10, pantsMaterial);
const rightUpperLeg = makeLimb(spinGroup, 0.12, pantsMaterial);
const rightLowerLeg = makeLimb(spinGroup, 0.10, pantsMaterial);
placeLimb(leftUpperLeg, leftHip, leftKnee);
placeLimb(leftLowerLeg, leftKnee, leftAnkle);
placeLimb(rightUpperLeg, rightHip, rightKnee);
placeLimb(rightLowerLeg, rightKnee, rightAnkle);
makeMesh(
spinGroup,
new THREE.SphereGeometry(0.13, 12, 10),
pantsMaterial,
leftKnee
);
makeMesh(
spinGroup,
new THREE.SphereGeometry(0.13, 12, 10),
pantsMaterial,
rightKnee
);
function addSkate(ankle, zRotation) {
const boot = makeMesh(
spinGroup,
new THREE.BoxGeometry(0.22, 0.18, 0.42),
bootMaterial,
new THREE.Vector3(ankle.x, ankle.y - 0.015, ankle.z)
);
boot.rotation.y = zRotation;
const blade = makeMesh(
spinGroup,
new THREE.BoxGeometry(0.045, 0.025, 0.56),
bladeMaterial,
new THREE.Vector3(ankle.x, 0.055, ankle.z)
);
blade.rotation.y = zRotation;
makeMesh(
spinGroup,
new THREE.BoxGeometry(0.205, 0.05, 0.39),
trimMaterial,
new THREE.Vector3(ankle.x, ankle.y - 0.09, ankle.z)
);
}
addSkate(leftAnkle, -0.15);
addSkate(rightAnkle, 0.18);
// Dynamic arms.
const shoulderLeft = new THREE.Vector3(-0.36, 1.80, 0);
const shoulderRight = new THREE.Vector3(0.36, 1.80, 0);
const leftUpperArm = makeLimb(spinGroup, 0.078, jacketMaterial);
const leftForearm = makeLimb(spinGroup, 0.069, jacketMaterial);
const rightUpperArm = makeLimb(spinGroup, 0.078, jacketMaterial);
const rightForearm = makeLimb(spinGroup, 0.069, jacketMaterial);
const leftShoulder = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.13, 14, 10),
jacketMaterial,
shoulderLeft
);
const rightShoulder = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.13, 14, 10),
jacketMaterial,
shoulderRight
);
const leftElbowJoint = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.092, 12, 10),
jacketMaterial
);
const rightElbowJoint = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.092, 12, 10),
jacketMaterial
);
const leftGlove = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.105, 14, 10),
gloveMaterial
);
const rightGlove = makeMesh(
spinGroup,
new THREE.SphereGeometry(0.105, 14, 10),
gloveMaterial
);
const armsIn = {
leftElbow: new THREE.Vector3(-0.57, 1.53, 0.17),
leftHand: new THREE.Vector3(-0.10, 1.70, 0.47),
rightElbow: new THREE.Vector3(0.57, 1.53, 0.12),
rightHand: new THREE.Vector3(0.13, 1.67, 0.50)
};
const armsOut = {
leftElbow: new THREE.Vector3(-0.96, 1.76, -0.05),
leftHand: new THREE.Vector3(-1.50, 1.58, -0.10),
rightElbow: new THREE.Vector3(0.96, 1.76, -0.05),
rightHand: new THREE.Vector3(1.50, 1.58, -0.10)
};
function mixVector(a, b, t) {
return a.clone().lerp(b, t);
}
function updateArms(q) {
const leftElbow = mixVector(armsIn.leftElbow, armsOut.leftElbow, q);
const leftHand = mixVector(armsIn.leftHand, armsOut.leftHand, q);
const rightElbow = mixVector(armsIn.rightElbow, armsOut.rightElbow, q);
const rightHand = mixVector(armsIn.rightHand, armsOut.rightHand, q);
placeLimb(leftUpperArm, shoulderLeft, leftElbow);
placeLimb(leftForearm, leftElbow, leftHand);
placeLimb(rightUpperArm, shoulderRight, rightElbow);
placeLimb(rightForearm, rightElbow, rightHand);
leftElbowJoint.position.copy(leftElbow);
rightElbowJoint.position.copy(rightElbow);
leftGlove.position.copy(leftHand);
rightGlove.position.copy(rightHand);
}
// -------------------------------------------------------------------------
// Animation phases and physical state
// -------------------------------------------------------------------------
const PHASE_LENGTH = 10.0;
const phaseStarts = [0, 2.4, 3.8, 6.2, 7.6];
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function getPhaseState(time) {
const cycleTime = time % PHASE_LENGTH;
if (cycleTime < 2.4) {
return {
q: 1,
key: "out",
title: "Arms out — torque-free coast",
copy:
"The shape is fixed. Angular momentum, angular speed, and rotational kinetic energy are all constant.",
color: "#43d9d0"
};
}
if (cycleTime < 3.8) {
const t = smoothstep((cycleTime - 2.4) / 1.4);
return {
q: 1 - t,
key: "pull",
title: "Pull arms in — internal work",
copy:
"I decreases while Lz stays fixed, so angular speed rises. The reduced model’s rotational kinetic energy also rises.",
color: "#ff7959"
};
}
if (cycleTime < 6.2) {
return {
q: 0,
key: "in",
title: "Arms in — faster torque-free coast",
copy:
"The smaller inertia produces a faster spin and more stored rotational kinetic energy, despite unchanged angular momentum.",
color: "#63a9ff"
};
}
if (cycleTime < 7.6) {
const t = smoothstep((cycleTime - 6.2) / 1.4);
return {
q: t,
key: "push",
title: "Extend arms — internal energy exchange",
copy:
"I increases while Lz remains fixed. Angular speed and the model’s rotational kinetic energy decrease.",
color: "#bb92ff"
};
}
return {
q: 1,
key: "out",
title: "Arms out — reference coast",
copy:
"The skater returns to the original shape and the original speed and energy.",
color: "#43d9d0"
};
}
let simulationTime = 0;
let paused = false;
let playbackRate = 1;
// -------------------------------------------------------------------------
// UI references and controls
// -------------------------------------------------------------------------
const ui = {
l: document.getElementById("lVal"),
omega: document.getElementById("omegaVal"),
rpm: document.getElementById("rpmVal"),
inertia: document.getElementById("inertiaVal"),
energy: document.getElementById("energyVal"),
delta: document.getElementById("deltaVal"),
speedFill: document.getElementById("speedFill"),
energyFill: document.getElementById("energyFill"),
phasePanel: document.getElementById("phasePanel"),
phaseTitle: document.getElementById("phaseTitle"),
phaseCopy: document.getElementById("phaseCopy"),
liveBadge: document.getElementById("liveBadge"),
pause: document.getElementById("pauseBtn"),
rate: document.getElementById("rateBtn"),
phase: document.getElementById("phaseBtn"),
restart: document.getElementById("restartBtn"),
camera: document.getElementById("cameraBtn"),
chart: document.getElementById("chart")
};
function togglePause() {
paused = !paused;
ui.pause.textContent = paused ? "Resume" : "Pause";
ui.liveBadge.textContent = paused
? "Paused · model held"
: "Live · no external torque";
}
function cycleRate() {
if (playbackRate === 0.5) playbackRate = 1;
else if (playbackRate === 1) playbackRate = 1.5;
else playbackRate = 0.5;
ui.rate.textContent = `Speed: ${playbackRate}×`;
}
function nextPhase() {
const next = phaseStarts.find((start) => start > simulationTime + 0.04);
simulationTime = next === undefined ? 0 : next;
history.length = 0;
}
function restart() {
simulationTime = 0;
spinGroup.rotation.y = 0;
history.length = 0;
}
ui.pause.addEventListener("click", togglePause);
ui.rate.addEventListener("click", cycleRate);
ui.phase.addEventListener("click", nextPhase);
ui.restart.addEventListener("click", restart);
ui.camera.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePause();
} else if (event.key.toLowerCase() === "c") {
nextPhase();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Live chart
// -------------------------------------------------------------------------
const history = [];
const chartContext = ui.chart.getContext("2d");
function drawChart() {
const rect = ui.chart.getBoundingClientRect();
if (rect.width < 2 || rect.height < 2) return;
const dpr = Math.min(window.devicePixelRatio, 2);
const width = rect.width;
const height = rect.height;
const pixelWidth = Math.round(width * dpr);
const pixelHeight = Math.round(height * dpr);
if (ui.chart.width !== pixelWidth || ui.chart.height !== pixelHeight) {
ui.chart.width = pixelWidth;
ui.chart.height = pixelHeight;
}
const context = chartContext;
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, width, height);
const left = 37;
const right = width - 39;
const top = 23;
const bottom = height - 25;
const plotWidth = right - left;
const plotHeight = bottom - top;
const timeEnd = Math.max(10, simulationTime + 0.05);
const timeStart = Math.max(0, timeEnd - 10);
context.lineWidth = 1;
context.strokeStyle = "rgba(255,255,255,0.09)";
context.fillStyle = "#7892a4";
context.font = "9px system-ui";
context.textAlign = "right";
context.textBaseline = "middle";
for (let i = 0; i <= 4; i++) {
const y = top + (plotHeight * i) / 4;
context.beginPath();
context.moveTo(left, y);
context.lineTo(right, y);
context.stroke();
const omegaValue = OMEGA_MAX * (1 - i / 4);
const energyValue = ENERGY_MAX * (1 - i / 4);
context.fillText(omegaValue.toFixed(0), left - 7, y);
context.textAlign = "left";
context.fillText(energyValue.toFixed(0), right + 7, y);
context.textAlign = "right";
}
context.textAlign = "left";
context.fillStyle = "#ff7959";
context.fillText("ω rad/s", left, 10);
context.textAlign = "right";
context.fillStyle = "#5ee2d8";
context.fillText("K J", right, 10);
context.textAlign = "center";
context.fillStyle = "#7892a4";
context.fillText("time →", (left + right) / 2, height - 7);
function drawSeries(key, maximum, color) {
context.beginPath();
context.strokeStyle = color;
context.lineWidth = 2;
context.lineJoin = "round";
context.lineCap = "round";
let started = false;
for (const point of history) {
if (point.time < timeStart - 0.1) continue;
const x =
left +
((point.time - timeStart) / (timeEnd - timeStart)) * plotWidth;
const value = THREE.MathUtils.clamp(point[key] / maximum, 0, 1);
const y = bottom - value * plotHeight;
if (!started) {
context.moveTo(x, y);
started = true;
} else {
context.lineTo(x, y);
}
}
context.stroke();
}
drawSeries("omega", OMEGA_MAX, "#ff7959");
drawSeries("energy", ENERGY_MAX, "#5ee2d8");
if (history.length > 0) {
const current = history[history.length - 1];
function currentPoint(key, maximum, color) {
const x =
left +
((current.time - timeStart) / (timeEnd - timeStart)) * plotWidth;
const y =
bottom -
(THREE.MathUtils.clamp(current[key] / maximum, 0, 1) * plotHeight);
context.beginPath();
context.fillStyle = color;
context.arc(x, y, 3, 0, Math.PI * 2);
context.fill();
}
currentPoint("omega", OMEGA_MAX, "#ff7959");
currentPoint("energy", ENERGY_MAX, "#5ee2d8");
}
}
// -------------------------------------------------------------------------
// Main animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const rawDelta = Math.min(clock.getDelta(), 0.05);
const phase = getPhaseState(simulationTime);
if (!paused) {
simulationTime += rawDelta * playbackRate;
const inertia = I_BODY + I_ARM * phase.q * phase.q;
const omega = L_Z / inertia;
// Integrate the visual spin using the angular speed derived from
// L = Iω. During shape changes, I changes and omega changes smoothly.
spinGroup.rotation.y =
(spinGroup.rotation.y + omega * rawDelta * playbackRate) % TAU;
history.push({
time: simulationTime,
omega,
energy: (L_Z * L_Z) / (2 * inertia)
});
if (history.length > 1200) history.shift();
}
const inertia = I_BODY + I_ARM * phase.q * phase.q;
const omega = L_Z / inertia;
const energy = (L_Z * L_Z) / (2 * inertia);
const rpm = (omega * 60) / TAU;
const deltaEnergy = energy - K_ARMS_OUT;
updateArms(phase.q);
ui.omega.textContent = omega.toFixed(2);
ui.rpm.textContent = rpm.toFixed(1);
ui.inertia.textContent = inertia.toFixed(2);
ui.energy.textContent = energy.toFixed(2);
ui.delta.textContent = `${deltaEnergy >= 0 ? "+" : ""}${deltaEnergy.toFixed(2)}`;
ui.speedFill.style.width = `${(omega / OMEGA_MAX) * 100}%`;
ui.energyFill.style.width = `${(energy / ENERGY_MAX) * 100}%`;
ui.phasePanel.style.setProperty("--phase", phase.color);
ui.phaseTitle.textContent = phase.title;
ui.phaseCopy.textContent = phase.copy;
spinRingMaterial.color.set(phase.color);
spinRingMaterial.emissive.set(phase.color);
spinRingMaterial.emissiveIntensity = 0.18 + (omega / OMEGA_MAX) * 0.38;
drawChart();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
drawChart();
});
if ("ResizeObserver" in window) {
const chartObserver = new ResizeObserver(drawChart);
chartObserver.observe(ui.chart);
}
updateArms(1);
loading.classList.add("hidden");
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```