Prompt specification
Build or customize the Three.js 3D scene "Two balls dropped and launched" 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: Two balls dropped and launched
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-balls-dropped-and-launched-x1418
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring projectile trajectories under gravity. Release one ball vertically and another horizontally from the same height at the same instant; show equal fall times under the stated no-drag model. Stylized solid forms.
Working Three.js Starter (two-balls-dropped-and-launched-x1418):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gravity Lab — Equal Fall Times</title>
<style>
:root {
--bg: #07111d;
--panel: rgba(9, 23, 39, 0.78);
--panel-solid: #0b1b2b;
--border: rgba(174, 205, 231, 0.16);
--text: #eff8ff;
--muted: #91a8bd;
--cyan: #43d9e9;
--cyan-soft: rgba(67, 217, 233, 0.14);
--orange: #ffb55c;
--orange-soft: rgba(255, 181, 92, 0.14);
--green: #73e0a5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
background:
radial-gradient(circle at 54% 42%, transparent 20%, rgba(2, 8, 15, 0.18) 78%),
linear-gradient(180deg, rgba(3, 10, 18, 0.12), rgba(3, 10, 18, 0.32));
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.header {
position: absolute;
top: 28px;
left: 30px;
max-width: 510px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(67, 217, 233, 0.65);
}
h1 {
margin: 0;
max-width: 470px;
font-size: clamp(27px, 3.2vw, 46px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
.intro {
max-width: 440px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.model-panel {
position: absolute;
top: 26px;
right: 26px;
width: 320px;
padding: 19px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.no-drag {
padding: 5px 8px;
border: 1px solid rgba(115, 224, 165, 0.28);
border-radius: 999px;
color: var(--green);
background: rgba(115, 224, 165, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.model-copy {
margin: 0 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.equations {
display: grid;
gap: 7px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 12px;
background: rgba(0, 0, 0, 0.13);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 11px;
color: #c9d8e5;
}
.equations span {
color: #7891a7;
}
.fall-result {
display: flex;
align-items: end;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--border);
}
.fall-result small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.fall-result strong {
font-size: 25px;
line-height: 1;
letter-spacing: -0.04em;
}
.fall-result strong em {
color: var(--muted);
font-size: 13px;
font-style: normal;
font-weight: 600;
}
.delta {
color: var(--green);
font-size: 11px;
font-weight: 750;
text-align: right;
}
.readouts {
position: absolute;
left: 26px;
bottom: 25px;
display: grid;
grid-template-columns: repeat(2, 205px);
gap: 10px;
}
.readout {
padding: 14px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
backdrop-filter: blur(16px);
}
.readout-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: 0 0 14px currentColor;
}
.vertical {
color: var(--orange);
}
.horizontal {
color: var(--cyan);
}
.readout-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric small {
display: block;
margin-bottom: 3px;
color: #718ba1;
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.metric b {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
font-weight: 650;
}
.progress {
height: 3px;
margin-top: 12px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.progress i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.controls-panel {
position: absolute;
right: 26px;
bottom: 25px;
width: 530px;
padding: 14px;
border: 1px solid var(--border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 11px;
color: var(--muted);
font-size: 11px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
font-weight: 700;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px rgba(67, 217, 233, 0.8);
}
.status.running .status-dot {
animation: pulse 0.8s ease-in-out infinite alternate;
}
.status.landed .status-dot {
background: var(--green);
box-shadow: 0 0 12px rgba(115, 224, 165, 0.8);
}
@keyframes pulse {
to {
opacity: 0.35;
transform: scale(0.75);
}
}
.timer {
color: var(--text);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 15px;
font-weight: 700;
}
.buttons {
display: grid;
grid-template-columns: 1.35fr 1fr 0.82fr;
gap: 8px;
}
button {
min-height: 42px;
border: 1px solid var(--border);
border-radius: 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.045em;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease,
opacity 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.28);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
opacity: 0.35;
cursor: default;
}
button.primary {
border-color: rgba(67, 217, 233, 0.4);
color: #06202a;
background: var(--cyan);
box-shadow: 0 7px 24px rgba(67, 217, 233, 0.16);
}
button.primary:hover:not(:disabled) {
background: #76e6f0;
}
.hint {
margin-top: 10px;
color: #617b91;
font-size: 9px;
text-align: center;
letter-spacing: 0.04em;
}
.ball-label {
position: absolute;
z-index: 4;
padding: 6px 9px;
border: 1px solid currentColor;
border-radius: 999px;
background: rgba(5, 15, 25, 0.84);
box-shadow: 0 6px 22px rgba(0, 0, 0, 0.24);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
opacity: 0;
}
.ball-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: currentColor;
opacity: 0.65;
}
@media (max-width: 1050px) {
.header {
max-width: 430px;
}
.model-panel {
width: 285px;
}
.readouts {
bottom: 106px;
}
.controls-panel {
left: 26px;
right: 26px;
width: auto;
}
}
@media (max-width: 720px) {
.header {
top: 18px;
left: 18px;
}
.intro {
display: none;
}
.model-panel {
top: 92px;
right: 14px;
width: 235px;
padding: 13px;
}
.model-copy,
.equations {
display: none;
}
.fall-result {
margin-top: 8px;
padding-top: 10px;
}
.fall-result strong {
font-size: 20px;
}
.readouts {
left: 14px;
right: 14px;
bottom: 108px;
grid-template-columns: 1fr 1fr;
}
.readout {
padding: 10px;
}
.controls-panel {
left: 14px;
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive Three.js projectile simulation"></div>
<div class="ui">
<header class="header">
<div class="eyebrow">Mechanics / Experiment 01</div>
<h1>Gravity doesn’t care about sideways speed.</h1>
<p class="intro">
One ball is dropped vertically. The other is launched horizontally from
the same height, at the same instant. With no air drag, they land together.
</p>
</header>
<aside class="model-panel">
<div class="panel-heading">
<strong>No-drag model</strong>
<span class="no-drag">g = 9.80 m/s²</span>
</div>
<p class="model-copy">
Both balls begin with zero vertical velocity. Horizontal velocity changes
only the horizontal coordinate, so both vertical motions are identical.
</p>
<div class="equations">
<div><span>y(t)</span> = 8.00 − ½(9.80)t²</div>
<div><span>x vertical</span> = −3.60</div>
<div><span>x horizontal</span> = 1.60 + 8.50t</div>
</div>
<div class="fall-result">
<div>
<small>Equal fall time</small>
<strong id="predicted-time">1.28 <em>s</em></strong>
</div>
<div class="delta" id="delta-result">
Δt = 0.00 s<br>
predicted
</div>
</div>
</aside>
<section class="readouts">
<div class="readout vertical">
<div class="readout-title">
<i class="dot"></i>
Vertical release
</div>
<div class="readout-grid">
<div class="metric">
<small>Position</small>
<b id="vertical-position">−3.60, 8.00</b>
</div>
<div class="metric">
<small>Velocity</small>
<b id="vertical-velocity">0.00, 0.00</b>
</div>
</div>
<div class="progress"><i id="vertical-progress"></i></div>
</div>
<div class="readout horizontal">
<div class="readout-title">
<i class="dot"></i>
Horizontal launch
</div>
<div class="readout-grid">
<div class="metric">
<small>Position</small>
<b id="horizontal-position">1.60, 8.00</b>
</div>
<div class="metric">
<small>Velocity</small>
<b id="horizontal-velocity">8.50, 0.00</b>
</div>
</div>
<div class="progress"><i id="horizontal-progress"></i></div>
</div>
</section>
<section class="controls-panel interactive">
<div class="status-row">
<div class="status" id="status">
<i class="status-dot"></i>
<span id="status-text">Ready — release both balls together</span>
</div>
<div class="timer" id="timer">t = 0.00 s</div>
</div>
<div class="buttons">
<button class="primary" id="release-button">▶ Release both</button>
<button id="pause-button" disabled>Pause</button>
<button id="reset-button">Reset</button>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom · Space to release/pause · R to reset
</div>
</section>
</div>
<div class="ball-label vertical" id="vertical-label">Vertical</div>
<div class="ball-label horizontal" id="horizontal-label">Horizontal</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Model constants
// ------------------------------------------------------------
const GRAVITY = 9.8;
const RELEASE_HEIGHT = 8.0;
const HORIZONTAL_SPEED = 8.5;
const BALL_RADIUS = 0.32;
const VERTICAL_X = -3.6;
const HORIZONTAL_X = 1.6;
// The ground surface is one radius below the landing ball center.
const GROUND_Y = -BALL_RADIUS;
const FALL_TIME = Math.sqrt(
(2 * RELEASE_HEIGHT) / GRAVITY
);
const HORIZONTAL_LANDING_X =
HORIZONTAL_X + HORIZONTAL_SPEED * FALL_TIME;
const COLORS = {
cyan: 0x43d9e9,
orange: 0xffb55c,
ground: 0x0b1b2b,
dark: 0x102638,
grid: 0x29445a,
white: 0xe8f6ff
};
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.018);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(3.5, 3.25, 0);
let cameraTheta = 0.58;
let cameraPhi = 1.08;
let cameraRadius = 22;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x +
cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z +
cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xb9e7ff,
0x08111b,
1.65
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 16, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 17;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.00035;
keyLight.target.position.set(3, 2, 0);
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0x3cbcff, 1.4);
rimLight.position.set(9, 7, -12);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffa64d, 24, 13, 2);
warmFill.position.set(-4, 8, 4);
scene.add(warmFill);
// ------------------------------------------------------------
// Ground and structural scene elements
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CylinderGeometry(22, 22, 0.5, 64),
new THREE.MeshStandardMaterial({
color: COLORS.ground,
roughness: 0.86,
metalness: 0.08
})
);
ground.position.set(3, GROUND_Y - 0.25, 0);
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 20, COLORS.grid, COLORS.grid);
grid.position.set(3, GROUND_Y + 0.012, 0);
grid.material.transparent = true;
grid.material.opacity = 0.17;
scene.add(grid);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(18, 0.035, 8, 120),
new THREE.MeshStandardMaterial({
color: 0x2f6177,
emissive: 0x123647,
emissiveIntensity: 0.65,
roughness: 0.5
})
);
rim.rotation.x = Math.PI / 2;
rim.position.set(3, GROUND_Y + 0.025, 0);
scene.add(rim);
function makeBox(width, height, depth, color) {
return new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({
color,
roughness: 0.6,
metalness: 0.18
})
);
}
function createLauncher(x, accentColor) {
const group = new THREE.Group();
group.position.x = x;
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x173044,
roughness: 0.45,
metalness: 0.55
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
emissive: accentColor,
emissiveIntensity: 0.38,
roughness: 0.36,
metalness: 0.35
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.9, 1.12, 0.24, 8),
frameMaterial
);
base.position.y = GROUND_Y + 0.12;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const columnHeight = RELEASE_HEIGHT - BALL_RADIUS - GROUND_Y;
for (const z of [-0.66, 0.66]) {
const column = makeBox(0.17, columnHeight, 0.17, 0x173044);
column.position.set(
0,
GROUND_Y + columnHeight / 2,
z
);
column.castShadow = true;
group.add(column);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.31, 0.12, 12),
frameMaterial
);
foot.position.set(0, GROUND_Y + 0.06, z);
foot.castShadow = true;
group.add(foot);
}
const topBeam = makeBox(0.17, 0.17, 1.5, 0x173044);
topBeam.position.set(
0,
RELEASE_HEIGHT - BALL_RADIUS,
0
);
topBeam.castShadow = true;
group.add(topBeam);
const releaseRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.065, 10, 40),
accentMaterial
);
releaseRing.rotation.x = Math.PI / 2;
releaseRing.position.y = RELEASE_HEIGHT - BALL_RADIUS;
releaseRing.castShadow = true;
group.add(releaseRing);
scene.add(group);
return { group, releaseRing, accentMaterial };
}
const verticalLauncher = createLauncher(
VERTICAL_X,
COLORS.orange
);
const horizontalLauncher = createLauncher(
HORIZONTAL_X,
COLORS.cyan
);
function createLandingMarker(x, color) {
const group = new THREE.Group();
group.position.set(x, GROUND_Y + 0.035, 0);
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.8, 0.055, 32),
new THREE.MeshStandardMaterial({
color: 0x102b3b,
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.65,
metalness: 0.25
})
);
pad.receiveShadow = true;
group.add(pad);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.055, 10, 40),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.72,
roughness: 0.35
})
);
ring.rotation.x = Math.PI / 2;
group.add(ring);
scene.add(group);
return group;
}
createLandingMarker(VERTICAL_X, COLORS.orange);
createLandingMarker(HORIZONTAL_LANDING_X, COLORS.cyan);
// Same-height guide.
const heightGuideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-6.4, RELEASE_HEIGHT, 0),
new THREE.Vector3(14.4, RELEASE_HEIGHT, 0)
]);
const heightGuide = new THREE.Line(
heightGuideGeometry,
new THREE.LineDashedMaterial({
color: 0xb6c9d9,
transparent: true,
opacity: 0.22,
dashSize: 0.18,
gapSize: 0.15
})
);
heightGuide.computeLineDistances();
scene.add(heightGuide);
// Height ruler.
const rulerPoints = [
new THREE.Vector3(-6.35, 0, 0),
new THREE.Vector3(-6.35, RELEASE_HEIGHT, 0)
];
for (let y = 0; y <= RELEASE_HEIGHT; y += 2) {
rulerPoints.push(
new THREE.Vector3(-6.52, y, 0),
new THREE.Vector3(-6.18, y, 0)
);
}
const ruler = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(rulerPoints),
new THREE.LineBasicMaterial({
color: 0x68869d,
transparent: true,
opacity: 0.45
})
);
scene.add(ruler);
function makeTextSprite(text, color = "#88a4ba") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 256, 64);
context.fillStyle = color;
context.font = "700 28px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 32);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
sprite.scale.set(1.9, 0.475, 1);
return sprite;
}
for (let y = 2; y <= RELEASE_HEIGHT; y += 2) {
const label = makeTextSprite(`${y} m`);
label.position.set(-7.25, y, 0);
scene.add(label);
}
for (let x = 0; x <= 12; x += 4) {
const label = makeTextSprite(`${x} m`);
label.position.set(x, GROUND_Y + 0.12, 1.35);
scene.add(label);
}
// ------------------------------------------------------------
// Predicted trajectory paths
// ------------------------------------------------------------
const verticalPathPoints = [
new THREE.Vector3(VERTICAL_X, RELEASE_HEIGHT, 0),
new THREE.Vector3(VERTICAL_X, 0, 0)
];
const horizontalPathPoints = [];
for (let i = 0; i <= 80; i++) {
const t = (i / 80) * FALL_TIME;
horizontalPathPoints.push(
new THREE.Vector3(
HORIZONTAL_X + HORIZONTAL_SPEED * t,
RELEASE_HEIGHT - 0.5 * GRAVITY * t * t,
0
)
);
}
function createPath(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.72,
dashSize: 0.25,
gapSize: 0.16,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
return line;
}
createPath(verticalPathPoints, COLORS.orange);
createPath(horizontalPathPoints, COLORS.cyan);
// Small solid markers make the paths read as designed trajectories.
function createPathMarker(position, color, radius = 0.065) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(radius, 10, 8),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.45,
roughness: 0.4
})
);
marker.position.copy(position);
scene.add(marker);
}
for (let i = 1; i < 7; i++) {
const t = (i / 7) * FALL_TIME;
createPathMarker(
new THREE.Vector3(
HORIZONTAL_X + HORIZONTAL_SPEED * t,
RELEASE_HEIGHT - 0.5 * GRAVITY * t * t,
0
),
COLORS.cyan,
0.06
);
}
for (let i = 1; i < 6; i++) {
createPathMarker(
new THREE.Vector3(
VERTICAL_X,
RELEASE_HEIGHT * (1 - i / 6),
0
),
COLORS.orange,
0.06
);
}
function createArrow(position, tangent, color) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.34, 12),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.45,
roughness: 0.38
})
);
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent.clone().normalize()
);
scene.add(arrow);
}
for (const fraction of [0.28, 0.62, 0.82]) {
const t = FALL_TIME * fraction;
createArrow(
new THREE.Vector3(
HORIZONTAL_X + HORIZONTAL_SPEED * t,
RELEASE_HEIGHT - 0.5 * GRAVITY * t * t,
0
),
new THREE.Vector3(HORIZONTAL_SPEED, -GRAVITY * t, 0),
COLORS.cyan
);
}
createArrow(
new THREE.Vector3(VERTICAL_X, 3.8, 0),
new THREE.Vector3(0, -1, 0),
COLORS.orange
);
// ------------------------------------------------------------
// Balls
// ------------------------------------------------------------
function createBall(color) {
const group = new THREE.Group();
const ball = new THREE.Mesh(
new THREE.IcosahedronGeometry(BALL_RADIUS, 2),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.13,
roughness: 0.28,
metalness: 0.16,
flatShading: true
})
);
ball.castShadow = true;
ball.receiveShadow = true;
group.add(ball);
const glow = new THREE.PointLight(color, 4.5, 4.2, 2);
group.add(glow);
scene.add(group);
return { group, ball, glow };
}
const verticalBall = createBall(COLORS.orange);
const horizontalBall = createBall(COLORS.cyan);
// ------------------------------------------------------------
// Motion trails
// ------------------------------------------------------------
const MAX_TRAIL_POINTS = 180;
function createTrail(color) {
const positions = new Float32Array(MAX_TRAIL_POINTS * 3);
const geometry = new THREE.BufferGeometry();
const attribute = new THREE.BufferAttribute(
positions,
3
);
attribute.setUsage(THREE.DynamicDrawUsage);
geometry.setAttribute("position", attribute);
geometry.setDrawRange(0, 0);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.88
})
);
line.frustumCulled = false;
scene.add(line);
return {
line,
positions,
count: 0,
add(position) {
if (this.count >= MAX_TRAIL_POINTS) return;
const i = this.count * 3;
this.positions[i] = position.x;
this.positions[i + 1] = position.y;
this.positions[i + 2] = position.z;
this.count++;
attribute.needsUpdate = true;
geometry.setDrawRange(0, this.count);
},
clear() {
this.count = 0;
geometry.setDrawRange(0, 0);
}
};
}
const verticalTrail = createTrail(COLORS.orange);
const horizontalTrail = createTrail(COLORS.cyan);
// ------------------------------------------------------------
// Landing impact rings
// ------------------------------------------------------------
function createImpactRing(x, color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.44, 0.035, 8, 48),
material
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, GROUND_Y + 0.055, 0);
ring.visible = false;
scene.add(ring);
return { ring, material };
}
const verticalImpact = createImpactRing(
VERTICAL_X,
COLORS.orange
);
const horizontalImpact = createImpactRing(
HORIZONTAL_LANDING_X,
COLORS.cyan
);
// ------------------------------------------------------------
// Simulation state
// ------------------------------------------------------------
let mode = "ready";
let simulationTime = 0;
let impactAge = 0;
let hasLanded = false;
let lastTrailTime = -1;
const releaseButton =
document.getElementById("release-button");
const pauseButton =
document.getElementById("pause-button");
const resetButton =
document.getElementById("reset-button");
const status =
document.getElementById("status");
const statusText =
document.getElementById("status-text");
const timer =
document.getElementById("timer");
const verticalPositionLabel =
document.getElementById("vertical-position");
const horizontalPositionLabel =
document.getElementById("horizontal-position");
const verticalVelocityLabel =
document.getElementById("vertical-velocity");
const horizontalVelocityLabel =
document.getElementById("horizontal-velocity");
const verticalProgress =
document.getElementById("vertical-progress");
const horizontalProgress =
document.getElementById("horizontal-progress");
const deltaResult =
document.getElementById("delta-result");
function signed(value, digits = 2) {
const rounded = Math.abs(value) < 0.0001 ? 0 : value;
return rounded.toFixed(digits);
}
function setBallPositions(time) {
const clampedTime = Math.min(time, FALL_TIME);
const verticalY =
RELEASE_HEIGHT - 0.5 * GRAVITY * clampedTime * clampedTime;
const horizontalY =
RELEASE_HEIGHT - 0.5 * GRAVITY * clampedTime * clampedTime;
const horizontalX =
HORIZONTAL_X + HORIZONTAL_SPEED * clampedTime;
verticalBall.group.position.set(
VERTICAL_X,
verticalY,
0
);
horizontalBall.group.position.set(
horizontalX,
horizontalY,
0
);
}
function updateTrails(time) {
if (time <= lastTrailTime) return;
lastTrailTime = time;
const clampedTime = Math.min(time, FALL_TIME);
const y =
RELEASE_HEIGHT - 0.5 * GRAVITY * clampedTime * clampedTime;
verticalTrail.add(
new THREE.Vector3(VERTICAL_X, y, 0)
);
horizontalTrail.add(
new THREE.Vector3(
HORIZONTAL_X + HORIZONTAL_SPEED * clampedTime,
y,
0
)
);
}
function updateButtonStates() {
releaseButton.disabled =
mode === "running" || mode === "landed";
pauseButton.disabled =
mode !== "running" && mode !== "paused";
pauseButton.textContent =
mode === "paused" ? "Resume" : "Pause";
}
function updateHUD() {
const displayTime = Math.min(
simulationTime,
FALL_TIME
);
const y =
RELEASE_HEIGHT -
0.5 * GRAVITY * displayTime * displayTime;
const x =
HORIZONTAL_X +
HORIZONTAL_SPEED * displayTime;
timer.textContent = `t = ${displayTime.toFixed(2)} s`;
verticalPositionLabel.textContent =
`${signed(VERTICAL_X)}, ${signed(y)}`;
horizontalPositionLabel.textContent =
`${signed(x)}, ${signed(y)}`;
verticalVelocityLabel.textContent =
"0.00, " +
signed(-GRAVITY * displayTime);
horizontalVelocityLabel.textContent =
`${signed(HORIZONTAL_SPEED)}, ` +
signed(-GRAVITY * displayTime);
const progress = Math.min(
displayTime / FALL_TIME,
1
) * 100;
verticalProgress.style.width = `${progress}%`;
horizontalProgress.style.width = `${progress}%`;
status.classList.remove(
"running",
"paused",
"landed"
);
if (mode === "ready") {
statusText.textContent =
"Ready — release both balls together";
} else if (mode === "running") {
status.classList.add("running");
statusText.textContent =
"Simulation running — no air drag";
} else if (mode === "paused") {
status.classList.add("paused");
statusText.textContent =
"Simulation paused";
} else {
status.classList.add("landed");
statusText.textContent =
"Both balls landed simultaneously";
}
}
function beginRelease() {
if (mode !== "ready") return;
mode = "running";
simulationTime = 0;
impactAge = 0;
hasLanded = false;
lastTrailTime = -1;
verticalTrail.clear();
horizontalTrail.clear();
verticalImpact.ring.visible = false;
horizontalImpact.ring.visible = false;
setBallPositions(0);
updateButtonStates();
updateHUD();
}
function togglePause() {
if (mode === "running") {
mode = "paused";
} else if (mode === "paused") {
mode = "running";
} else {
return;
}
updateButtonStates();
updateHUD();
}
function resetSimulation() {
mode = "ready";
simulationTime = 0;
impactAge = 0;
hasLanded = false;
lastTrailTime = -1;
verticalTrail.clear();
horizontalTrail.clear();
verticalImpact.ring.visible = false;
horizontalImpact.ring.visible = false;
verticalImpact.material.opacity = 0;
horizontalImpact.material.opacity = 0;
setBallPositions(0);
deltaResult.innerHTML =
"Δt = 0.00 s<br>predicted";
updateButtonStates();
updateHUD();
}
releaseButton.addEventListener(
"click",
beginRelease
);
pauseButton.addEventListener(
"click",
togglePause
);
resetButton.addEventListener(
"click",
resetSimulation
);
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
event.target.tagName !== "BUTTON"
) {
event.preventDefault();
if (mode === "ready") {
beginRelease();
} else {
togglePause();
}
}
if (
event.key.toLowerCase() === "r" &&
event.target.tagName !== "BUTTON"
) {
resetSimulation();
}
if (
event.key.toLowerCase() === "c" &&
event.target.tagName !== "BUTTON"
) {
resetCamera();
}
});
// ------------------------------------------------------------
// Camera controls implemented directly
// ------------------------------------------------------------
const pointers = new Map();
let lastPointerX = 0;
let lastPointerY = 0;
let previousPinchDistance = 0;
function resetCamera() {
cameraTheta = 0.58;
cameraPhi = 1.08;
cameraRadius = 22;
updateCamera();
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener(
"pointerdown",
(event) => {
renderer.domElement.setPointerCapture(
event.pointerId
);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
}
);
renderer.domElement.addEventListener(
"pointermove",
(event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = pointerDistance();
if (
previousPinchDistance > 0 &&
distance > 0
) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius *
(previousPinchDistance / distance),
12,
34
);
}
previousPinchDistance = distance;
updateCamera();
return;
}
const deltaX =
event.clientX - lastPointerX;
const deltaY =
event.clientY - lastPointerY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.005,
0.42,
1.43
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
}
);
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener(
"pointerup",
endPointer
);
renderer.domElement.addEventListener(
"pointercancel",
endPointer
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius *
Math.exp(event.deltaY * 0.001),
12,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"dblclick",
resetCamera
);
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const verticalLabel =
document.getElementById("vertical-label");
const horizontalLabel =
document.getElementById("horizontal-label");
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x =
(projected.x * 0.5 + 0.5) *
window.innerWidth;
const y =
(-projected.y * 0.5 + 0.5) *
window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y - 31}px`;
}
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
let previousFrameTime = performance.now();
function animate(frameTime) {
const delta = Math.min(
(frameTime - previousFrameTime) / 1000,
0.04
);
previousFrameTime = frameTime;
if (mode === "running") {
simulationTime += delta;
if (simulationTime >= FALL_TIME) {
simulationTime = FALL_TIME;
mode = "landed";
hasLanded = true;
impactAge = 0;
verticalImpact.ring.visible = true;
horizontalImpact.ring.visible = true;
deltaResult.innerHTML =
`Δt = 0.00 s<br>observed`;
updateButtonStates();
}
setBallPositions(simulationTime);
updateTrails(simulationTime);
}
if (hasLanded) {
impactAge += delta;
const alpha = Math.max(
0,
0.85 * (1 - impactAge / 0.85)
);
const scale = 1 + impactAge * 4.2;
verticalImpact.material.opacity = alpha;
horizontalImpact.material.opacity = alpha;
verticalImpact.ring.scale.setScalar(scale);
horizontalImpact.ring.scale.setScalar(scale);
}
// A brief pulse on the launch rings when motion begins.
const ringPulse =
mode === "running"
? 1 +
0.09 *
Math.sin(simulationTime * 28) *
Math.exp(-simulationTime * 5)
: 1;
verticalLauncher.releaseRing.scale.setScalar(
ringPulse
);
horizontalLauncher.releaseRing.scale.setScalar(
ringPulse
);
// Subtle ball rotation gives the faceted forms a physical feel.
verticalBall.ball.rotation.x += delta * 0.9;
verticalBall.ball.rotation.z += delta * 0.65;
horizontalBall.ball.rotation.x += delta * 1.1;
horizontalBall.ball.rotation.y += delta * 0.75;
updateHUD();
placeLabel(
verticalLabel,
verticalBall.group.position
);
placeLabel(
horizontalLabel,
horizontalBall.group.position
);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// ------------------------------------------------------------
// Resize handling
// ------------------------------------------------------------
function handleResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
renderer.setSize(width, height);
}
window.addEventListener(
"resize",
handleResize
);
// Initialize the scene.
document.getElementById(
"predicted-time"
).innerHTML = `${FALL_TIME.toFixed(2)} <em>s</em>`;
setBallPositions(0);
updateButtonStates();
updateHUD();
</script>
</body>
</html>
```