Prompt specification
Build or customize the Three.js 3D scene "Bus interior inertia demonstration" 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: Bus interior inertia demonstration
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bus-interior-inertia-demonstration-x1403
Scene Description Prompt:
Bus interior inertia demonstration. Compose a small bus with a freely sliding toy block on a tray; animate acceleration and compare ground-frame motion with motion relative to the bus. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (bus-interior-inertia-demonstration-x1403):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bus Interior — Inertia Demonstration</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: #101c2c;
--panel-2: #142338;
--line: #263a52;
--text: #edf6ff;
--muted: #91a7bd;
--cyan: #4de3ff;
--orange: #ffb454;
--green: #72e6a8;
--red: #ff7185;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 12% 0%, #172c43 0, transparent 36rem),
radial-gradient(circle at 90% 12%, #12293b 0, transparent 32rem),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
padding: 24px;
}
button,
input {
font: inherit;
}
.app {
width: min(1500px, 100%);
margin: 0 auto;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 0.74rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
background: var(--cyan);
content: "";
box-shadow: 0 0 16px rgba(77, 227, 255, 0.65);
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 3.8vw, 3.1rem);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 620px;
margin: 10px 0 0;
color: var(--muted);
font-size: 0.95rem;
line-height: 1.55;
}
.controls {
display: flex;
flex-shrink: 0;
gap: 9px;
}
.control {
min-height: 42px;
padding: 0 16px;
border: 1px solid var(--line);
border-radius: 10px;
background: #142338;
color: var(--text);
cursor: pointer;
font-weight: 750;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.control:hover {
border-color: #4a6887;
background: #1a2d46;
transform: translateY(-1px);
}
.control.primary {
border-color: rgba(77, 227, 255, 0.65);
background: var(--cyan);
color: #07111e;
}
.stage {
position: relative;
height: min(68vh, 720px);
min-height: 510px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 18px;
background: #0b1523;
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}
#threeCanvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#threeCanvas:active {
cursor: grabbing;
}
.view-label {
position: absolute;
z-index: 2;
top: 16px;
left: 16px;
max-width: min(430px, calc(100% - 32px));
padding: 10px 13px;
border: 1px solid rgba(122, 157, 189, 0.25);
border-radius: 10px;
background: rgba(7, 17, 30, 0.78);
pointer-events: none;
backdrop-filter: blur(12px);
}
.view-label.world {
left: calc(var(--split, 66%) + 16px);
}
.view-label .kicker {
display: block;
margin-bottom: 4px;
color: var(--cyan);
font-size: 0.65rem;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.view-label.world .kicker {
color: var(--orange);
}
.view-label strong {
display: block;
font-size: 0.94rem;
}
.view-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.72rem;
}
.phase-badge {
position: absolute;
z-index: 2;
bottom: 16px;
left: 16px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(114, 230, 168, 0.38);
border-radius: 999px;
background: rgba(7, 17, 30, 0.8);
color: var(--green);
font-size: 0.7rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(10px);
}
.phase-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.camera-help {
position: absolute;
z-index: 2;
right: 16px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(122, 157, 189, 0.22);
border-radius: 9px;
background: rgba(7, 17, 30, 0.72);
color: var(--muted);
font-size: 0.68rem;
pointer-events: none;
}
.dashboard {
display: grid;
grid-template-columns: minmax(0, 1.65fr) minmax(310px, 0.8fr);
gap: 14px;
margin-top: 14px;
}
.card {
border: 1px solid var(--line);
border-radius: 15px;
background:
linear-gradient(145deg, rgba(20, 35, 56, 0.95), rgba(13, 25, 41, 0.95));
box-shadow: 0 15px 38px rgba(0, 0, 0, 0.16);
}
.chart-card {
min-width: 0;
padding: 16px 17px 13px;
}
.card-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 8px;
}
.card-heading h2,
.metrics h2 {
margin: 0;
font-size: 0.8rem;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 0.74rem;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
color: var(--muted);
font-size: 0.69rem;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend i {
width: 15px;
height: 3px;
background: currentColor;
}
.legend .bus {
color: var(--orange);
}
.legend .block {
color: var(--cyan);
}
#chart {
display: block;
width: 100%;
height: 300px;
}
.timeline {
position: relative;
height: 24px;
margin-top: 3px;
border-radius: 7px;
background: #091523;
overflow: hidden;
}
.timeline-segment {
position: absolute;
top: 0;
bottom: 0;
border-right: 1px solid rgba(255, 255, 255, 0.13);
}
.timeline-segment span {
position: absolute;
top: 7px;
left: 8px;
color: rgba(255, 255, 255, 0.63);
font-size: 0.57rem;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.timeline-marker {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
width: 3px;
background: white;
box-shadow: 0 0 12px rgba(255, 255, 255, 0.7);
transform: translateX(-50%);
}
.metrics {
padding: 17px;
}
.metrics h2 {
margin-bottom: 13px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-width: 0;
padding: 12px;
border: 1px solid rgba(122, 157, 189, 0.14);
border-radius: 11px;
background: rgba(6, 16, 28, 0.46);
}
.metric-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 0.62rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: var(--text);
font-size: clamp(1rem, 2vw, 1.35rem);
font-variant-numeric: tabular-nums;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-value.cyan {
color: var(--cyan);
}
.metric-value.orange {
color: var(--orange);
}
.explanation {
min-height: 83px;
margin: 12px 0 0;
padding: 12px;
border-left: 3px solid var(--cyan);
border-radius: 0 9px 9px 0;
background: rgba(77, 227, 255, 0.055);
color: #b8c9da;
font-size: 0.76rem;
line-height: 1.55;
}
.explanation strong {
color: var(--text);
}
.note {
margin: 11px 0 0;
color: #70889f;
font-size: 0.66rem;
line-height: 1.45;
}
@media (max-width: 980px) {
body {
padding: 14px;
}
header {
align-items: flex-start;
flex-direction: column;
}
.dashboard {
grid-template-columns: 1fr;
}
.stage {
height: 680px;
}
.view-label.world {
left: 16px;
top: calc(var(--world-top, 58%) + 16px);
}
.camera-help {
display: none;
}
}
@media (max-width: 560px) {
.controls {
width: 100%;
}
.control {
flex: 1;
}
.stage {
min-height: 650px;
}
.view-label {
max-width: calc(100% - 32px);
}
#chart {
height: 270px;
}
.metric-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div>
<div class="eyebrow">Inertia Lab / Voxel Mechanics</div>
<h1>What moves when the bus moves?</h1>
<p class="subtitle">
A freely sliding block stays with the bus only because the tray pushes it.
Compare its absolute ground-frame path with its position relative to the bus.
</p>
</div>
<div class="controls">
<button id="playButton" class="control primary" type="button">Pause</button>
<button id="resetButton" class="control" type="button">Restart drive</button>
</div>
</header>
<section id="stage" class="stage" aria-label="Interactive bus inertia demonstration">
<canvas id="threeCanvas"></canvas>
<div id="interiorLabel" class="view-label">
<span class="kicker">01 / Bus frame</span>
<strong>The bus is stationary; watch the block slide.</strong>
<small>Cyan arrow indicates relative acceleration.</small>
</div>
<div id="worldLabel" class="view-label world">
<span class="kicker">02 / Ground frame</span>
<strong>The world is stationary; the bus travels right.</strong>
<small>Road ticks provide a fixed reference.</small>
</div>
<div class="phase-badge">
<span class="phase-dot"></span>
<span id="phaseText">Accelerating</span>
</div>
<div class="camera-help">Drag interior to orbit · scroll to zoom</div>
</section>
<section class="dashboard">
<div class="card chart-card">
<div class="card-heading">
<div>
<h2>Frame comparison</h2>
<p>Position history, plotted against time</p>
</div>
<div class="legend">
<span class="bus"><i></i> Bus</span>
<span class="block"><i></i> Toy block</span>
</div>
</div>
<canvas id="chart" aria-label="Ground frame and bus frame position graphs"></canvas>
<div class="timeline" aria-label="Drive cycle timeline">
<div class="timeline-segment" style="left:0; width:9.5%; background:#284057">
<span>Idle</span>
</div>
<div class="timeline-segment" style="left:9.5%; width:23.8%; background:#1d5264">
<span>Accelerate</span>
</div>
<div class="timeline-segment" style="left:33.3%; width:23.8%; background:#334e39">
<span>Coast</span>
</div>
<div class="timeline-segment" style="left:57.1%; width:23.8%; background:#61422d">
<span>Brake</span>
</div>
<div class="timeline-segment" style="left:80.9%; width:19.1%; background:#26374b"></div>
<div id="timelineMarker" class="timeline-marker" style="left:0%"></div>
</div>
</div>
<aside class="card metrics">
<h2>Live measurements</h2>
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Bus position</span>
<span id="busPosition" class="metric-value orange">0.00 m</span>
</div>
<div class="metric">
<span class="metric-label">Block ground position</span>
<span id="groundPosition" class="metric-value cyan">0.00 m</span>
</div>
<div class="metric">
<span class="metric-label">Block relative position</span>
<span id="relativePosition" class="metric-value">0.00 m</span>
</div>
<div class="metric">
<span class="metric-label">Bus speed</span>
<span id="busSpeed" class="metric-value">0.00 m/s</span>
</div>
<div class="metric">
<span class="metric-label">Block ground speed</span>
<span id="blockSpeed" class="metric-value">0.00 m/s</span>
</div>
<div class="metric">
<span class="metric-label">Distance behind bus</span>
<span id="lagDistance" class="metric-value">0.00 m</span>
</div>
</div>
<p id="explanation" class="explanation">
<strong>The bus accelerates.</strong>
Its tray pushes the block forward, so the block begins moving with the bus.
</p>
<p class="note">
Model: rigid bus, low-friction tray (μ ≈ 0.066), 1D motion.
The block’s relative motion is integrated from
a<sub>relative</sub> = −a<sub>bus</sub> − friction.
</p>
</aside>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and shared constants
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const canvas = document.getElementById("threeCanvas");
const chartCanvas = document.getElementById("chart");
const chartContext = chartCanvas.getContext("2d");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const phaseText = document.getElementById("phaseText");
const phaseDot = document.querySelector(".phase-dot");
const timelineMarker = document.getElementById("timelineMarker");
const busPositionElement = document.getElementById("busPosition");
const groundPositionElement = document.getElementById("groundPosition");
const relativePositionElement = document.getElementById("relativePosition");
const busSpeedElement = document.getElementById("busSpeed");
const blockSpeedElement = document.getElementById("blockSpeed");
const lagDistanceElement = document.getElementById("lagDistance");
const explanationElement = document.getElementById("explanation");
const COLORS = {
background: 0x0b1523,
worldBackground: 0x09121e,
floor: 0x31465a,
floorAlt: 0x385068,
teal: 0x197b83,
tealDark: 0x11565f,
orange: 0xf28c38,
orangeDark: 0xb75e27,
navy: 0x122236,
seat: 0x326b9e,
seatDark: 0x244d76,
tray: 0x73879a,
trayDark: 0x465b6e,
yellow: 0xffcf4d,
yellowDark: 0xd89722,
cyan: 0x4de3ff,
window: 0x193a52,
tire: 0x101720,
tireAlt: 0x202c38,
road: 0x202b35,
white: 0xd9e7f2
};
const DRIVE_DURATION = 8.5;
const FIXED_STEP = 1 / 120;
const FRICTION_ACCELERATION = 0.65; // μg in m/s²
const TRAY_LIMIT = 3.58;
const phaseBands = [
{ start: 0.0, end: 0.8, name: "Ready" },
{ start: 0.8, end: 2.8, name: "Accelerating" },
{ start: 2.8, end: 4.8, name: "Coasting" },
{ start: 4.8, end: 6.8, name: "Braking" },
{ start: 6.8, end: 8.5, name: "Settling" }
];
// -------------------------------------------------------------------------
// Three.js renderer and scenes
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const interiorScene = new THREE.Scene();
interiorScene.background = new THREE.Color(COLORS.background);
interiorScene.fog = new THREE.Fog(0x0b1523, 21, 38);
const worldScene = new THREE.Scene();
worldScene.background = new THREE.Color(COLORS.worldBackground);
worldScene.fog = new THREE.Fog(0x09121e, 25, 48);
const interiorCamera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const worldCamera = new THREE.PerspectiveCamera(36, 1, 0.1, 120);
const hemisphere = new THREE.HemisphereLight(0xbfe8ff, 0x243041, 2.15);
interiorScene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffffff, 3.1);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
interiorScene.add(sun);
const interiorFill = new THREE.DirectionalLight(0x55dfff, 1.25);
interiorFill.position.set(-8, 6, -7);
interiorScene.add(interiorFill);
const worldHemisphere = new THREE.HemisphereLight(0xccecff, 0x1a2532, 2.1);
worldScene.add(worldHemisphere);
const worldSun = new THREE.DirectionalLight(0xffffff, 2.8);
worldSun.position.set(10, 17, 11);
worldSun.castShadow = true;
worldSun.shadow.mapSize.set(2048, 2048);
worldSun.shadow.camera.left = -18;
worldSun.shadow.camera.right = 18;
worldSun.shadow.camera.top = 13;
worldSun.shadow.camera.bottom = -13;
worldSun.shadow.camera.near = 1;
worldSun.shadow.camera.far = 55;
worldSun.shadow.normalBias = 0.03;
worldScene.add(worldSun);
// -------------------------------------------------------------------------
// Voxel construction helpers
// -------------------------------------------------------------------------
const unitCube = new THREE.BoxGeometry(1, 1, 1);
const unitEdges = new THREE.EdgesGeometry(unitCube);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x07111e,
transparent: true,
opacity: 0.42
});
const materialCache = new Map();
function getMaterial(color, opacity = 1, basic = false) {
const key = `${color}_${opacity}_${basic}`;
if (!materialCache.has(key)) {
const parameters = { color };
if (basic) {
materialCache.set(
key,
new THREE.MeshBasicMaterial({
...parameters,
transparent: opacity < 1,
opacity,
depthWrite: opacity === 1
})
);
} else {
materialCache.set(
key,
new THREE.MeshLambertMaterial({
...parameters,
transparent: opacity < 1,
opacity,
depthWrite: opacity === 1
})
);
}
}
return materialCache.get(key);
}
function addBlock(
parent,
size,
position,
color,
options = {}
) {
const mesh = new THREE.Mesh(
unitCube,
getMaterial(color, options.opacity ?? 1, options.basic ?? false)
);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.shadow ?? true;
mesh.receiveShadow = options.shadow ?? true;
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] ?? 0,
options.rotation[1] ?? 0,
options.rotation[2] ?? 0
);
}
if (options.edges) {
const outline = new THREE.LineSegments(unitEdges, edgeMaterial);
mesh.add(outline);
}
parent.add(mesh);
return mesh;
}
function addVoxelWheel(parent, x, y, z, hubColor) {
const wheel = new THREE.Group();
for (let gx = -2; gx <= 2; gx++) {
for (let gy = -2; gy <= 2; gy++) {
if (gx * gx + gy * gy > 5) continue;
addBlock(
wheel,
[0.235, 0.235, 0.34],
[gx * 0.235, gy * 0.235, 0],
(gx + gy) % 2 === 0 ? COLORS.tire : COLORS.tireAlt,
{ shadow: true }
);
}
}
addBlock(
wheel,
[0.28, 0.28, 0.39],
[0, 0, 0],
hubColor,
{ edges: true }
);
wheel.position.set(x, y, z);
parent.add(wheel);
}
function makeToyBlock() {
const toy = new THREE.Group();
addBlock(
toy,
[0.92, 0.92, 0.92],
[0, 0, 0],
COLORS.yellow,
{ edges: true }
);
// Contrasting voxel details on the visible faces.
addBlock(
toy,
[0.38, 0.38, 0.045],
[0.18, 0.16, 0.482],
COLORS.yellowDark,
{ shadow: false }
);
addBlock(
toy,
[0.24, 0.48, 0.46],
[0.482, -0.12, 0],
COLORS.orange,
{ shadow: false }
);
// Four studs made from small cubes.
const studPositions = [
[-0.24, -0.24],
[0.24, -0.24],
[-0.24, 0.24],
[0.24, 0.24]
];
for (const [sx, sz] of studPositions) {
addBlock(
toy,
[0.18, 0.12, 0.18],
[sx, 0.51, sz],
COLORS.yellow,
{ shadow: false }
);
}
toy.position.set(0, 1.02, 1.18);
return toy;
}
function makeStepArrow(color) {
const arrow = new THREE.Group();
addBlock(
arrow,
[1.55, 0.13, 0.13],
[0.25, 0, 0],
color,
{ basic: true, shadow: false }
);
// Stepped arrowhead keeps the voxel visual language.
addBlock(
arrow,
[0.22, 0.22, 0.22],
[1.12, 0.10, 0],
color,
{ basic: true, shadow: false }
);
addBlock(
arrow,
[0.22, 0.22, 0.22],
[1.34, 0.10, 0],
color,
{ basic: true, shadow: false }
);
addBlock(
arrow,
[0.22, 0.22, 0.22],
[1.56, 0.10, 0],
color,
{ basic: true, shadow: false }
);
addBlock(
arrow,
[0.22, 0.22, 0.22],
[1.34, 0.32, 0],
color,
{ basic: true, shadow: false }
);
addBlock(
arrow,
[0.22, 0.22, 0.22],
[1.12, 0.32, 0],
color,
{ basic: true, shadow: false }
);
return arrow;
}
function addSeat(parent, x, z, color = COLORS.seat) {
addBlock(
parent,
[1.25, 0.42, 1.08],
[x, 0.48, z],
color,
{ edges: true }
);
addBlock(
parent,
[1.25, 1.18, 0.25],
[x, 1.13, z - 0.43],
COLORS.seatDark,
{ edges: true }
);
addBlock(
parent,
[0.66, 0.31, 0.24],
[x, 1.84, z - 0.43],
color,
{ edges: true }
);
}
function createBus(includeSeats) {
const bus = new THREE.Group();
// Chassis and tiled floor.
addBlock(
bus,
[12.25, 0.36, 5.1],
[0, 0, 0],
COLORS.navy,
{ edges: true }
);
for (let ix = 0; ix < 16; ix++) {
for (let iz = 0; iz < 6; iz++) {
const x = (ix - 7.5) * 0.74;
const z = (iz - 2.5) * 0.78;
const color = (ix + iz) % 2 === 0 ? COLORS.floor : COLORS.floorAlt;
addBlock(
bus,
[0.68, 0.075, 0.68],
[x, 0.215, z],
color,
{ shadow: false }
);
}
}
// Far-side body panels.
addBlock(
bus,
[12.15, 0.95, 0.2],
[0, 0.69, -2.55],
COLORS.teal,
{ edges: true }
);
addBlock(
bus,
[12.15, 0.2, 0.25],
[0, 1.25, -2.55],
COLORS.tealDark,
{ edges: true }
);
// Near-side cutaway sill.
addBlock(
bus,
[12.15, 0.43, 0.22],
[0, 0.48, 2.55],
COLORS.orange,
{ edges: true }
);
// Window row and pillars.
const windowXs = [-4.85, -2.43, 0, 2.43, 4.85];
for (const x of windowXs) {
addBlock(
bus,
[1.88, 0.95, 0.08],
[x, 1.88, -2.59],
COLORS.window,
{ opacity: 0.92, shadow: false }
);
}
for (const x of [-5.95, -3.64, -1.21, 1.21, 3.64, 5.95]) {
addBlock(
bus,
[0.19, 1.4, 0.27],
[x, 1.8, -2.58],
COLORS.orange,
{ edges: true }
);
}
// Roof rails leave the interior visible.
addBlock(
bus,
[12.25, 0.17, 0.18],
[0, 2.67, -2.55],
COLORS.orange,
{ edges: true }
);
addBlock(
bus,
[12.25, 0.15, 0.16],
[0, 2.67, 2.55],
COLORS.orangeDark,
{ edges: true }
);
// Front and rear end blocks.
addBlock(
bus,
[0.22, 0.8, 5.15],
[6.02, 0.58, 0],
COLORS.orange,
{ edges: true }
);
addBlock(
bus,
[0.13, 1.35, 3.9],
[6.05, 1.67, -0.45],
COLORS.window,
{ opacity: 0.44, shadow: false }
);
addBlock(
bus,
[0.22, 2.65, 0.22],
[6.03, 1.5, -2.55],
COLORS.orangeDark,
{ edges: true }
);
addBlock(
bus,
[0.22, 2.65, 0.22],
[6.03, 1.5, 2.55],
COLORS.orangeDark,
{ edges: true }
);
addBlock(
bus,
[0.24, 2.45, 5.15],
[-6.02, 1.4, 0],
COLORS.tealDark,
{ opacity: 0.94, edges: true }
);
// Voxel wheels.
for (const x of [-4.1, 4.1]) {
addVoxelWheel(bus, x, -0.13, -2.72, COLORS.yellowDark);
addVoxelWheel(bus, x, -0.13, 2.72, COLORS.yellowDark);
}
// Low-friction tray.
addBlock(
bus,
[7.45, 0.2, 2.2],
[0, 0.43, 1.18],
COLORS.tray,
{ edges: true }
);
addBlock(
bus,
[7.55, 0.13, 0.12],
[0, 0.61, 0.11],
COLORS.trayDark,
{ edges: true }
);
addBlock(
bus,
[7.55, 0.13, 0.12],
[0, 0.61, 2.25],
COLORS.trayDark,
{ edges: true }
);
for (const x of [-3.76, 3.76]) {
addBlock(
bus,
[0.13, 0.42, 2.23],
[x, 0.68, 1.18],
COLORS.orangeDark,
{ edges: true }
);
}
// Cyan position marks on the tray.
for (let x = -3.5; x <= 3.5; x += 0.5) {
addBlock(
bus,
[0.08, 0.025, 0.55],
[x, 0.545, 1.18],
COLORS.cyan,
{ basic: true, shadow: false }
);
}
if (includeSeats) {
addSeat(bus, -4.55, -1.35);
addSeat(bus, -2.75, -1.35);
addSeat(bus, 4.48, -1.35, COLORS.orange);
// Block-built steering wheel.
for (const [sx, sy] of [
[-0.22, 0], [0.22, 0], [0, 0.22], [0, -0.22]
]) {
addBlock(
bus,
[0.18, 0.18, 0.18],
[4.92 + sx, 1.48 + sy, -0.45],
COLORS.navy,
{ edges: true }
);
}
}
const toy = makeToyBlock();
bus.add(toy);
return { bus, toy };
}
const interiorBus = createBus(true);
interiorScene.add(interiorBus.bus);
const relativeArrow = makeStepArrow(COLORS.cyan);
relativeArrow.position.set(1.35, 1.63, 1.18);
interiorBus.bus.add(relativeArrow);
const driveArrow = makeStepArrow(COLORS.orange);
driveArrow.position.set(3.7, 2.1, 1.2);
interiorBus.bus.add(driveArrow);
// A dark display platform beneath the cutaway bus.
addBlock(
interiorScene,
[22, 0.3, 12],
[0, -0.72, 0],
0x0e1b29,
{ shadow: false }
);
// -------------------------------------------------------------------------
// Ground-frame scene
// -------------------------------------------------------------------------
const road = addBlock(
worldScene,
[30, 0.22, 9],
[4, -0.28, 0],
COLORS.road,
{ shadow: false }
);
road.receiveShadow = true;
addBlock(
worldScene,
[30, 0.32, 1.1],
[4, -0.22, 3.65],
0x354657,
{ shadow: false }
);
for (let x = -8; x <= 18; x += 2.5) {
addBlock(
worldScene,
[1.35, 0.035, 0.13],
[x, -0.155, -3.28],
0xd8c78e,
{ basic: true, shadow: false }
);
}
// Fixed world ruler.
for (let x = -2; x <= 15; x++) {
const major = x % 2 === 0;
addBlock(
worldScene,
[major ? 0.1 : 0.07, major ? 0.42 : 0.25, 0.12],
[x, -0.02, 3.12],
major ? COLORS.white : 0x778b9e,
{ basic: true, shadow: false }
);
}
// World origin marker.
addBlock(
worldScene,
[0.18, 1.25, 0.18],
[0, 0.45, 3.12],
COLORS.white,
{ basic: true, shadow: false }
);
const worldBus = createBus(false);
worldScene.add(worldBus.bus);
const worldBusMarker = addBlock(
worldScene,
[0.62, 0.12, 0.62],
[0, -0.06, 3.12],
COLORS.orange,
{ basic: true, shadow: false }
);
const worldBlockMarker = addBlock(
worldScene,
[0.62, 0.12, 0.62],
[0, -0.04, 3.12],
COLORS.cyan,
{ basic: true, shadow: false }
);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.85, 0),
radius: 15.2,
yaw: 0.62,
pitch: 0.47,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateInteriorCamera() {
const horizontalRadius =
orbit.radius * Math.cos(orbit.pitch);
interiorCamera.position.set(
orbit.target.x + horizontalRadius * Math.sin(orbit.yaw),
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z + horizontalRadius * Math.cos(orbit.yaw)
);
interiorCamera.lookAt(orbit.target);
}
updateInteriorCamera();
worldCamera.position.set(18, 11.5, 22);
worldCamera.lookAt(4.7, 0.55, 0);
let layout = {
width: 1,
height: 1,
mobile: false,
interiorWidth: 1,
interiorHeight: 1,
worldWidth: 1,
worldHeight: 1
};
function isInteriorPointer(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
const x = clientX - rect.left;
const y = clientY - rect.top;
if (layout.mobile) {
return y <= layout.interiorHeight;
}
return x <= layout.interiorWidth;
}
canvas.addEventListener("pointerdown", (event) => {
if (!isInteriorPointer(event.clientX, event.clientY)) return;
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.005,
0.18,
1.03
);
updateInteriorCamera();
});
function endDrag(event) {
orbit.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
if (!isInteriorPointer(event.clientX, event.clientY)) return;
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
9.5,
23
);
updateInteriorCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Simulation
// -------------------------------------------------------------------------
const simulation = {
time: 0,
busX: 0,
busVelocity: 0,
relativeX: 0,
relativeVelocity: 0,
relativeAcceleration: 0,
running: true,
history: []
};
function busAccelerationAt(time) {
if (time >= 0.8 && time < 2.8) return 1.2;
if (time >= 4.8 && time < 6.8) return -1.0;
return 0;
}
function phaseAt(time) {
for (const phase of phaseBands) {
if (time >= phase.start && time < phase.end) {
return phase;
}
}
return phaseBands[phaseBands.length - 1];
}
function resetSimulation(autoplay = true) {
simulation.time = 0;
simulation.busX = 0;
simulation.busVelocity = 0;
simulation.relativeX = 0;
simulation.relativeVelocity = 0;
simulation.relativeAcceleration = 0;
simulation.running = autoplay;
simulation.history.length = 0;
simulation.history.push({
time: 0,
busX: 0,
blockGroundX: 0,
relativeX: 0
});
updatePlayButton();
}
function updatePlayButton() {
playButton.textContent = simulation.running ? "Pause" : "Resume";
if (!simulation.running && simulation.time >= DRIVE_DURATION) {
playButton.textContent = "Run again";
}
}
function integrateSimulation(dt) {
const busAcceleration = busAccelerationAt(simulation.time);
const previousRelativeVelocity = simulation.relativeVelocity;
// Ground-frame bus motion.
simulation.busX +=
simulation.busVelocity * dt +
0.5 * busAcceleration * dt * dt;
simulation.busVelocity += busAcceleration * dt;
// Relative block dynamics with Coulomb friction.
if (Math.abs(simulation.relativeVelocity) > 0.0001) {
const frictionAcceleration =
-FRICTION_ACCELERATION *
Math.sign(simulation.relativeVelocity);
simulation.relativeAcceleration =
-busAcceleration + frictionAcceleration;
} else {
if (Math.abs(busAcceleration) <= FRICTION_ACCELERATION) {
// Static friction is sufficient: no relative sliding.
simulation.relativeAcceleration = 0;
} else {
// Friction acts in the direction opposing incipient relative motion.
simulation.relativeAcceleration =
-busAcceleration +
FRICTION_ACCELERATION * Math.sign(busAcceleration);
}
}
simulation.relativeX +=
simulation.relativeVelocity * dt +
0.5 * simulation.relativeAcceleration * dt * dt;
simulation.relativeVelocity +=
simulation.relativeAcceleration * dt;
// During coasting, stop exactly when relative velocity reaches zero.
if (
previousRelativeVelocity < 0 &&
simulation.relativeVelocity > 0 &&
Math.abs(busAcceleration) <= FRICTION_ACCELERATION
) {
simulation.relativeVelocity = 0;
simulation.relativeAcceleration = 0;
}
// End stops on the tray.
if (simulation.relativeX < -TRAY_LIMIT) {
simulation.relativeX = -TRAY_LIMIT;
simulation.relativeVelocity = Math.max(
0,
simulation.relativeVelocity * -0.08
);
} else if (simulation.relativeX > TRAY_LIMIT) {
simulation.relativeX = TRAY_LIMIT;
simulation.relativeVelocity = Math.min(
0,
simulation.relativeVelocity * -0.08
);
}
simulation.time += dt;
if (
simulation.history.length === 0 ||
simulation.time - simulation.history[simulation.history.length - 1].time >= 0.045
) {
simulation.history.push({
time: simulation.time,
busX: simulation.busX,
blockGroundX: simulation.busX + simulation.relativeX,
relativeX: simulation.relativeX
});
}
if (simulation.time >= DRIVE_DURATION) {
simulation.time = DRIVE_DURATION;
simulation.running = false;
updatePlayButton();
}
}
// -------------------------------------------------------------------------
// Visual updates
// -------------------------------------------------------------------------
function updateVisuals() {
const groundX = simulation.busX + simulation.relativeX;
interiorBus.toy.position.x = simulation.relativeX;
worldBus.toy.position.x = simulation.relativeX;
worldBus.bus.position.x = simulation.busX;
worldBusMarker.position.x = simulation.busX;
worldBlockMarker.position.x = groundX;
const acceleration = busAccelerationAt(simulation.time);
driveArrow.visible = Math.abs(acceleration) > 0.01;
driveArrow.rotation.y = acceleration > 0 ? 0 : Math.PI;
relativeArrow.visible =
Math.abs(simulation.relativeAcceleration) > 0.025;
relativeArrow.rotation.y =
simulation.relativeAcceleration > 0 ? 0 : Math.PI;
// Small vertical bob makes the toy feel less mechanically locked to the tray.
const movementAmount = Math.min(
1,
Math.abs(simulation.relativeVelocity) * 0.055
);
interiorBus.toy.rotation.z =
Math.sin(simulation.time * 12) * 0.018 * movementAmount;
worldBus.toy.rotation.z =
interiorBus.toy.rotation.z;
const phase = phaseAt(simulation.time);
phaseText.textContent = phase.name;
timelineMarker.style.left =
`${(simulation.time / DRIVE_DURATION) * 100}%`;
let phaseColor = "#72e6a8";
if (phase.name === "Accelerating") phaseColor = "#4de3ff";
if (phase.name === "Coasting") phaseColor = "#ffb454";
if (phase.name === "Braking") phaseColor = "#ff7185";
if (phase.name === "Settling") phaseColor = "#a6b7c9";
phaseDot.style.color = phaseColor;
phaseText.parentElement.style.color = phaseColor;
busPositionElement.textContent = `${simulation.busX.toFixed(2)} m`;
groundPositionElement.textContent = `${groundX.toFixed(2)} m`;
relativePositionElement.textContent =
`${simulation.relativeX >= 0 ? "+" : ""}${simulation.relativeX.toFixed(2)} m`;
busSpeedElement.textContent =
`${simulation.busVelocity.toFixed(2)} m/s`;
blockSpeedElement.textContent =
`${(simulation.busVelocity + simulation.relativeVelocity).toFixed(2)} m/s`;
lagDistanceElement.textContent =
`${(simulation.busX - groundX).toFixed(2)} m`;
if (phase.name === "Accelerating") {
explanationElement.innerHTML =
"<strong>The bus accelerates.</strong> " +
"The tray pushes the block forward, but the block initially lags. " +
"In the bus frame it slides backward; in the ground frame it still moves forward, just slower than the bus.";
} else if (phase.name === "Coasting") {
explanationElement.innerHTML =
"<strong>The bus coasts at constant speed.</strong> " +
"The block keeps moving because no net force is required for constant velocity. " +
"Low-friction contact gradually brings its motion back into alignment with the bus.";
} else if (phase.name === "Braking") {
explanationElement.innerHTML =
"<strong>The bus slows down.</strong> " +
"The block tends to keep moving forward. Relative to the decelerating bus, " +
"it therefore slides toward the front of the tray.";
} else if (phase.name === "Settling") {
explanationElement.innerHTML =
"<strong>The system settles.</strong> " +
"Friction removes the remaining relative velocity. " +
"In the ground frame the bus and block now travel together at the same speed.";
} else {
explanationElement.innerHTML =
"<strong>Ready.</strong> " +
"Press Resume or restart the drive. The bus will accelerate, coast, and brake.";
}
}
// -------------------------------------------------------------------------
// Frame-comparison chart
// -------------------------------------------------------------------------
function drawChart() {
const width = chartCanvas.clientWidth;
const height = chartCanvas.clientHeight;
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const pixelWidth = Math.max(1, Math.round(width * dpr));
const pixelHeight = Math.max(1, Math.round(height * dpr));
if (
chartCanvas.width !== pixelWidth ||
chartCanvas.height !== pixelHeight
) {
chartCanvas.width = pixelWidth;
chartCanvas.height = pixelHeight;
}
const context = chartContext;
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, width, height);
const margin = { left: 48, right: 18, top: 31, bottom: 27 };
const gap = 27;
const plotWidth = Math.max(1, width - margin.left - margin.right);
const plotHeight =
Math.max(1, height - margin.top - margin.bottom - gap) / 2;
const groundMin = 0;
const groundMax = Math.max(12, simulation.busX + 1.4);
const relativeMin = -2.7;
const relativeMax = 1.2;
const mapX = (time) =>
margin.left + (time / DRIVE_DURATION) * plotWidth;
const mapGroundY = (value) =>
margin.top +
plotHeight -
((value - groundMin) / (groundMax - groundMin)) * plotHeight;
const relativeTop = margin.top + plotHeight + gap;
const mapRelativeY = (value) =>
relativeTop +
plotHeight -
((value - relativeMin) / (relativeMax - relativeMin)) * plotHeight;
function drawGrid(min, max, mapY, top) {
context.save();
context.strokeStyle = "rgba(145, 167, 189, 0.12)";
context.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const value = min + ((max - min) * i) / 4;
const y = mapY(value);
context.beginPath();
context.moveTo(margin.left, y);
context.lineTo(width - margin.right, y);
context.stroke();
context.fillStyle = "#71889e";
context.font = "10px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "right";
context.textBaseline = "middle";
context.fillText(value.toFixed(1), margin.left - 9, y);
}
context.strokeStyle = "rgba(145, 167, 189, 0.08)";
for (const time of [0, 2, 4, 6, 8]) {
const x = mapX(time);
context.beginPath();
context.moveTo(x, top);
context.lineTo(x, top + plotHeight);
context.stroke();
}
context.restore();
}
function drawHistory(key, color, mapY, top) {
context.save();
context.strokeStyle = color;
context.lineWidth = 2.35;
context.lineJoin = "round";
context.lineCap = "round";
context.beginPath();
simulation.history.forEach((sample, index) => {
const x = mapX(sample.time);
const y = mapY(sample[key]);
if (index === 0) context.moveTo(x, y);
else context.lineTo(x, y);
});
context.stroke();
context.restore();
}
// Panel backgrounds.
context.fillStyle = "rgba(5, 14, 25, 0.32)";
context.fillRect(
margin.left,
margin.top,
plotWidth,
plotHeight
);
context.fillRect(
margin.left,
relativeTop,
plotWidth,
plotHeight
);
drawGrid(
groundMin,
groundMax,
mapGroundY,
margin.top
);
drawGrid(
relativeMin,
relativeMax,
mapRelativeY,
relativeTop
);
// Labels.
context.font = "700 10px ui-sans-serif, system-ui, sans-serif";
context.textAlign = "left";
context.textBaseline = "top";
context.fillStyle = "#c7d7e6";
context.fillText(
"GROUND FRAME / absolute position",
margin.left,
7
);
context.fillStyle = "#91a7bd";
context.fillText(
"BUS FRAME / relative position",
margin.left,
relativeTop - 20
);
context.font = "10px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillStyle = "#6f879d";
context.textAlign = "right";
context.fillText(
"time →",
width - margin.right,
height - 15
);
// Phase boundaries.
context.save();
context.setLineDash([3, 5]);
context.strokeStyle = "rgba(255, 255, 255, 0.16)";
for (const time of [0.8, 2.8, 4.8, 6.8]) {
const x = mapX(time);
context.beginPath();
context.moveTo(x, margin.top);
context.lineTo(x, margin.top + plotHeight);
context.moveTo(x, relativeTop);
context.lineTo(x, relativeTop + plotHeight);
context.stroke();
}
context.restore();
// Ground-frame paths.
drawHistory("busX", "#ffb454", mapGroundY, margin.top);
drawHistory(
"blockGroundX",
"#4de3ff",
mapGroundY,
margin.top
);
// Bus-frame paths.
context.save();
context.strokeStyle = "#ffb454";
context.lineWidth = 2.35;
context.beginPath();
context.moveTo(mapX(0), mapRelativeY(0));
context.lineTo(mapX(DRIVE_DURATION), mapRelativeY(0));
context.stroke();
context.restore();
drawHistory(
"relativeX",
"#4de3ff",
mapRelativeY,
relativeTop
);
// Current-time cursor.
const cursorX = mapX(simulation.time);
context.save();
context.strokeStyle = "rgba(255,255,255,0.38)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(cursorX, margin.top);
context.lineTo(cursorX, margin.top + plotHeight);
context.moveTo(cursorX, relativeTop);
context.lineTo(cursorX, relativeTop + plotHeight);
context.stroke();
context.restore();
function drawCurrentDot(value, y, color) {
context.save();
context.fillStyle = color;
context.strokeStyle = "#081522";
context.lineWidth = 2;
context.beginPath();
context.arc(cursorX, y, 4.6, 0, Math.PI * 2);
context.fill();
context.stroke();
context.restore();
}
const lastSample =
simulation.history[simulation.history.length - 1] || {
busX: simulation.busX,
blockGroundX: simulation.busX + simulation.relativeX,
relativeX: simulation.relativeX
};
drawCurrentDot(
lastSample.busX,
mapGroundY(lastSample.busX),
"#ffb454"
);
drawCurrentDot(
lastSample.blockGroundX,
mapGroundY(lastSample.blockGroundX),
"#4de3ff"
);
drawCurrentDot(
lastSample.relativeX,
mapRelativeY(lastSample.relativeX),
"#4de3ff"
);
}
// -------------------------------------------------------------------------
// Layout and rendering
// -------------------------------------------------------------------------
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const mobile = width < 980;
layout.mobile = mobile;
layout.width = width;
layout.height = height;
if (mobile) {
layout.interiorWidth = width;
layout.interiorHeight = Math.floor(height * 0.58);
layout.worldWidth = width;
layout.worldHeight = height - layout.interiorHeight;
stage.style.setProperty("--split", "0%");
stage.style.setProperty("--world-top", "58%");
} else {
layout.interiorWidth = Math.floor(width * 0.66);
layout.interiorHeight = height;
layout.worldWidth = width - layout.interiorWidth;
layout.worldHeight = height;
stage.style.setProperty("--split", "66%");
stage.style.setProperty("--world-top", "0%");
}
renderer.setSize(width, height, false);
interiorCamera.aspect =
layout.interiorWidth / Math.max(1, layout.interiorHeight);
interiorCamera.updateProjectionMatrix();
worldCamera.aspect =
layout.worldWidth / Math.max(1, layout.worldHeight);
worldCamera.updateProjectionMatrix();
updateInteriorCamera();
}
function renderScenes() {
renderer.setScissorTest(true);
if (layout.mobile) {
// Interior on top.
renderer.setViewport(
0,
layout.worldHeight,
layout.interiorWidth,
layout.interiorHeight
);
renderer.setScissor(
0,
layout.worldHeight,
layout.interiorWidth,
layout.interiorHeight
);
renderer.render(interiorScene, interiorCamera);
// Ground frame below.
renderer.setViewport(
0,
0,
layout.worldWidth,
layout.worldHeight
);
renderer.setScissor(
0,
0,
layout.worldWidth,
layout.worldHeight
);
renderer.render(worldScene, worldCamera);
} else {
// Interior on the left.
renderer.setViewport(
0,
0,
layout.interiorWidth,
layout.interiorHeight
);
renderer.setScissor(
0,
0,
layout.interiorWidth,
layout.interiorHeight
);
renderer.render(interiorScene, interiorCamera);
// Ground frame on the right.
renderer.setViewport(
layout.interiorWidth,
0,
layout.worldWidth,
layout.worldHeight
);
renderer.setScissor(
layout.interiorWidth,
0,
layout.worldWidth,
layout.worldHeight
);
renderer.render(worldScene, worldCamera);
}
renderer.setScissorTest(false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resizeObserver.observe(chartCanvas.parentElement);
window.addEventListener("resize", resize);
playButton.addEventListener("click", () => {
if (simulation.time >= DRIVE_DURATION) {
resetSimulation(true);
return;
}
simulation.running = !simulation.running;
updatePlayButton();
});
resetButton.addEventListener("click", () => {
resetSimulation(true);
});
resetSimulation(true);
resize();
let previousTime = performance.now();
let accumulator = 0;
function animate(now) {
const frameDelta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (simulation.running) {
accumulator += frameDelta;
while (accumulator >= FIXED_STEP) {
integrateSimulation(FIXED_STEP);
accumulator -= FIXED_STEP;
}
} else {
accumulator = 0;
}
updateVisuals();
renderScenes();
drawChart();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```