Prompt specification
Build or customize the Three.js 3D scene "Fixed and movable pulley lift 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: Fixed and movable pulley lift comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fixed-and-movable-pulley-lift-comparison-x1422
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Raise identical model loads with a fixed pulley and a movable pulley; show different pulling distances and forces while matching ideal gravitational work.
Working Three.js Starter (fixed-and-movable-pulley-lift-comparison-x1422):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pulley Lab — Equal Work, Different Forces</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(10, 24, 41, 0.82);
--panel-strong: rgba(8, 20, 35, 0.94);
--line: rgba(169, 205, 232, 0.17);
--text: #edf7ff;
--muted: #9cb1c5;
--fixed: #59d8ff;
--movable: #ffb84d;
--work: #a7f3d0;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 18%, #15304a 0%, #091827 42%, #050b13 100%);
color: var(--text);
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;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 440px;
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--work);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
border-radius: 2px;
background: var(--work);
box-shadow: 0 0 12px rgba(167, 243, 208, 0.6);
}
h1 {
margin: 10px 0 8px;
max-width: 430px;
font-size: clamp(26px, 3vw, 43px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.brand p {
max-width: 430px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 22px;
right: 22px;
width: 294px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.control-head strong {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--work);
box-shadow: 0 0 10px rgba(167, 243, 208, 0.85);
}
.control {
margin: 13px 0;
}
.control label {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 12px;
}
.control output {
color: var(--text);
font-size: 13px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
background: linear-gradient(90deg, #446179, #253a4d);
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #dff7ff;
border-radius: 50%;
appearance: none;
background: #3ebde6;
box-shadow: 0 0 0 4px rgba(89, 216, 255, 0.12);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #dff7ff;
border-radius: 50%;
background: #3ebde6;
box-shadow: 0 0 0 4px rgba(89, 216, 255, 0.12);
cursor: pointer;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
button {
min-height: 40px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
font: inherit;
font-size: 12px;
font-weight: 760;
cursor: pointer;
transition: transform 0.16s ease, background 0.16s ease;
}
button:hover {
background: rgba(255, 255, 255, 0.1);
transform: translateY(-1px);
}
button.primary {
border-color: rgba(89, 216, 255, 0.45);
background: linear-gradient(135deg, #238caf, #17647f);
}
.assumption {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #8198ad;
font-size: 10px;
line-height: 1.45;
}
.comparison {
position: absolute;
left: 50%;
bottom: 22px;
width: min(900px, calc(100vw - 44px));
transform: translateX(-50%);
padding: 14px;
border: 1px solid var(--line);
border-radius: 19px;
background: var(--panel-strong);
box-shadow: 0 25px 90px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(18px);
pointer-events: none;
}
.comparison-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 11px;
}
.comparison-title {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.equal-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border: 1px solid rgba(167, 243, 208, 0.22);
border-radius: 99px;
color: var(--work);
background: rgba(167, 243, 208, 0.07);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
white-space: nowrap;
}
.equal-badge::before {
content: "✓";
display: grid;
width: 16px;
height: 16px;
place-items: center;
border-radius: 50%;
color: #092117;
background: var(--work);
}
.systems {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.system {
position: relative;
overflow: hidden;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.028);
}
.system::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--accent);
}
.system.fixed { --accent: var(--fixed); }
.system.movable { --accent: var(--movable); }
.system-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.system-title strong {
color: var(--accent);
font-size: 12px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.ratio {
padding: 3px 7px;
border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
border-radius: 99px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric span {
display: block;
margin-bottom: 3px;
color: #7f95aa;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.metric strong {
font-size: 14px;
font-variant-numeric: tabular-nums;
}
.work-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 11px;
padding: 9px 11px;
border: 1px solid rgba(167, 243, 208, 0.12);
border-radius: 10px;
background: rgba(167, 243, 208, 0.045);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.work-line span {
color: var(--muted);
}
.work-line b {
color: var(--work);
font-size: 13px;
}
.camera-help {
position: absolute;
right: 25px;
bottom: 238px;
color: rgba(188, 210, 227, 0.62);
font-size: 10px;
letter-spacing: 0.03em;
}
@media (max-width: 820px) {
.brand {
top: 16px;
left: 16px;
max-width: 55vw;
}
.brand p { display: none; }
.controls {
top: 14px;
right: 14px;
width: 250px;
padding: 13px;
}
.comparison {
bottom: 12px;
width: calc(100vw - 24px);
}
.camera-help { display: none; }
}
@media (max-width: 590px) {
.brand {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
}
.brand h1 {
margin-top: 7px;
font-size: 24px;
}
.controls {
top: 105px;
left: 12px;
right: 12px;
width: auto;
padding: 11px 13px;
}
.control {
margin: 9px 0;
}
.assumption { display: none; }
.comparison {
bottom: 8px;
padding: 10px;
}
.comparison-top { margin-bottom: 8px; }
.systems {
grid-template-columns: 1fr;
gap: 7px;
}
.system {
padding: 9px 10px;
}
.metrics {
gap: 4px;
}
.metric strong { font-size: 12px; }
.work-line {
margin-top: 8px;
padding: 7px 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="hud">
<header class="brand">
<div class="eyebrow">Mechanics Studio / Ideal Pulleys</div>
<h1>Equal work.<br>Different effort.</h1>
<p>
Two identical loads rise the same distance. A movable pulley reduces the
required force, but the rope must travel twice as far.
</p>
</header>
<section class="controls" aria-label="Simulation controls">
<div class="control-head">
<strong>Experiment</strong>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">READY</span>
</div>
</div>
<div class="control">
<label for="massInput">
Identical load mass
<output id="massOutput">20 kg</output>
</label>
<input id="massInput" type="range" min="5" max="60" step="1" value="20" />
</div>
<div class="control">
<label for="heightInput">
Vertical lift
<output id="heightOutput">2.0 m</output>
</label>
<input id="heightInput" type="range" min="0.5" max="2.2" step="0.1" value="2" />
</div>
<div class="buttons">
<button id="playButton" class="primary" type="button">▶ Raise loads</button>
<button id="resetButton" type="button">↺ Reset</button>
</div>
<div class="assumption">
Ideal assumptions: massless rope, frictionless pulleys, constant speed,
and quasistatic input force.
</div>
</section>
<section class="comparison" aria-label="Work comparison">
<div class="comparison-top">
<div class="comparison-title">Live mechanical advantage comparison</div>
<div class="equal-badge">EQUAL GRAVITATIONAL WORK</div>
</div>
<div class="systems">
<article class="system fixed">
<div class="system-title">
<strong>Fixed pulley</strong>
<span class="ratio">1 : 1</span>
</div>
<div class="metrics">
<div class="metric">
<span>Pull force</span>
<strong id="fixedForce">196.2 N</strong>
</div>
<div class="metric">
<span>Pull distance</span>
<strong id="fixedDistance">2.00 m</strong>
</div>
<div class="metric">
<span>Input work</span>
<strong id="fixedWork">392.4 J</strong>
</div>
</div>
</article>
<article class="system movable">
<div class="system-title">
<strong>Movable pulley</strong>
<span class="ratio">2 : 1</span>
</div>
<div class="metrics">
<div class="metric">
<span>Pull force</span>
<strong id="movableForce">98.1 N</strong>
</div>
<div class="metric">
<span>Pull distance</span>
<strong id="movableDistance">4.00 m</strong>
</div>
<div class="metric">
<span>Input work</span>
<strong id="movableWork">392.4 J</strong>
</div>
</div>
</article>
</div>
<div class="work-line">
<span id="equationText">
196.2 N × 2.00 m = 98.1 N × 4.00 m = 392.4 J = mgh
</span>
<b id="totalWork">392.4 J</b>
</div>
</section>
<div class="camera-help">Drag to orbit · Scroll to zoom · Shift-drag to pan</div>
</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 experiment state */
/* -------------------------------------------------------------------------- */
const $ = (id) => document.getElementById(id);
const massInput = $("massInput");
const heightInput = $("heightInput");
const massOutput = $("massOutput");
const heightOutput = $("heightOutput");
const playButton = $("playButton");
const resetButton = $("resetButton");
const statusText = $("statusText");
const G = 9.81;
const INITIAL_LOAD_Y = 0.78;
const PULLEY_RADIUS = 0.58;
const FIXED_PULLEY = new THREE.Vector3(-3.8, 5.15, 0);
const MOVING_PULLEY_X = 3.4;
const MOVING_PULLEY_INITIAL_Y = 1.78;
const UPPER_MOVABLE_PULLEY = new THREE.Vector3(4.56, 5.15, 0);
const FIXED_FREE_X = FIXED_PULLEY.x + PULLEY_RADIUS;
const MOVABLE_FREE_X = UPPER_MOVABLE_PULLEY.x + PULLEY_RADIUS;
const FIXED_FREE_START_Y = 4.18;
const MOVABLE_FREE_START_Y = 4.75;
let mass = 20;
let liftHeight = 2;
let progress = 0;
let playing = false;
/* -------------------------------------------------------------------------- */
/* Renderer, scene, lights */
/* -------------------------------------------------------------------------- */
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: 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.15;
renderer.setClearColor(0x000000, 0);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111f, 0.027);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xb9ddff, 0x14202e, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe7f5ff, 3.2);
keyLight.position.set(4, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3fc8ff, 1.7);
rimLight.position.set(-9, 5, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa53d, 22, 12, 2);
warmLight.position.set(4, 4, 4);
scene.add(warmLight);
const coolLight = new THREE.PointLight(0x38d7ff, 20, 12, 2);
coolLight.position.set(-4, 4, 4);
scene.add(coolLight);
/* -------------------------------------------------------------------------- */
/* Materials and geometry helpers */
/* -------------------------------------------------------------------------- */
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.88,
metalness: 0.12
}),
platform: new THREE.MeshStandardMaterial({
color: 0x12283b,
roughness: 0.62,
metalness: 0.46
}),
steel: new THREE.MeshStandardMaterial({
color: 0x30475a,
roughness: 0.36,
metalness: 0.82
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x162a3b,
roughness: 0.48,
metalness: 0.72
}),
fixed: new THREE.MeshStandardMaterial({
color: 0x47c8ef,
emissive: 0x06384b,
emissiveIntensity: 0.8,
roughness: 0.28,
metalness: 0.68
}),
movable: new THREE.MeshStandardMaterial({
color: 0xffa936,
emissive: 0x4a2602,
emissiveIntensity: 0.75,
roughness: 0.28,
metalness: 0.64
}),
weight: new THREE.MeshStandardMaterial({
color: 0xf0b74a,
roughness: 0.34,
metalness: 0.56
}),
weightEdge: new THREE.MeshStandardMaterial({
color: 0x263849,
roughness: 0.35,
metalness: 0.8
}),
rope: new THREE.MeshStandardMaterial({
color: 0xf5e9cb,
roughness: 0.72,
metalness: 0.05
}),
bolt: new THREE.MeshStandardMaterial({
color: 0x9db1c1,
roughness: 0.28,
metalness: 0.9
})
};
function box(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, length, position, material, radialSegments = 24) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLine(parent, color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 1, 0)
]);
const options = {
color,
transparent: opacity < 1,
opacity
};
const material = dashed
? new THREE.LineDashedMaterial({ ...options, dashSize: 0.10, gapSize: 0.075 })
: new THREE.LineBasicMaterial(options);
const line = new THREE.Line(geometry, material);
if (dashed) line.computeLineDistances();
parent.add(line);
return line;
}
function setLine(line, a, b) {
line.geometry.setFromPoints([a, b]);
if (line.material.isLineDashedMaterial) line.computeLineDistances();
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createSprite(text, accent = "#8bdfff", width = 3.3) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 192 / 768, 1);
sprite.renderOrder = 20;
function setText(value) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(6, 18, 31, 0.90)";
roundedRect(ctx, 8, 8, 752, 176, 34);
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = "#eef8ff";
ctx.font = "800 55px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(value, 384, 97);
texture.needsUpdate = true;
}
setText(text);
return { sprite, setText };
}
/* -------------------------------------------------------------------------- */
/* Environment */
/* -------------------------------------------------------------------------- */
const ground = new THREE.Mesh(new THREE.PlaneGeometry(42, 32), materials.floor);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.03;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x28506a, 0x152b3d);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.46;
scene.add(grid);
function createPlatform(cx, width, accent) {
const group = new THREE.Group();
scene.add(group);
box(group,
new THREE.Vector3(width, 0.24, 2.9),
new THREE.Vector3(cx, 0.12, 0),
materials.platform
);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.75,
roughness: 0.35,
metalness: 0.45
});
box(group,
new THREE.Vector3(width - 0.12, 0.025, 2.76),
new THREE.Vector3(cx, 0.255, 0),
edgeMaterial,
false
);
return group;
}
createPlatform(-3.8, 4.25, 0x2384a3);
createPlatform(3.95, 5.9, 0x9c6321);
function createFrame(cx, width, accentMaterial) {
const group = new THREE.Group();
scene.add(group);
const postX = width * 0.5;
[-postX, postX].forEach((offset) => {
box(group,
new THREE.Vector3(0.18, 5.75, 0.22),
new THREE.Vector3(cx + offset, 2.87, -0.25),
materials.steel
);
box(group,
new THREE.Vector3(0.55, 0.12, 0.65),
new THREE.Vector3(cx + offset, 0.30, -0.08),
materials.darkSteel
);
for (let y = 0.7; y < 5.5; y += 1.05) {
const bolt = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 10, 10),
materials.bolt
);
bolt.position.set(cx + offset, y, -0.125);
group.add(bolt);
}
});
box(group,
new THREE.Vector3(width + 0.42, 0.28, 0.34),
new THREE.Vector3(cx, 5.87, -0.25),
materials.steel
);
box(group,
new THREE.Vector3(width + 0.18, 0.055, 0.36),
new THREE.Vector3(cx, 5.71, -0.23),
accentMaterial,
false
);
return group;
}
createFrame(-3.8, 3.25, materials.fixed);
createFrame(3.95, 4.1, materials.movable);
/* Subtle floating dust gives the diorama some depth. */
const dustCount = 260;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 25;
dustPositions[i * 3 + 1] = Math.random() * 10 + 0.5;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 15;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x8dc8e8,
size: 0.025,
transparent: true,
opacity: 0.35,
depthWrite: false
})
);
scene.add(dust);
/* -------------------------------------------------------------------------- */
/* Pulleys */
/* -------------------------------------------------------------------------- */
function createPulley(accentMaterial) {
const group = new THREE.Group();
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(PULLEY_RADIUS - 0.11, PULLEY_RADIUS - 0.11, 0.22, 48),
materials.darkSteel
);
wheel.rotation.x = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(PULLEY_RADIUS - 0.045, 0.058, 12, 56),
accentMaterial
);
rim.castShadow = true;
group.add(rim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.38, 24),
materials.bolt
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
group.add(hub);
for (let i = 0; i < 4; i++) {
const spoke = new THREE.Mesh(
new THREE.BoxGeometry(0.075, PULLEY_RADIUS * 1.35, 0.07),
accentMaterial
);
spoke.rotation.z = i * Math.PI / 4;
spoke.position.z = 0.15;
spoke.castShadow = true;
group.add(spoke);
}
const center = new THREE.Mesh(
new THREE.CircleGeometry(0.065, 20),
materials.bolt
);
center.position.z = 0.19;
group.add(center);
return group;
}
const fixedPulley = createPulley(materials.fixed);
fixedPulley.position.copy(FIXED_PULLEY);
scene.add(fixedPulley);
const upperMovablePulley = createPulley(materials.movable);
upperMovablePulley.position.copy(UPPER_MOVABLE_PULLEY);
scene.add(upperMovablePulley);
const movingPulley = createPulley(materials.movable);
movingPulley.position.set(MOVING_PULLEY_X, MOVING_PULLEY_INITIAL_Y, 0);
scene.add(movingPulley);
/* Axle brackets. */
function createAxle(center, accentMaterial) {
const group = new THREE.Group();
scene.add(group);
box(group,
new THREE.Vector3(0.12, 0.78, 0.18),
new THREE.Vector3(center.x, center.y + 0.5, -0.13),
materials.steel
);
const axle = cylinder(
group,
0.085,
0.55,
new THREE.Vector3(center.x, center.y, 0),
materials.bolt
);
axle.rotation.x = Math.PI / 2;
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.07, 20),
accentMaterial
);
cap.rotation.x = Math.PI / 2;
cap.position.set(center.x, center.y, 0.30);
group.add(cap);
}
createAxle(FIXED_PULLEY, materials.fixed);
createAxle(UPPER_MOVABLE_PULLEY, materials.movable);
/* -------------------------------------------------------------------------- */
/* Identical model loads */
/* -------------------------------------------------------------------------- */
function createWeight() {
const group = new THREE.Group();
box(group,
new THREE.Vector3(1.0, 0.76, 0.82),
new THREE.Vector3(0, 0, 0),
materials.weight
);
[-0.36, 0.36].forEach((x) => {
box(group,
new THREE.Vector3(0.075, 0.80, 0.86),
new THREE.Vector3(x, 0, 0),
materials.weightEdge
);
});
box(group,
new THREE.Vector3(1.03, 0.075, 0.86),
new THREE.Vector3(0, -0.31, 0),
materials.weightEdge
);
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.035, 10, 28, Math.PI * 1.7),
materials.bolt
);
hook.position.y = 0.49;
hook.rotation.z = -Math.PI * 0.35;
hook.castShadow = true;
group.add(hook);
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 224;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(0.67, 0.29),
new THREE.MeshBasicMaterial({ map: texture, transparent: true })
);
plate.position.set(0, 0.02, 0.422);
group.add(plate);
function setMass(value) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(11, 28, 43, 0.94)";
roundedRect(ctx, 10, 10, 492, 204, 34);
ctx.fill();
ctx.strokeStyle = "#f6d98b";
ctx.lineWidth = 8;
ctx.stroke();
ctx.fillStyle = "#fff6da";
ctx.font = "800 90px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`${value} kg`, 256, 116);
texture.needsUpdate = true;
}
setMass(mass);
return { group, setMass };
}
const fixedWeight = createWeight();
fixedWeight.group.position.set(
FIXED_PULLEY.x - PULLEY_RADIUS,
INITIAL_LOAD_Y,
0
);
scene.add(fixedWeight.group);
const movableWeight = createWeight();
movableWeight.group.position.set(MOVING_PULLEY_X, INITIAL_LOAD_Y, 0);
scene.add(movableWeight.group);
/* Connector between the movable pulley and its load. */
const movingConnector = cylinder(
scene,
0.075,
1,
new THREE.Vector3(MOVING_PULLEY_X, 1.3, 0),
materials.bolt,
16
);
/* -------------------------------------------------------------------------- */
/* Rope, handles, annotations */
/* -------------------------------------------------------------------------- */
const fixedRope = new THREE.Mesh(new THREE.BufferGeometry(), materials.rope);
const movableRope = new THREE.Mesh(new THREE.BufferGeometry(), materials.rope);
fixedRope.castShadow = true;
movableRope.castShadow = true;
scene.add(fixedRope, movableRope);
function arcPoints(cx, cy, radius, startAngle, endAngle, count = 20) {
const points = [];
for (let i = 0; i <= count; i++) {
const t = i / count;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
points.push(new THREE.Vector3(
cx + Math.cos(angle) * radius,
cy + Math.sin(angle) * radius,
0
));
}
return points;
}
function uniquePoints(points) {
const result = [];
points.forEach((point) => {
if (!result.length || point.distanceTo(result[result.length - 1]) > 0.0001) {
result.push(point.clone());
}
});
return result;
}
function updateRope(mesh, points) {
const cleaned = uniquePoints(points);
const path = new THREE.CurvePath();
for (let i = 0; i < cleaned.length - 1; i++) {
path.add(new THREE.LineCurve3(cleaned[i], cleaned[i + 1]));
}
const geometry = new THREE.TubeGeometry(
path,
Math.max(80, cleaned.length * 5),
0.034,
7,
false
);
mesh.geometry.dispose();
mesh.geometry = geometry;
}
function createHandle(color) {
const group = new THREE.Group();
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.3,
metalness: 0.65
});
const grip = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.42, 20),
material
);
grip.rotation.z = Math.PI / 2;
grip.castShadow = true;
group.add(grip);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.025, 8, 22),
materials.bolt
);
collar.rotation.y = Math.PI / 2;
group.add(collar);
return group;
}
const fixedHandle = createHandle(0x59d8ff);
const movableHandle = createHandle(0xffb84d);
function createGuide(color, labelText, width = 2.15) {
const group = new THREE.Group();
scene.add(group);
const line = makeLine(group, color, 0.68, true);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 12),
new THREE.MeshBasicMaterial({ color })
);
group.add(marker);
const tag = createSprite(labelText, `#${new THREE.Color(color).getHexString()}`, width);
group.add(tag.sprite);
return { group, line, marker, tag };
}
const fixedPullGuide = createGuide(0x59d8ff, "PULL 2.00 m");
const movablePullGuide = createGuide(0xffb84d, "PULL 4.00 m", 2.35);
const fixedHeightGuide = createGuide(0x59d8ff, "LIFT 2.00 m", 2.0);
const movableHeightGuide = createGuide(0xffb84d, "LIFT 2.00 m", 2.0);
function createGhost(x, color) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(1.03, 0.79, 0.85)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.28
});
const ghost = new THREE.LineSegments(geometry, material);
ghost.position.set(x, INITIAL_LOAD_Y + liftHeight, -0.04);
scene.add(ghost);
return ghost;
}
const fixedGhost = createGhost(
FIXED_PULLEY.x - PULLEY_RADIUS,
0x59d8ff
);
const movableGhost = createGhost(MOVING_PULLEY_X, 0xffb84d);
const fixedSign = createSprite("01 FIXED PULLEY", "#59d8ff", 3.5);
fixedSign.sprite.position.set(-3.8, 6.48, 0);
scene.add(fixedSign.sprite);
const movableSign = createSprite("02 MOVABLE PULLEY", "#ffb84d", 3.8);
movableSign.sprite.position.set(3.9, 6.48, 0);
scene.add(movableSign.sprite);
const fixedRatio = createSprite("F = mg", "#59d8ff", 1.75);
fixedRatio.sprite.position.set(-5.05, 4.43, 0);
scene.add(fixedRatio.sprite);
const movableRatio = createSprite("F = mg / 2", "#ffb84d", 2.05);
movableRatio.sprite.position.set(1.98, 4.63, 0);
scene.add(movableRatio.sprite);
/* -------------------------------------------------------------------------- */
/* Scene animation */
/* -------------------------------------------------------------------------- */
function updateRigGeometry() {
const loadY = INITIAL_LOAD_Y + liftHeight * progress;
const movingY = MOVING_PULLEY_INITIAL_Y + liftHeight * progress;
const fixedHandleY = FIXED_FREE_START_Y - liftHeight * progress;
const movableHandleY = MOVABLE_FREE_START_Y - 2 * liftHeight * progress;
fixedWeight.group.position.y = loadY;
movableWeight.group.position.y = loadY;
movingPulley.position.y = movingY;
const connectorTop = movingY - 0.08;
const connectorBottom = loadY + 0.46;
const connectorLength = Math.max(0.1, connectorTop - connectorBottom);
movingConnector.scale.y = connectorLength;
movingConnector.position.y = connectorBottom + connectorLength * 0.5;
fixedHandle.position.set(FIXED_FREE_X, fixedHandleY, 0);
movableHandle.position.set(MOVABLE_FREE_X, movableHandleY, 0);
fixedPulley.rotation.z = -(liftHeight * progress) / PULLEY_RADIUS;
upperMovablePulley.rotation.z = -(2 * liftHeight * progress) / PULLEY_RADIUS;
movingPulley.rotation.z = -(2 * liftHeight * progress) / PULLEY_RADIUS;
/* Fixed system: load → fixed pulley → downward free end. */
const fixedLeftX = FIXED_PULLEY.x - PULLEY_RADIUS;
const fixedRightX = FIXED_PULLEY.x + PULLEY_RADIUS;
const fixedPoints = [
new THREE.Vector3(fixedLeftX, loadY + 0.62, 0),
new THREE.Vector3(fixedLeftX, FIXED_PULLEY.y, 0),
...arcPoints(
FIXED_PULLEY.x,
FIXED_PULLEY.y,
PULLEY_RADIUS,
Math.PI,
0
),
new THREE.Vector3(fixedRightX, fixedHandleY, 0)
];
updateRope(fixedRope, fixedPoints);
/*
* Movable system:
* ceiling anchor → moving pulley → upper fixed redirector → free end.
*/
const movingLeftX = MOVING_PULLEY_X - PULLEY_RADIUS;
const movingRightX = MOVING_PULLEY_X + PULLEY_RADIUS;
const upperLeftX = UPPER_MOVABLE_PULLEY.x - PULLEY_RADIUS;
const upperRightX = UPPER_MOVABLE_PULLEY.x + PULLEY_RADIUS;
const movablePoints = [
new THREE.Vector3(movingLeftX, 5.72, 0),
new THREE.Vector3(movingLeftX, movingY, 0),
...arcPoints(
MOVING_PULLEY_X,
movingY,
PULLEY_RADIUS,
Math.PI,
Math.PI * 2
),
new THREE.Vector3(movingRightX, UPPER_MOVABLE_PULLEY.y, 0),
...arcPoints(
UPPER_MOVABLE_PULLEY.x,
UPPER_MOVABLE_PULLEY.y,
PULLEY_RADIUS,
Math.PI,
0
),
new THREE.Vector3(MOVABLE_FREE_X, movableHandleY, 0)
];
updateRope(movableRope, movablePoints);
/* Pull-distance guides. */
const fixedGuideX = FIXED_FREE_X + 0.32;
const movableGuideX = MOVABLE_FREE_X + 0.32;
setLine(
fixedPullGuide.line,
new THREE.Vector3(fixedGuideX, FIXED_FREE_START_Y, 0.08),
new THREE.Vector3(fixedGuideX, fixedHandleY, 0.08)
);
fixedPullGuide.marker.position.set(fixedGuideX, fixedHandleY, 0.08);
fixedPullGuide.tag.sprite.position.set(
fixedGuideX + 0.05,
(FIXED_FREE_START_Y + fixedHandleY) * 0.5,
0.10
);
setLine(
movablePullGuide.line,
new THREE.Vector3(movableGuideX, MOVABLE_FREE_START_Y, 0.08),
new THREE.Vector3(movableGuideX, movableHandleY, 0.08)
);
movablePullGuide.marker.position.set(movableGuideX, movableHandleY, 0.08);
movablePullGuide.tag.sprite.position.set(
movableGuideX + 0.07,
(MOVABLE_FREE_START_Y + movableHandleY) * 0.5,
0.10
);
/* Equal vertical-lift guides. */
const finalLoadY = INITIAL_LOAD_Y + liftHeight;
setLine(
fixedHeightGuide.line,
new THREE.Vector3(fixedLeftX - 0.72, INITIAL_LOAD_Y, 0),
new THREE.Vector3(fixedLeftX - 0.72, finalLoadY, 0)
);
fixedHeightGuide.marker.position.set(
fixedLeftX - 0.72,
finalLoadY,
0
);
fixedHeightGuide.tag.sprite.position.set(
fixedLeftX - 0.82,
(INITIAL_LOAD_Y + finalLoadY) * 0.5,
0.08
);
setLine(
movableHeightGuide.line,
new THREE.Vector3(movingLeftX - 0.64, INITIAL_LOAD_Y, 0),
new THREE.Vector3(movingLeftX - 0.64, finalLoadY, 0)
);
movableHeightGuide.marker.position.set(
movingLeftX - 0.64,
finalLoadY,
0
);
movableHeightGuide.tag.sprite.position.set(
movingLeftX - 0.72,
(INITIAL_LOAD_Y + finalLoadY) * 0.5,
0.08
);
fixedGhost.position.y = finalLoadY;
movableGhost.position.y = finalLoadY;
}
/* -------------------------------------------------------------------------- */
/* Physics readout */
/* -------------------------------------------------------------------------- */
function formatNumber(value, digits = 1) {
return value.toLocaleString(undefined, {
minimumFractionDigits: digits,
maximumFractionDigits: digits
});
}
function updateReadouts() {
const gravityForce = mass * G;
const fixedForceValue = gravityForce;
const movableForceValue = gravityForce / 2;
const fixedDistanceValue = liftHeight;
const movableDistanceValue = 2 * liftHeight;
const work = gravityForce * liftHeight;
massOutput.textContent = `${mass} kg`;
heightOutput.textContent = `${liftHeight.toFixed(1)} m`;
$("fixedForce").textContent = `${formatNumber(fixedForceValue)} N`;
$("movableForce").textContent = `${formatNumber(movableForceValue)} N`;
$("fixedDistance").textContent = `${formatNumber(fixedDistanceValue, 2)} m`;
$("movableDistance").textContent = `${formatNumber(movableDistanceValue, 2)} m`;
$("fixedWork").textContent = `${formatNumber(work)} J`;
$("movableWork").textContent = `${formatNumber(work)} J`;
$("totalWork").textContent = `${formatNumber(work)} J`;
$("equationText").textContent =
`${formatNumber(fixedForceValue)} N × ${formatNumber(fixedDistanceValue, 2)} m` +
` = ${formatNumber(movableForceValue)} N × ${formatNumber(movableDistanceValue, 2)} m` +
` = ${formatNumber(work)} J = mgh`;
fixedWeight.setMass(mass);
movableWeight.setMass(mass);
fixedPullGuide.tag.setText(`PULL ${formatNumber(fixedDistanceValue, 2)} m`);
movablePullGuide.tag.setText(`PULL ${formatNumber(movableDistanceValue, 2)} m`);
fixedHeightGuide.tag.setText(`LIFT ${formatNumber(liftHeight, 2)} m`);
movableHeightGuide.tag.setText(`LIFT ${formatNumber(liftHeight, 2)} m`);
}
function updatePlayButton() {
playButton.textContent = playing
? "❚❚ Pause"
: progress >= 1
? "▶ Raise again"
: "▶ Raise loads";
}
function resetExperiment() {
progress = 0;
playing = false;
updatePlayButton();
updateRigGeometry();
}
massInput.addEventListener("input", () => {
mass = Number(massInput.value);
updateReadouts();
resetExperiment();
});
heightInput.addEventListener("input", () => {
liftHeight = Number(heightInput.value);
updateReadouts();
resetExperiment();
});
playButton.addEventListener("click", () => {
if (progress >= 1) progress = 0;
playing = !playing;
updatePlayButton();
});
resetButton.addEventListener("click", resetExperiment);
/* -------------------------------------------------------------------------- */
/* Direct camera controls: orbit, pan, and zoom */
/* -------------------------------------------------------------------------- */
const cameraState = {
target: new THREE.Vector3(0.15, 2.75, 0),
radius: 17.2,
theta: 0.38,
phi: 1.22
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let previousPointer = { x: 0, y: 0 };
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragging = true;
activePointerId = event.pointerId;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || event.button === 2) {
cameraState.target.x -= dx * 0.009;
cameraState.target.y += dy * 0.009;
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-7,
7
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
1,
6
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.52,
1.46
);
}
updateCamera();
});
function endDrag(event) {
if (activePointerId !== null && event.pointerId === activePointerId) {
dragging = false;
activePointerId = null;
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
28
);
updateCamera();
}, { passive: false });
/* -------------------------------------------------------------------------- */
/* Resize and animation loop */
/* -------------------------------------------------------------------------- */
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
const animationDuration = 6.8;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
progress = Math.min(1, progress + delta / animationDuration);
if (progress >= 1) {
playing = false;
updatePlayButton();
}
statusText.textContent = progress >= 1
? "COMPLETE"
: "RAISING";
} else {
statusText.textContent = progress === 0
? "READY"
: progress >= 1
? "COMPLETE"
: "PAUSED";
}
updateRigGeometry();
dust.rotation.y += delta * 0.012;
dust.position.y = Math.sin(clock.elapsedTime * 0.22) * 0.035;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateReadouts();
updateRigGeometry();
updateCamera();
animate();
</script>
</body>
</html>
```