Prompt specification
Build or customize the Three.js 3D scene "Top spin-down display" 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: Top spin-down display
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/top-spin-down-display-x0378
Scene Description Prompt:
Animate a low-poly spinning top slowing, wobbling, and settling in a stylized sequence. One HTML file with Three.js from cdnjs.
Working Three.js Starter (top-spin-down-display-x0378):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Low-Poly Spinning Top</title>
<style>
:root{
--coral:#e4572e; --teal:#17bebb; --gold:#ffd166; --cream:#f4ecdc;
--ink:#070b18;
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden}
body{
background:
radial-gradient(120% 90% at 50% 0%, #24345f 0%, #131c36 42%, var(--ink) 100%);
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
color:var(--cream);
-webkit-font-smoothing:antialiased;
}
canvas{display:block;touch-action:none}
#hud{position:fixed;inset:0;pointer-events:none;z-index:10}
.panel{
position:absolute;padding:14px 16px;border-radius:14px;
background:rgba(9,14,30,.42);border:1px solid rgba(244,236,220,.12);
backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
box-shadow:0 10px 30px rgba(0,0,0,.35);
}
#title{top:22px;left:22px}
#title h1{font-size:15px;letter-spacing:.24em;font-weight:600}
#title h1 span{color:var(--coral)}
#title p{margin-top:7px;font-size:11px;letter-spacing:.1em;opacity:.55}
#stats{bottom:22px;left:22px;min-width:236px}
.row{display:flex;justify-content:space-between;align-items:baseline;font-size:11px;letter-spacing:.12em}
#phase{color:var(--gold);font-weight:600}
.meter{margin-top:10px;height:6px;border-radius:99px;background:rgba(244,236,220,.12);overflow:hidden}
.meter i{display:block;height:100%;width:0%;border-radius:99px;
background:linear-gradient(90deg,var(--teal),var(--gold) 60%,var(--coral));transition:width .08s linear}
.sub{margin-top:9px;font-size:10px;letter-spacing:.1em;opacity:.45}
#hint{bottom:22px;right:22px;font-size:10.5px;letter-spacing:.1em;opacity:.6;text-align:right;line-height:1.7}
#hint b{color:var(--teal);font-weight:600}
#replay{
position:absolute;top:22px;right:22px;pointer-events:auto;cursor:pointer;
font:inherit;font-size:11px;letter-spacing:.18em;color:var(--cream);
padding:11px 16px;border-radius:99px;border:1px solid rgba(244,236,220,.2);
background:rgba(9,14,30,.42);backdrop-filter:blur(10px);transition:.18s;
}
#replay:hover{background:rgba(228,87,46,.22);border-color:rgba(228,87,46,.6);transform:translateY(-1px)}
#legend{position:absolute;left:50%;top:24px;transform:translateX(-50%);font-size:10px;letter-spacing:.28em;opacity:.35}
@media (max-width:640px){
#legend{display:none} #hint{display:none}
#title{top:14px;left:14px;padding:11px 13px} #stats{bottom:14px;left:14px}
#replay{top:14px;right:14px;padding:9px 13px}
}
</style>
</head>
<body>
<div id="hud">
<div class="panel" id="title">
<h1>LOW<span>·</span>POLY TOP</h1>
<p>spin · decay · wobble · settle</p>
</div>
<div id="legend">A STUDY IN GRAVITY & FRICTION</div>
<button id="replay">↻ REPLAY</button>
<div class="panel" id="stats">
<div class="row"><span>PHASE</span><span id="phase">LAUNCH</span></div>
<div class="meter"><i id="bar"></i></div>
<div class="row sub"><span>SPIN RATE</span><span id="rate">0.0 rev/s</span></div>
<div class="row sub"><span>TILT</span><span id="tilt">0.0°</span></div>
</div>
<div class="panel" id="hint">
<b>drag</b> orbit · <b>wheel / pinch</b> zoom<br>
<b>space</b> replay · <b>double-click</b> reset view
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
PALETTE / RENDERER
============================================================ */
const COL = {
coral : 0xe4572e,
teal : 0x17bebb,
gold : 0xffd166,
cream : 0xf4ecdc,
steel : 0xc9d4e6,
plate : 0x101c36,
bg : 0x0a1024
};
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(COL.bg, 0.045);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 100);
camera.position.set(3.4, 2.6, 4.2);
const renderer = new THREE.WebGLRenderer({ antialias:true, alpha:true, powerPreference:'high-performance' });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.appendChild(renderer.domElement);
/* ============================================================
LIGHTS
============================================================ */
scene.add(new THREE.HemisphereLight(0x86a8ff, 0x0c1428, 0.75));
const key = new THREE.DirectionalLight(0xfff2dd, 2.1);
key.position.set(3.5, 6.5, 4.5);
key.castShadow = true;
key.shadow.mapSize.set(1024,1024);
key.shadow.camera.left = -4; key.shadow.camera.right = 4;
key.shadow.camera.top = 4; key.shadow.camera.bottom = -4;
key.shadow.camera.near = 0.5; key.shadow.camera.far = 18;
key.shadow.bias = -0.0008;
key.shadow.normalBias = 0.02;
scene.add(key);
const rim = new THREE.PointLight(COL.teal, 22, 14, 2);
rim.position.set(-3.2, 1.8, -3.4);
scene.add(rim);
const warm = new THREE.PointLight(COL.gold, 14, 12, 2);
warm.position.set(2.6, 2.2, -2.4);
scene.add(warm);
/* ============================================================
STAGE (ground, arena disc, rings, ticks)
============================================================ */
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60,60),
new THREE.MeshStandardMaterial({ color:0x0a1128, roughness:1, metalness:0 })
);
ground.rotation.x = -Math.PI/2;
ground.position.y = -0.001;
ground.receiveShadow = true;
scene.add(ground);
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(3.25, 3.45, 0.18, 56),
new THREE.MeshStandardMaterial({ color:COL.plate, roughness:.85, metalness:.08 })
);
disc.position.y = -0.09;
disc.receiveShadow = true;
scene.add(disc);
const rimRing = new THREE.Mesh(
new THREE.TorusGeometry(3.25, 0.022, 6, 96),
new THREE.MeshBasicMaterial({ color:COL.teal, transparent:true, opacity:.65 })
);
rimRing.rotation.x = Math.PI/2; rimRing.position.y = 0.005;
scene.add(rimRing);
[1.05, 1.85, 2.65].forEach((r,i)=>{
const ring = new THREE.Mesh(
new THREE.RingGeometry(r-0.008, r+0.008, 80),
new THREE.MeshBasicMaterial({ color:i===1?COL.gold:COL.teal, transparent:true, opacity:.22, side:THREE.DoubleSide })
);
ring.rotation.x = -Math.PI/2; ring.position.y = 0.004;
scene.add(ring);
});
const tickMat = new THREE.MeshBasicMaterial({ color:0x8ea6d8, transparent:true, opacity:.35 });
for(let i=0;i<36;i++){
const a = i/36*Math.PI*2;
const t = new THREE.Mesh(new THREE.BoxGeometry(i%3===0?0.16:0.08, 0.008, 0.02), tickMat);
t.position.set(Math.cos(a)*3.02, 0.006, Math.sin(a)*3.02);
t.rotation.y = -a;
scene.add(t);
}
/* soft contact blob texture */
function blobTexture(){
const c = document.createElement('canvas'); c.width = c.height = 128;
const x = c.getContext('2d');
const g = x.createRadialGradient(64,64,2,64,64,62);
g.addColorStop(0,'rgba(0,0,0,0.62)'); g.addColorStop(.55,'rgba(0,0,0,0.24)'); g.addColorStop(1,'rgba(0,0,0,0)');
x.fillStyle=g; x.fillRect(0,0,128,128);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}
const blob = new THREE.Mesh(
new THREE.PlaneGeometry(1.3,1.3),
new THREE.MeshBasicMaterial({ map:blobTexture(), transparent:true, depthWrite:false, opacity:.9 })
);
blob.rotation.x = -Math.PI/2; blob.position.y = 0.006;
scene.add(blob);
/* ============================================================
THE TOP (low-poly lathe body + accents)
============================================================ */
const topRoot = new THREE.Group(); // vertical position (launch / bounce)
const tiltGroup = new THREE.Group(); // lean + precession
const spinGroup = new THREE.Group(); // spin about own axis
topRoot.add(tiltGroup); tiltGroup.add(spinGroup);
scene.add(topRoot);
const flat = (color, extra={}) => new THREE.MeshStandardMaterial(
Object.assign({ color, flatShading:true, roughness:.45, metalness:.05 }, extra)
);
const bodyMat = flat(COL.coral);
const bandMat = flat(COL.teal, { roughness:.35 });
const goldMat = flat(COL.gold, { roughness:.3, metalness:.35, emissive:COL.gold, emissiveIntensity:.12 });
const steelMat = flat(COL.steel, { roughness:.22, metalness:.85 });
const knobMat = flat(COL.cream, { roughness:.5 });
const profile = [
[0.000,0.22],[0.055,0.22],[0.090,0.30],[0.280,0.38],[0.440,0.48],
[0.475,0.60],[0.460,0.72],[0.370,0.82],[0.220,0.90],[0.120,0.94],
[0.115,1.04],[0.210,1.08],[0.130,1.12],[0.110,1.18],[0.110,1.30],
[0.200,1.36],[0.120,1.42],[0.000,1.46]
].map(p => new THREE.Vector2(p[0], p[1]));
const body = new THREE.Mesh(new THREE.LatheGeometry(profile, 12), bodyMat);
body.castShadow = true; body.receiveShadow = true;
spinGroup.add(body);
const band = new THREE.Mesh(new THREE.CylinderGeometry(0.482,0.482,0.085,12), bandMat);
band.position.y = 0.655; band.castShadow = true;
spinGroup.add(band);
const tip = new THREE.Mesh(new THREE.ConeGeometry(0.062, 0.22, 8), steelMat);
tip.rotation.x = Math.PI; tip.position.y = 0.11; tip.castShadow = true;
spinGroup.add(tip);
const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.075,0.095,0.22,8), knobMat);
stem.position.y = 1.24; stem.castShadow = true;
spinGroup.add(stem);
const knob = new THREE.Mesh(new THREE.IcosahedronGeometry(0.165, 0), knobMat);
knob.position.y = 1.47; knob.castShadow = true;
spinGroup.add(knob);
/* three radial fins make the spin readable */
for(let i=0;i<3;i++){
const g = new THREE.Group(); g.rotation.y = i*Math.PI*2/3;
const fin = new THREE.Mesh(new THREE.BoxGeometry(0.54,0.045,0.10), goldMat);
fin.position.set(0.30, 0.575, 0); fin.castShadow = true;
g.add(fin); spinGroup.add(g);
}
/* glowing energy rings (speed-reactive) */
const haloMat = new THREE.MeshBasicMaterial({ color:COL.teal, transparent:true, opacity:.3, blending:THREE.AdditiveBlending, depthWrite:false });
const halo1 = new THREE.Mesh(new THREE.TorusGeometry(0.86,0.012,6,64), haloMat);
halo1.rotation.x = Math.PI/2; halo1.position.y = 0.10;
const halo2 = new THREE.Mesh(new THREE.TorusGeometry(0.62,0.010,6,64), haloMat.clone());
halo2.material.color.set(COL.gold);
halo2.rotation.x = Math.PI/2; halo2.position.y = 1.02;
spinGroup.add(halo1, halo2);
/* ============================================================
DUST MOTES
============================================================ */
const DUST = 260;
const dustPos = new Float32Array(DUST*3), dustBase = new Float32Array(DUST*3), dustPh = new Float32Array(DUST);
for(let i=0;i<DUST;i++){
const a = Math.random()*Math.PI*2, r = Math.random()*7 + .4, y = Math.random()*4.2;
dustBase[i*3]=Math.cos(a)*r; dustBase[i*3+1]=y; dustBase[i*3+2]=Math.sin(a)*r;
dustPos[i*3]=dustBase[i*3]; dustPos[i*3+1]=dustBase[i*3+2]*0+dustBase[i*3+1]; dustPos[i*3+2]=dustBase[i*3+2];
dustPh[i]=Math.random()*Math.PI*2;
}
const dustGeo = new THREE.BufferGeometry();
dustGeo.setAttribute('position', new THREE.BufferAttribute(dustPos,3));
const dust = new THREE.Points(dustGeo, new THREE.PointsMaterial({
color:0xbcd0ff, size:0.035, transparent:true, opacity:.4, sizeAttenuation:true, depthWrite:false
}));
scene.add(dust);
/* ============================================================
LANDING BURST + SHOCKWAVE
============================================================ */
const BN = 90;
const bPos = new Float32Array(BN*3), bVel = new Float32Array(BN*3), bLife = new Float32Array(BN);
const bGeo = new THREE.BufferGeometry();
bGeo.setAttribute('position', new THREE.BufferAttribute(bPos,3));
const bMat = new THREE.PointsMaterial({ color:0xffd9a8, size:.07, transparent:true, opacity:0, depthWrite:false, blending:THREE.AdditiveBlending });
const burst = new THREE.Points(bGeo, bMat); burst.frustumCulled=false; scene.add(burst);
const shock = new THREE.Mesh(
new THREE.RingGeometry(0.86,1.0,72),
new THREE.MeshBasicMaterial({ color:COL.gold, transparent:true, opacity:0, side:THREE.DoubleSide, depthWrite:false })
);
shock.rotation.x = -Math.PI/2; shock.position.y = 0.012; scene.add(shock);
let burstT = -1, shockT = -1;
function fireBurst(){
burstT = 0;
for(let i=0;i<BN;i++){
const a = Math.random()*Math.PI*2, sp = 1.6 + Math.random()*2.6;
bPos[i*3] = Math.cos(a)*0.16; bPos[i*3+1] = 0.05 + Math.random()*0.06; bPos[i*3+2] = Math.sin(a)*0.16;
bVel[i*3] = Math.cos(a)*sp; bVel[i*3+1] = 0.5 + Math.random()*1.7; bVel[i*3+2] = Math.sin(a)*sp;
bLife[i] = 0.75 + Math.random()*0.85;
}
shockT = 0;
}
/* ============================================================
STYLIZED TIMELINE (keyframed, deterministic)
============================================================ */
function curve(keys, t){
if(t <= keys[0][0]) return keys[0][1];
const last = keys[keys.length-1];
if(t >= last[0]) return last[1];
for(let i=0;i<keys.length-1;i++){
const [t0,v0]=keys[i], [t1,v1]=keys[i+1];
if(t>=t0 && t<=t1){
const u=(t-t0)/(t1-t0), s=u*u*(3-2*u);
return v0+(v1-v0)*s;
}
}
return last[1];
}
const SPIN_KEYS = [
[0,0],[0.35,7],[1.00,26],[1.30,30],[4.00,30],[5.20,21],[6.40,14],
[7.60,8.4],[8.80,4.6],[9.80,2.2],[10.80,0.7],[11.60,0.12],[12.40,0],[14,0]
];
const TILT_KEYS = [
[0,0],[1.20,0.010],[2.50,0.016],[4.00,0.030],[5.50,0.090],[7.00,0.190],
[8.20,0.260],[9.20,0.245],[10.00,0.175],[10.80,0.095],[11.50,0.038],
[12.20,0.008],[13.20,0],[14,0]
];
const HEIGHT_KEYS = [
[0,2.30],[0.55,1.10],[0.95,0.22],[1.15,0.02],[1.32,0.10],[1.55,0.0],[2.0,0],[14,0]
];
const MAXSPIN = 30;
const PHASES = [
[0.0,'LAUNCH'],[1.3,'FULL SPIN'],[4.0,'DECAY'],[7.0,'WOBBLE'],[10.2,'SETTLE'],[12.6,'AT REST']
];
function phaseAt(t){
let p = PHASES[0][1];
for(const [tt,n] of PHASES){ if(t>=tt) p=n; }
return p;
}
let simT = 0, spinAngle = 0, precessAngle = 0, landed = false, lastLandT = -99;
/* ============================================================
CUSTOM ORBIT CONTROLS (no addons)
============================================================ */
const cam = {
azT: 0.72, polT: 1.16, distT: 5.1,
az: 0.72, pol: 1.16, dist: 5.1,
target: new THREE.Vector3(0, 0.80, 0),
idle: 0
};
const canvas = renderer.domElement;
const pointers = new Map();
let pinchPrev = 0;
function clamp(v,a,b){ return Math.max(a, Math.min(b,v)); }
canvas.addEventListener('pointerdown', e=>{
canvas.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, {x:e.clientX, y:e.clientY});
cam.idle = 0;
if(pointers.size===2) pinchPrev = pinchDist();
});
canvas.addEventListener('pointermove', e=>{
if(!pointers.has(e.pointerId)) return;
const p = pointers.get(e.pointerId);
const dx = e.clientX - p.x, dy = e.clientY - p.y;
p.x = e.clientX; p.y = e.clientY;
cam.idle = 0;
if(pointers.size===1){
cam.azT -= dx*0.0062;
cam.polT = clamp(cam.polT - dy*0.0050, 0.16, 1.48);
} else if(pointers.size===2){
const d = pinchDist();
if(pinchPrev>0) cam.distT = clamp(cam.distT * (pinchPrev/d), 2.1, 16);
pinchPrev = d;
}
});
function endPointer(e){ pointers.delete(e.pointerId); if(pointers.size<2) pinchPrev = 0; }
canvas.addEventListener('pointerup', endPointer);
canvas.addEventListener('pointercancel', endPointer);
canvas.addEventListener('pointerleave', endPointer);
function pinchDist(){
const a=[...pointers.values()];
if(a.length<2) return 0;
return Math.hypot(a[0].x-a[1].x, a[0].y-a[1].y);
}
canvas.addEventListener('wheel', e=>{
e.preventDefault();
cam.distT = clamp(cam.distT * (1 + Math.sign(e.deltaY)*0.09), 2.1, 16);
cam.idle = 0;
}, {passive:false});
canvas.addEventListener('dblclick', ()=>{ cam.azT=0.72; cam.polT=1.16; cam.distT=5.1; });
addEventListener('keydown', e=>{ if(e.code==='Space'){ e.preventDefault(); replay(); } });
document.getElementById('replay').addEventListener('click', replay);
function replay(){
simT = 0; spinAngle = 0; precessAngle = 0; landed = false; lastLandT = -99; burstT=-1; shockT=-1;
}
/* ============================================================
RESIZE
============================================================ */
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
/* ============================================================
MAIN LOOP
============================================================ */
const clock = new THREE.Clock();
const phaseEl = document.getElementById('phase');
const barEl = document.getElementById('bar');
const rateEl = document.getElementById('rate');
const tiltEl = document.getElementById('tilt');
const qA = new THREE.Quaternion(), qB = new THREE.Quaternion();
const axis = new THREE.Vector3();
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 1/20);
simT += dt;
/* --- keyframed motion ------------------------------------ */
const omega = curve(SPIN_KEYS, simT);
const amp = curve(TILT_KEYS, simT);
const h = curve(HEIGHT_KEYS, simT);
spinAngle += omega * dt;
// precession accelerates as the spin decays (classic top behaviour)
precessAngle += (0.35 + 3.1 * (1 - omega/MAXSPIN)) * (0.35 + omega/MAXSPIN*1.4) * dt * 1.15;
// oscillating lean about a precessing axis
const osc = 0.70 + 0.30*Math.sin(simT*6.1) + 0.14*Math.sin(simT*9.3 + 1.1);
const theta = amp * osc;
axis.set(Math.cos(precessAngle), 0, Math.sin(precessAngle)).normalize();
qA.setFromAxisAngle(axis, theta);
qB.setFromAxisAngle(new THREE.Vector3(1,0,0), amp*0.35*Math.sin(simT*4.7));
tiltGroup.quaternion.copy(qA).multiply(qB);
topRoot.position.y = h;
spinGroup.rotation.y = spinAngle;
// micro bob while fast
topRoot.position.y += 0.012 * (omega/MAXSPIN) * Math.sin(simT*17.0);
/* --- landing detection ----------------------------------- */
if(!landed && simT > 1.05){ landed = true; fireBurst(); lastLandT = simT; }
/* --- energy halos --------------------------------------- */
const sn = omega/MAXSPIN;
haloMat.opacity = 0.08 + 0.55*sn;
halo2.material.opacity = 0.05 + 0.45*sn*sn;
halo1.rotation.z += dt*(1.5 + 4*sn);
halo2.rotation.z -= dt*(1.0 + 3*sn);
/* --- contact blob ---------------------------------------- */
const sc = 1 + h*0.45;
blob.scale.set(sc, sc, sc);
blob.material.opacity = 0.9 / (1 + h*2.2);
/* --- dust drift ------------------------------------------ */
for(let i=0;i<DUST;i++){
const ph = dustPh[i];
dustPos[i*3] = dustBase[i*3] + Math.sin(simT*0.35 + ph)*0.28;
dustPos[i*3+1] = dustBase[i*3+1] + Math.sin(simT*0.22 + ph*1.7)*0.20;
dustPos[i*3+2] = dustBase[i*3+2] + Math.cos(simT*0.30 + ph*0.8)*0.28;
}
dustGeo.attributes.position.needsUpdate = true;
/* --- burst particles ------------------------------------- */
if(burstT >= 0){
burstT += dt;
let alive = 0;
for(let i=0;i<BN;i++){
if(burstT > bLife[i]){ bPos[i*3+1] = -99; continue; }
alive++;
bVel[i*3+1] -= 3.4*dt;
bVel[i*3] *= 0.985; bVel[i*3+2] *= 0.985;
bPos[i*3] += bVel[i*3]*dt;
bPos[i*3+1] += bVel[i*3+1]*dt;
bPos[i*3+2] += bVel[i*3+2]*dt;
if(bPos[i*3+1] < 0.01){ bPos[i*3+1]=0.01; bVel[i*3+1]*=-0.35; }
}
bGeo.attributes.position.needsUpdate = true;
bMat.opacity = Math.max(0, 0.85*(1 - burstT/1.7));
if(burstT > 1.8){ burstT = -1; bMat.opacity = 0; }
}
if(shockT >= 0){
shockT += dt;
const u = Math.min(shockT/0.85, 1);
shock.scale.setScalar(0.25 + u*3.0);
shock.material.opacity = 0.75*(1-u);
if(u>=1){ shockT = -1; shock.material.opacity = 0; }
}
/* --- camera ---------------------------------------------- */
cam.idle += dt;
if(cam.idle > 2.6){
const ramp = Math.min((cam.idle-2.6)/1.4, 1);
cam.azT += dt*0.085*ramp; // cinematic drift
}
const k = 1 - Math.pow(0.0012, dt);
cam.az += (cam.azT - cam.az )*k;
cam.pol += (cam.polT - cam.pol )*k;
cam.dist += (cam.distT - cam.dist)*k;
const sp = Math.sin(cam.pol);
camera.position.set(
cam.target.x + cam.dist*sp*Math.sin(cam.az),
cam.target.y + cam.dist*Math.cos(cam.pol),
cam.target.z + cam.dist*sp*Math.cos(cam.az)
);
camera.lookAt(cam.target);
/* --- HUD -------------------------------------------------- */
phaseEl.textContent = phaseAt(simT);
barEl.style.width = (sn*100).toFixed(1)+'%';
rateEl.textContent = (omega/(Math.PI*2)).toFixed(1)+' rev/s';
tiltEl.textContent = (theta*180/Math.PI).toFixed(1)+'°';
renderer.render(scene, camera);
// loop the sequence after a rest beat
if(simT > 16.5) replay();
}
animate();
</script>
</body>
</html>
```