Prompt specification
Build or customize the Three.js 3D scene "Gear train with idler 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: Gear train with idler comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/gear-train-with-idler-comparison-x1386
Scene Description Prompt:
Compare stylized gear trains with and without an idler, showing rotation direction and input-to-output ratios. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (gear-train-with-idler-comparison-x1386):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gear Train Comparison — Direct vs Idler</title>
<style>
:root {
--ink: #172c36;
--muted: #68777c;
--paper: #f1eee5;
--teal: #258a7c;
--amber: #e99b31;
--purple: #7467d8;
--coral: #d96552;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.title-block {
position: absolute;
top: 22px;
left: 50%;
width: min(560px, calc(100% - 180px));
transform: translateX(-50%);
text-align: center;
}
.eyebrow {
margin-bottom: 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 39px);
line-height: 1.05;
letter-spacing: -0.045em;
}
h1 span {
color: var(--coral);
font-weight: 500;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 13px;
}
.controls {
position: absolute;
top: 25px;
right: 26px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(23, 44, 54, 0.16);
border-radius: 999px;
padding: 10px 16px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 6px 20px rgba(23, 44, 54, 0.08);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
transform 160ms ease,
background 160ms ease;
}
button:hover {
transform: translateY(-1px);
background: white;
}
.hint {
position: absolute;
left: 26px;
bottom: 25px;
max-width: 220px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.hint strong {
color: var(--ink);
}
.results {
position: absolute;
right: 25px;
bottom: 22px;
display: grid;
grid-template-columns: repeat(2, minmax(250px, 330px));
gap: 12px;
}
.result-card {
position: relative;
overflow: hidden;
padding: 17px 19px 16px;
border: 1px solid rgba(23, 44, 54, 0.11);
border-radius: 18px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 14px 40px rgba(23, 44, 54, 0.1);
backdrop-filter: blur(14px);
}
.result-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 5px;
background: var(--accent);
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.card-kicker {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.ratio-badge {
padding: 4px 8px;
border-radius: 999px;
background: color-mix(in srgb, var(--accent) 12%, white);
color: var(--accent);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.gear-chain {
margin-bottom: 10px;
font-size: 22px;
font-weight: 850;
letter-spacing: -0.03em;
}
.facts {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.fact {
padding: 5px 8px;
border-radius: 8px;
background: #f1f3ef;
color: #4f6268;
font-size: 10px;
font-weight: 700;
}
.fact strong {
color: var(--ink);
}
.card-note {
margin: 10px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
@media (max-width: 900px) {
.title-block {
top: 17px;
width: calc(100% - 150px);
left: 20px;
transform: none;
text-align: left;
}
.subtitle {
display: none;
}
.controls {
top: 18px;
right: 18px;
}
.results {
right: 14px;
bottom: 14px;
grid-template-columns: repeat(2, minmax(210px, 1fr));
}
.result-card {
padding: 14px 15px;
}
.gear-chain {
font-size: 18px;
}
.hint {
display: none;
}
}
@media (max-width: 620px) {
.title-block {
width: calc(100% - 120px);
}
h1 {
font-size: 21px;
}
.eyebrow {
font-size: 9px;
}
button {
padding: 9px 12px;
}
.results {
right: 10px;
bottom: 10px;
left: 10px;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.result-card {
border-radius: 13px;
padding: 12px 11px;
}
.card-top {
display: block;
}
.ratio-badge {
display: inline-block;
margin-top: 5px;
}
.gear-chain {
font-size: 15px;
}
.facts {
display: block;
}
.fact {
display: inline-block;
margin: 2px 2px 0 0;
font-size: 9px;
}
.card-note {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<header class="title-block">
<div class="eyebrow">Mechanism Study 01</div>
<h1>Direct Drive <span>vs.</span> Idler Drive</h1>
<p class="subtitle">
See how an idler changes direction while preserving the final speed ratio.
</p>
</header>
<div class="controls">
<button id="pauseButton" type="button" aria-pressed="false">
Ⅱ Pause
</button>
</div>
<div class="hint">
<strong>Camera:</strong> drag to orbit<br />
Scroll to zoom · double-click to reset
</div>
<section class="results" aria-label="Gear ratio comparison">
<article class="result-card" style="--accent: var(--teal)">
<div class="card-top">
<div class="card-kicker">Without idler</div>
<div class="ratio-badge">2:1 reduction</div>
</div>
<div class="gear-chain">12T → 24T</div>
<div class="facts">
<div class="fact"><strong>Output:</strong> ½ speed</div>
<div class="fact"><strong>Direction:</strong> opposite</div>
<div class="fact"><strong>Meshes:</strong> 1</div>
</div>
<p class="card-note">
One external gear mesh reverses the rotation direction.
</p>
</article>
<article class="result-card" style="--accent: var(--purple)">
<div class="card-top">
<div class="card-kicker">With idler</div>
<div class="ratio-badge">2:1 reduction</div>
</div>
<div class="gear-chain">12T → 16T → 24T</div>
<div class="facts">
<div class="fact"><strong>Output:</strong> ½ speed</div>
<div class="fact"><strong>Direction:</strong> same</div>
<div class="fact"><strong>Meshes:</strong> 2</div>
</div>
<p class="card-note">
The idler reverses direction twice, so the output matches the input.
</p>
</article>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1eee5);
scene.fog = new THREE.Fog(0xf1eee5, 18, 38);
const camera = new THREE.PerspectiveCamera(
41,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x667780, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dd, 4.2);
keyLight.position.set(-4, 8, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xa9c7ff, 1.35);
rimLight.position.set(8, 2, -4);
scene.add(rimLight);
const COLORS = {
input: 0xeaa139,
idler: 0x7568d8,
output: 0x258c7d,
ink: 0x172c36,
direct: 0x258c7d,
withIdler: 0x7568d8
};
const TAU = Math.PI * 2;
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
const view = {
radius: 15.8,
theta: 0,
phi: 1.43,
target: new THREE.Vector3(0, 0.15, 0)
};
const defaultView = {
radius: 15.8,
theta: 0,
phi: 1.43
};
function updateCamera() {
camera.position.setFromSphericalCoords(
view.radius,
view.phi,
view.theta
);
camera.lookAt(view.target);
}
function resetCamera() {
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.theta = THREE.MathUtils.clamp(
view.theta - dx * 0.005,
-0.65,
0.65
);
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.004,
1.18,
1.54
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.008,
12,
25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
updateCamera();
// -------------------------------------------------------------------------
// Rounded panel backgrounds and floor details
// -------------------------------------------------------------------------
function addPanel(x, width, accent) {
const group = new THREE.Group();
const panel = new THREE.Mesh(
new THREE.BoxGeometry(width, 5.75, 0.16),
new THREE.MeshStandardMaterial({
color: 0xfffdf8,
roughness: 0.95,
metalness: 0
})
);
panel.position.set(x, 0.15, -0.68);
panel.receiveShadow = true;
group.add(panel);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 4.7, 0.025),
new THREE.MeshBasicMaterial({ color: accent })
);
stripe.position.set(x - width / 2 + 0.22, 0.1, -0.57);
group.add(stripe);
const topRule = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.55, 0.025, 0.025),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.28
})
);
topRule.position.set(x, 2.77, -0.56);
group.add(topRule);
scene.add(group);
}
addPanel(-2.45, 7.35, COLORS.direct);
addPanel(5.4, 7.85, COLORS.withIdler);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xe6e3d9,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.82;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x879a9b, 0xb9c0b9);
grid.position.y = -2.8;
grid.material.transparent = true;
grid.material.opacity = 0.13;
scene.add(grid);
// -------------------------------------------------------------------------
// Canvas-generated labels
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(title, subtitle, accent, width = 1.75) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(23,44,54,0.15)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
roundedRect(ctx, 10, 10, 620, 158, 28);
ctx.fillStyle = "rgba(255,255,255,0.96)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.lineWidth = 5;
ctx.strokeStyle = accent;
roundedRect(ctx, 10, 10, 620, 158, 28);
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 30, 30, 10, 118, 5);
ctx.fill();
ctx.textBaseline = "middle";
ctx.fillStyle = "#172c36";
ctx.font = "800 38px Arial, sans-serif";
ctx.fillText(title, 62, 67);
ctx.fillStyle = "#68777c";
ctx.font = "600 27px Arial, sans-serif";
ctx.fillText(subtitle, 62, 119);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 180 / 640, 1);
sprite.renderOrder = 20;
return sprite;
}
const directHeading = makeLabel(
"WITHOUT IDLER",
"One mesh · one direction reversal",
"#258c7d",
3.55
);
directHeading.position.set(-2.45, 3.4, 0.85);
scene.add(directHeading);
const idlerHeading = makeLabel(
"WITH IDLER",
"Two meshes · direction reverses twice",
"#7568d8",
3.75
);
idlerHeading.position.set(5.4, 3.4, 0.85);
scene.add(idlerHeading);
// -------------------------------------------------------------------------
// Gear geometry
// -------------------------------------------------------------------------
function createGearGeometry(teeth, radius, thickness) {
const shape = new THREE.Shape();
const rootRadius = radius * 0.82;
const points = [];
const profile = [
[0.00, rootRadius],
[0.17, radius],
[0.61, radius],
[0.82, rootRadius]
];
for (let tooth = 0; tooth < teeth; tooth++) {
for (const [fraction, r] of profile) {
const angle = ((tooth + fraction) / teeth) * TAU;
points.push(new THREE.Vector2(
Math.cos(angle) * r,
Math.sin(angle) * r
));
}
}
shape.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i].x, points[i].y);
}
shape.closePath();
// Central axle opening.
const centerHole = new THREE.Path();
centerHole.absarc(0, 0, radius * 0.18, 0, TAU, true);
shape.holes.push(centerHole);
// Annular spoke openings.
const holeCount = teeth >= 20 ? 6 : 5;
const holeHalfAngle = 0.25;
const innerRadius = radius * 0.29;
const outerRadius = radius * 0.62;
for (let i = 0; i < holeCount; i++) {
const centerAngle = (i / holeCount) * TAU + 0.12;
const a0 = centerAngle - holeHalfAngle;
const a1 = centerAngle + holeHalfAngle;
const hole = new THREE.Path();
const p0 = new THREE.Vector2(
Math.cos(a0) * innerRadius,
Math.sin(a0) * innerRadius
);
const p1 = new THREE.Vector2(
Math.cos(a1) * innerRadius,
Math.sin(a1) * innerRadius
);
const p2 = new THREE.Vector2(
Math.cos(a1) * outerRadius,
Math.sin(a1) * outerRadius
);
const p3 = new THREE.Vector2(
Math.cos(a0) * outerRadius,
Math.sin(a0) * outerRadius
);
hole.moveTo(p0.x, p0.y);
hole.lineTo(p1.x, p1.y);
hole.lineTo(p2.x, p2.y);
hole.lineTo(p3.x, p3.y);
hole.closePath();
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: thickness,
steps: 1,
curveSegments: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: radius * 0.026,
bevelThickness: radius * 0.022
});
geometry.translate(0, 0, -thickness / 2);
geometry.computeVertexNormals();
return geometry;
}
function createGear({
x,
y,
teeth,
radius,
color,
phase = 0
}) {
const group = new THREE.Group();
group.position.set(x, y, 0);
group.rotation.z = phase;
const baseColor = new THREE.Color(color);
const sideColor = baseColor.clone().multiplyScalar(0.68);
const faceMaterial = new THREE.MeshStandardMaterial({
color: baseColor,
roughness: 0.34,
metalness: 0.13
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: sideColor,
roughness: 0.44,
metalness: 0.11
});
const geometry = createGearGeometry(teeth, radius, 0.36);
const gear = new THREE.Mesh(geometry, [
faceMaterial,
sideMaterial
]);
gear.castShadow = true;
gear.receiveShadow = true;
group.add(gear);
const edgeMaterial = new THREE.LineBasicMaterial({
color: COLORS.ink,
transparent: true,
opacity: 0.16
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 36),
edgeMaterial
);
group.add(edges);
const hubColor = baseColor.clone().lerp(
new THREE.Color(0xffffff),
0.22
);
const hubGeometry = new THREE.CylinderGeometry(
radius * 0.205,
radius * 0.205,
0.49,
32
);
hubGeometry.rotateX(Math.PI / 2);
const hub = new THREE.Mesh(
hubGeometry,
new THREE.MeshStandardMaterial({
color: hubColor,
roughness: 0.26,
metalness: 0.18
})
);
hub.castShadow = true;
group.add(hub);
const axleGeometry = new THREE.CylinderGeometry(
radius * 0.075,
radius * 0.075,
0.54,
24
);
axleGeometry.rotateX(Math.PI / 2);
const axle = new THREE.Mesh(
axleGeometry,
new THREE.MeshStandardMaterial({
color: 0x263b43,
roughness: 0.25,
metalness: 0.55
})
);
axle.castShadow = true;
group.add(axle);
scene.add(group);
return group;
}
// -------------------------------------------------------------------------
// Curved rotation arrows
// -------------------------------------------------------------------------
function addDirectionArrow(cx, cy, radius, clockwise, color) {
const points = [];
const count = 48;
const start = clockwise ? Math.PI * 0.68 : -Math.PI * 0.68;
const end = clockwise ? -Math.PI * 0.68 : Math.PI * 0.68;
for (let i = 0; i <= count; i++) {
const t = i / count;
const angle = THREE.MathUtils.lerp(start, end, t);
const r = radius + 0.18;
points.push(new THREE.Vector3(
cx + Math.cos(angle) * r,
cy + Math.sin(angle) * r,
0.34
));
}
const curve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 56, 0.026, 8, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9
})
);
scene.add(tube);
const endAngle = end;
const tangent = clockwise
? new THREE.Vector3(
Math.sin(endAngle),
-Math.cos(endAngle),
0
)
: new THREE.Vector3(
-Math.sin(endAngle),
Math.cos(endAngle),
0
);
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.31, 18),
new THREE.MeshBasicMaterial({ color })
);
cone.position.copy(points[points.length - 1]);
cone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent.normalize()
);
scene.add(cone);
}
// -------------------------------------------------------------------------
// Direct train: 12T -> 24T
// -------------------------------------------------------------------------
const directInput = createGear({
x: -4.4,
y: 0,
teeth: 12,
radius: 0.78,
color: COLORS.input
});
const directOutput = createGear({
x: -2.06,
y: 0,
teeth: 24,
radius: 1.56,
color: COLORS.output,
phase: 0.027
});
const directInputLabel = makeLabel(
"INPUT · 12T",
"ω = 1.00× · CW",
"#e99b31",
1.72
);
directInputLabel.position.set(-4.4, 1.57, 0.8);
scene.add(directInputLabel);
const directOutputLabel = makeLabel(
"OUTPUT · 24T",
"ω = 0.50× · CCW",
"#258c7d",
1.82
);
directOutputLabel.position.set(-2.06, 2.38, 0.8);
scene.add(directOutputLabel);
addDirectionArrow(-4.4, 0, 0.78, true, COLORS.input);
addDirectionArrow(-2.06, 0, 1.56, false, COLORS.output);
// -------------------------------------------------------------------------
// Idler train: 12T -> 16T -> 24T
// -------------------------------------------------------------------------
const idlerInput = createGear({
x: 2.8,
y: 0,
teeth: 12,
radius: 0.78,
color: COLORS.input
});
const idlerGear = createGear({
x: 4.62,
y: 0,
teeth: 16,
radius: 1.04,
color: COLORS.idler,
phase: 0.04
});
const idlerOutput = createGear({
x: 7.22,
y: 0,
teeth: 24,
radius: 1.56,
color: COLORS.output,
phase: 0.055
});
const idlerInputLabel = makeLabel(
"INPUT · 12T",
"ω = 1.00× · CW",
"#e99b31",
1.72
);
idlerInputLabel.position.set(2.8, 1.57, 0.8);
scene.add(idlerInputLabel);
const idlerMiddleLabel = makeLabel(
"IDLER · 16T",
"ω = 0.75× · CCW",
"#7568d8",
1.72
);
idlerMiddleLabel.position.set(4.62, 1.83, 0.8);
scene.add(idlerMiddleLabel);
const idlerOutputLabel = makeLabel(
"OUTPUT · 24T",
"ω = 0.50× · CW",
"#258c7d",
1.82
);
idlerOutputLabel.position.set(7.22, 2.38, 0.8);
scene.add(idlerOutputLabel);
addDirectionArrow(2.8, 0, 0.78, true, COLORS.input);
addDirectionArrow(4.62, 0, 1.04, false, COLORS.idler);
addDirectionArrow(7.22, 0, 1.56, true, COLORS.output);
// -------------------------------------------------------------------------
// Pulsing contact markers
// -------------------------------------------------------------------------
const contactPositions = [
[-3.62, 0],
[3.58, 0],
[5.66, 0]
];
const contactMarkers = contactPositions.map(([x, y]) => {
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 20, 12),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 20, 12),
new THREE.MeshBasicMaterial({
color: 0xffcb72,
transparent: true,
opacity: 0.22,
depthWrite: false
})
);
core.position.set(x, y, 0.48);
halo.position.copy(core.position);
scene.add(core, halo);
return { core, halo };
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const inputSpeed = -0.78; // Negative Z rotation is clockwise from the front.
const directOutputSpeed = -inputSpeed * (12 / 24);
const middleIdlerSpeed = -inputSpeed * (12 / 16);
const idlerOutputSpeed = -middleIdlerSpeed * (16 / 24);
let elapsed = 0;
let paused = false;
const clock = new THREE.Clock();
const pauseButton = document.getElementById("pauseButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "▶ Play" : "Ⅱ Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += delta;
}
directInput.rotation.z = inputSpeed * elapsed;
directOutput.rotation.z = directOutputSpeed * elapsed;
idlerInput.rotation.z = inputSpeed * elapsed;
idlerGear.rotation.z = middleIdlerSpeed * elapsed;
idlerOutput.rotation.z = idlerOutputSpeed * elapsed;
const pulse = 1 + Math.sin(elapsed * 5.5) * 0.22;
contactMarkers.forEach(({ halo }, index) => {
const offsetPulse = 1 + Math.sin(elapsed * 5.5 + index * 0.8) * 0.18;
halo.scale.setScalar(offsetPulse);
halo.material.opacity = 0.14 + (pulse - 0.78) * 0.35;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// -------------------------------------------------------------------------
// Resize handling
// -------------------------------------------------------------------------
function onResize() {
const width = innerWidth;
const height = innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(width, height);
// Fit the wide comparison on narrow displays.
if (aspect < 1.2) {
view.radius = THREE.MathUtils.clamp(
15.8 + (1.2 - aspect) * 11,
15.8,
27
);
} else {
view.radius = Math.min(view.radius, 18);
}
updateCamera();
}
addEventListener("resize", onResize);
onResize();
</script>
</body>
</html>
```