Prompt specification
Build or customize the Three.js 3D scene "Frame rate motion comparison" 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: Frame rate motion comparison
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/frame-rate-motion-comparison-x0334
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a flipbook. Animate a bouncing ball sequence at two playback rates beside its static frame strip; preserve identical frame order while making temporal sampling differences evident. Low-poly.
Working Three.js Starter (frame-rate-motion-comparison-x0334):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flipbook Lab — Same Frames, Different Time</title>
<style>
:root {
color-scheme: light;
--ink: #17282c;
--paper: #f5f0e6;
--slow: #36b9a3;
--fast: #ff8057;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9dfda;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
top: 26px;
left: 28px;
z-index: 10;
width: min(380px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
padding: 7px 10px;
border: 1px solid rgba(23, 40, 44, 0.22);
border-radius: 999px;
background: rgba(245, 240, 230, 0.76);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--fast);
transform: rotate(12deg);
}
h1 {
margin: 0;
max-width: 350px;
font-size: clamp(30px, 4vw, 50px);
line-height: 0.98;
letter-spacing: -0.055em;
}
#hud p {
max-width: 350px;
margin: 15px 0 0;
color: rgba(23, 40, 44, 0.74);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 16px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border-radius: 7px;
background: rgba(245, 240, 230, 0.78);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 50%;
}
#controls {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 20;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border: 1px solid rgba(23, 40, 44, 0.18);
border-radius: 13px;
background: rgba(245, 240, 230, 0.84);
box-shadow: 0 12px 36px rgba(24, 38, 38, 0.13);
backdrop-filter: blur(12px);
}
button {
border: 0;
border-radius: 8px;
padding: 9px 12px;
background: #20373b;
color: #fffaf0;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #2e4a4f;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#hint {
position: fixed;
left: 28px;
bottom: 28px;
z-index: 10;
color: rgba(23, 40, 44, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d9dfda;
color: #20373b;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#hud {
top: 18px;
left: 18px;
}
#hud p {
display: none;
}
.legend {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
}
#hint {
left: 18px;
bottom: 66px;
max-width: 120px;
line-height: 1.5;
}
}
</style>
</head>
<body>
<div id="hud">
<div class="eyebrow">Flipbook Lab / Sampling Study</div>
<h1>Same frames.<br>Different time.</h1>
<p>
Both players consume the same ordered 16-frame bouncing-ball sequence.
The faster player gathers more samples, but never changes the frame order.
</p>
<div class="legend">
<span><i style="background:#36b9a3"></i>0.5× sampling</span>
<span><i style="background:#ff8057"></i>1.5× sampling</span>
<span><i style="background:#f25f3d"></i>shared ball</span>
</div>
</div>
<div id="hint">Drag to orbit · wheel to zoom</div>
<div id="controls">
<button id="pause" type="button">Pause</button>
<button id="reset" type="button">Reset sequence</button>
<button id="home" type="button">Reset view</button>
</div>
<div id="loading">Building flipbook…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9dfda);
scene.fog = new THREE.Fog(0xd9dfda, 25, 58);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
// Direct camera controls: no addons or examples modules.
const orbit = {
yaw: 0.06,
pitch: 0.39,
radius: 17.8,
target: new THREE.Vector3(-0.15, 1.45, 0)
};
function updateCamera() {
const cp = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * cp * orbit.radius,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * cp * orbit.radius
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.yaw = 0.06;
orbit.pitch = 0.39;
orbit.radius = innerWidth / innerHeight < 1 ? 25 : 17.8;
orbit.target.set(-0.15, 1.45, 0);
updateCamera();
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.0045,
0.15,
0.78
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
10,
29
);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Lighting and low-poly materials
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf7fbff, 0x806b54, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.2);
keyLight.position.set(-5, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8edbcf, 1.1);
rimLight.position.set(9, 6, -7);
scene.add(rimLight);
const materials = {
table: new THREE.MeshStandardMaterial({
color: 0xc8bda8,
roughness: 0.96,
metalness: 0
}),
ground: new THREE.MeshStandardMaterial({
color: 0xd1d8d2,
roughness: 1
}),
paper: new THREE.MeshStandardMaterial({
color: 0xf4ecdc,
roughness: 0.93,
metalness: 0
}),
dark: new THREE.MeshStandardMaterial({
color: 0x1c3035,
roughness: 0.68,
metalness: 0.12,
flatShading: true
}),
frame: new THREE.MeshStandardMaterial({
color: 0x31484c,
roughness: 0.6,
metalness: 0.2,
flatShading: true
}),
ball: new THREE.MeshStandardMaterial({
color: 0xf25f3d,
roughness: 0.68,
metalness: 0.03,
flatShading: true
}),
slow: new THREE.MeshStandardMaterial({
color: 0x36b9a3,
roughness: 0.6,
metalness: 0.12,
flatShading: true
}),
fast: new THREE.MeshStandardMaterial({
color: 0xff8057,
roughness: 0.6,
metalness: 0.12,
flatShading: true
})
};
const table = new THREE.Mesh(
new THREE.BoxGeometry(24, 0.22, 10.5),
materials.table
);
table.position.y = -0.13;
table.receiveShadow = true;
scene.add(table);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.26;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 24, 0x76837f, 0x76837f);
grid.position.y = -0.008;
grid.scale.z = 0.42;
grid.material.transparent = true;
grid.material.opacity = 0.09;
scene.add(grid);
// ---------------------------------------------------------------------
// One canonical, ordered frame sequence
// ---------------------------------------------------------------------
const FRAME_COUNT = 16;
const BASE_FPS = 4;
// Every player samples this exact array. No player-specific animation
// is generated here.
const frames = Array.from({ length: FRAME_COUNT }, (_, i) => {
const angle = (i / FRAME_COUNT) * Math.PI * 2;
return {
x: -Math.cos(angle) * 0.9,
y: (1 - Math.cos(angle * 2)) * 0.5,
rotation: i * 0.43
};
});
function makeCanvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSourceTitle() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#20373b";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#ff8057";
ctx.fillRect(0, 0, 18, canvas.height);
ctx.fillStyle = "#f7f0e4";
ctx.font = "800 54px system-ui, sans-serif";
ctx.fillText("SOURCE FRAME STRIP", 52, 78);
ctx.fillStyle = "#a9c1bf";
ctx.font = "700 24px system-ui, sans-serif";
ctx.fillText(
"16 CANONICAL FRAMES / ONE LOCKED ORDER / 01 → 16",
54,
128
);
const texture = makeCanvasTexture(canvas);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(7.75, 1.15),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.position.set(-4.45, 1.47, 0.01);
return mesh;
}
scene.add(makeSourceTitle());
function makeFrameNumberTexture(number) {
const canvas = document.createElement("canvas");
canvas.width = 96;
canvas.height = 48;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 96, 48);
ctx.fillStyle = "#20373b";
ctx.font = "800 27px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number).padStart(2, "0"), 48, 24);
return makeCanvasTexture(canvas);
}
// Static horizontal strip showing every frame in order.
const stripGroup = new THREE.Group();
stripGroup.position.set(-4.45, 0, 0);
scene.add(stripGroup);
const stripBase = new THREE.Mesh(
new THREE.BoxGeometry(7.85, 0.18, 1.22),
materials.dark
);
stripBase.position.y = 0.1;
stripBase.castShadow = true;
stripBase.receiveShadow = true;
stripGroup.add(stripBase);
const stripInset = new THREE.Mesh(
new THREE.BoxGeometry(7.55, 0.025, 0.96),
new THREE.MeshStandardMaterial({
color: 0x284146,
roughness: 0.85
})
);
stripInset.position.set(0, 0.202, 0.04);
stripInset.receiveShadow = true;
stripGroup.add(stripInset);
const miniBallGeometry = new THREE.IcosahedronGeometry(1, 1);
frames.forEach((frame, i) => {
const cardGroup = new THREE.Group();
cardGroup.position.set(
(i - (FRAME_COUNT - 1) / 2) * 0.47,
0.66,
0.19
);
cardGroup.rotation.x = -0.075;
stripGroup.add(cardGroup);
const card = new THREE.Mesh(
new THREE.BoxGeometry(0.4, 0.72, 0.065),
materials.paper
);
card.castShadow = true;
card.receiveShadow = true;
cardGroup.add(card);
const baseline = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.012, 0.012),
new THREE.MeshBasicMaterial({ color: 0x8f9890 })
);
baseline.position.set(0, -0.145, 0.043);
cardGroup.add(baseline);
const miniBall = new THREE.Mesh(miniBallGeometry, materials.ball);
miniBall.scale.setScalar(0.075);
miniBall.position.set(
frame.x * 0.105,
-0.13 + frame.y * 0.265,
0.092
);
miniBall.rotation.set(frame.rotation * 0.5, frame.rotation, 0);
miniBall.castShadow = true;
cardGroup.add(miniBall);
const numberTexture = makeFrameNumberTexture(i + 1);
const numberPlane = new THREE.Mesh(
new THREE.PlaneGeometry(0.25, 0.125),
new THREE.MeshBasicMaterial({
map: numberTexture,
transparent: true,
depthWrite: false
})
);
numberPlane.position.set(0, -0.275, 0.04);
cardGroup.add(numberPlane);
});
// ---------------------------------------------------------------------
// Player screen texture
// ---------------------------------------------------------------------
function createScreen(player) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const texture = makeCanvasTexture(canvas);
function draw(index, sampleNumber) {
const accent = player.accent;
const accentCSS = player.accentCSS;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#13262b";
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Header.
ctx.fillStyle = accentCSS;
ctx.fillRect(0, 0, 12, 92);
ctx.fillStyle = accentCSS;
ctx.font = "800 39px system-ui, sans-serif";
ctx.fillText(player.rateLabel, 30, 43);
ctx.fillStyle = "#f2eee4";
ctx.font = "750 21px system-ui, sans-serif";
ctx.fillText(player.title, 30, 75);
ctx.textAlign = "right";
ctx.fillStyle = "#89a4a5";
ctx.font = "700 15px ui-monospace, monospace";
ctx.fillText(
`${player.intervalLabel} / SAMPLE`,
738,
39
);
ctx.fillStyle = "#f2eee4";
ctx.font = "800 24px ui-monospace, monospace";
ctx.fillText(
`SAMPLE ${String(sampleNumber).padStart(4, "0")}`,
738,
72
);
ctx.textAlign = "left";
// Playfield grid.
ctx.strokeStyle = "rgba(139,164,165,0.13)";
ctx.lineWidth = 1;
for (let y = 112; y <= 342; y += 46) {
ctx.beginPath();
ctx.moveTo(30, y);
ctx.lineTo(738, y);
ctx.stroke();
}
for (let x = 78; x < 738; x += 66) {
ctx.beginPath();
ctx.moveTo(x, 106);
ctx.lineTo(x, 342);
ctx.stroke();
}
// Canonical trajectory.
ctx.strokeStyle = "rgba(225,235,229,0.25)";
ctx.lineWidth = 2;
ctx.beginPath();
frames.forEach((frame, i) => {
const px = 384 + frame.x * 245;
const py = 340 - frame.y * 215;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
});
ctx.stroke();
// Canonical sample points.
frames.forEach((frame, i) => {
const px = 384 + frame.x * 245;
const py = 340 - frame.y * 215;
const current = i === index;
ctx.beginPath();
ctx.arc(px, py, current ? 8 : 4, 0, Math.PI * 2);
ctx.fillStyle = current ? accentCSS : "#68898a";
ctx.fill();
if (current) {
ctx.strokeStyle = "rgba(255,255,255,0.8)";
ctx.lineWidth = 2;
ctx.stroke();
}
});
// Baseline.
ctx.strokeStyle = "rgba(226,235,228,0.38)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(48, 340);
ctx.lineTo(720, 340);
ctx.stroke();
// Current-frame information.
ctx.fillStyle = "#799697";
ctx.font = "700 14px ui-monospace, monospace";
ctx.fillText("CURRENT CANONICAL FRAME", 30, 374);
ctx.fillStyle = "#f3efe6";
ctx.font = "800 27px ui-monospace, monospace";
ctx.fillText(
`${String(index + 1).padStart(2, "0")} / ${FRAME_COUNT}`,
30,
405
);
ctx.textAlign = "right";
ctx.fillStyle = "#799697";
ctx.font = "700 14px system-ui, sans-serif";
ctx.fillText("IDENTICAL FRAME ORDER", 738, 374);
ctx.fillStyle = "#f3efe6";
ctx.font = "800 19px ui-monospace, monospace";
ctx.fillText("01 → 02 → … → 16", 738, 402);
ctx.textAlign = "left";
// Miniature order strip. Both screens always show this same order.
ctx.fillStyle = "#0d1d21";
ctx.fillRect(20, 424, 728, 69);
const cellWidth = 43;
const gap = 2;
const startX = 31;
for (let i = 0; i < FRAME_COUNT; i++) {
const x = startX + i * (cellWidth + gap);
const selected = i === index;
ctx.fillStyle = selected ? accentCSS : "#20363a";
ctx.fillRect(x, 434, cellWidth, 48);
ctx.fillStyle = selected ? "#14272b" : "#8fa7a6";
ctx.font = "800 16px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.fillText(
String(i + 1).padStart(2, "0"),
x + cellWidth / 2,
464
);
}
ctx.textAlign = "left";
texture.needsUpdate = true;
}
return { canvas, ctx, texture, draw };
}
// ---------------------------------------------------------------------
// Player construction
// ---------------------------------------------------------------------
function createPlayer({
x,
rate,
rateLabel,
title,
intervalLabel,
accent,
accentCSS
}) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const base = new THREE.Mesh(
new THREE.BoxGeometry(3.5, 0.18, 2.12),
materials.dark
);
base.position.y = 0.12;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 1.22, 0.36),
materials.frame
);
stem.position.y = 0.8;
stem.castShadow = true;
group.add(stem);
const screenFrame = new THREE.Mesh(
new THREE.BoxGeometry(3.35, 2.3, 0.3),
materials.frame
);
screenFrame.position.y = 2.2;
screenFrame.castShadow = true;
screenFrame.receiveShadow = true;
group.add(screenFrame);
const accentBar = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 2.12, 0.035),
new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.55,
metalness: 0.1,
flatShading: true
})
);
accentBar.position.set(-1.59, 2.2, 0.168);
group.add(accentBar);
const player = {
group,
rate,
rateLabel,
title,
intervalLabel,
accent,
accentCSS,
lastIndex: -1,
pulseAt: -10
};
const screen = createScreen(player);
player.screen = screen;
const face = new THREE.Mesh(
new THREE.PlaneGeometry(3.1, 2.12),
new THREE.MeshBasicMaterial({ map: screen.texture })
);
face.position.set(0, 2.2, 0.157);
group.add(face);
// Static 3D trajectory over the screen.
const points = frames.map(
frame =>
new THREE.Vector3(
frame.x * 0.92,
1.68 + frame.y * 0.82,
0.18
)
);
const trajectory = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0xa7c1bd,
transparent: true,
opacity: 0.28
})
);
group.add(trajectory);
const sampleDots = new THREE.Group();
const dotGeometry = new THREE.IcosahedronGeometry(0.026, 0);
const dotMaterial = new THREE.MeshBasicMaterial({
color: 0x8eaaa8,
transparent: true,
opacity: 0.65
});
points.forEach(point => {
const dot = new THREE.Mesh(dotGeometry, dotMaterial);
dot.position.copy(point);
sampleDots.add(dot);
});
group.add(sampleDots);
const ball = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.155, 1),
materials.ball
);
ball.castShadow = true;
ball.position.z = 0.29;
group.add(ball);
player.ball = ball;
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.11, 12),
new THREE.MeshBasicMaterial({
color: 0x071719,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
shadow.scale.set(1.5, 0.35, 1);
shadow.position.z = 0.17;
group.add(shadow);
player.shadow = shadow;
const pulse = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.012, 4, 16),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0,
depthWrite: false
})
);
pulse.position.z = 0.27;
group.add(pulse);
player.pulse = pulse;
return player;
}
const slowPlayer = createPlayer({
x: 2.0,
rate: 0.5,
rateLabel: "0.5×",
title: "SLOW SAMPLING",
intervalLabel: "500 ms",
accent: 0x36b9a3,
accentCSS: "#36b9a3"
});
const fastPlayer = createPlayer({
x: 6.2,
rate: 1.5,
rateLabel: "1.5×",
title: "FAST SAMPLING",
intervalLabel: "167 ms",
accent: 0xff8057,
accentCSS: "#ff8057"
});
const players = [slowPlayer, fastPlayer];
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
let elapsed = 0;
let paused = false;
let previousTime = performance.now();
function setPlayerFrame(player, index, sampleNumber) {
const frame = frames[index];
player.ball.position.x = frame.x * 0.92;
player.ball.position.y = 1.68 + frame.y * 0.82;
player.ball.rotation.set(
frame.rotation * 0.7,
frame.rotation,
frame.rotation * 0.35
);
player.shadow.position.x = player.ball.position.x;
player.shadow.position.y = 1.68;
player.pulse.position.x = player.ball.position.x;
player.pulse.position.y = player.ball.position.y;
player.pulseAt = elapsed;
player.screen.draw(index, sampleNumber);
player.lastIndex = index;
}
function animate(now) {
requestAnimationFrame(animate);
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (!paused) elapsed += delta;
players.forEach(player => {
// The only difference is how frequently this same frame array
// is sampled. Frame order and frame content remain identical.
const samplePosition = elapsed * BASE_FPS * player.rate;
const index = Math.floor(samplePosition) % FRAME_COUNT;
const sampleNumber = Math.floor(samplePosition) + 1;
if (index !== player.lastIndex) {
setPlayerFrame(player, index, sampleNumber);
}
const pulseAge = elapsed - player.pulseAt;
if (pulseAge >= 0 && pulseAge < 0.14) {
const t = pulseAge / 0.14;
player.pulse.visible = true;
player.pulse.material.opacity = (1 - t) * 0.9;
player.pulse.scale.setScalar(1 + t * 1.65);
} else {
player.pulse.visible = false;
}
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
// ---------------------------------------------------------------------
// UI controls and resizing
// ---------------------------------------------------------------------
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
});
document.querySelector("#reset").addEventListener("click", () => {
elapsed = 0;
players.forEach(player => {
player.lastIndex = -1;
player.pulseAt = -10;
});
});
document.querySelector("#home").addEventListener("click", resetCamera);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// Render once, then remove the loading message.
renderer.render(scene, camera);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```