Prompt specification
Build or customize the Three.js 3D scene "Change the regulating rhythm and compare time" 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: Change the regulating rhythm and compare time
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-the-regulating-rhythm-and-compare-time-x2504
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Change the regulating rhythm and compare time. Let users adjust the simplified oscillator period driving an escapement. Show the resulting clock-rate change while distinguishing the model from a precision historical clock simulation. Return one self-contained HTML file.
Working Three.js Starter (change-the-regulating-rhythm-and-compare-time-x2504):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rhythm Between Two Clocks</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5f2;
--muted: #9fb4b8;
--panel: rgba(8, 24, 34, 0.88);
--line: rgba(180, 219, 214, 0.16);
--reference: #ff936f;
--regulated: #63ddc8;
--gold: #efd08a;
--slow: #ff936f;
--fast: #63ddc8;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.hero {
position: fixed;
z-index: 2;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
background: var(--gold);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.hero p {
max-width: 365px;
margin: 14px 0 0;
color: #c3d2d2;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
width: 370px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 22px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #31515a transparent;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-title h2 {
margin: 0;
font-size: 14px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.model-badge {
padding: 6px 9px;
border: 1px solid rgba(239, 208, 138, 0.3);
border-radius: 999px;
color: var(--gold);
background: rgba(239, 208, 138, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.section {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type { padding-top: 0; border-top: 0; }
.label-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.label-row label,
.section-title {
color: #c6d5d4;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#periodValue {
color: var(--regulated);
font-size: 25px;
font-weight: 650;
letter-spacing: -0.03em;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 7px 0 14px;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--regulated) 0,
var(--regulated) var(--fill),
#2b414a var(--fill),
#2b414a 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
appearance: none;
border: 3px solid #0b202a;
border-radius: 50%;
background: var(--regulated);
box-shadow: 0 0 0 1px rgba(99, 221, 200, 0.65), 0 0 18px rgba(99, 221, 200, 0.32);
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #0b202a;
border-radius: 50%;
background: var(--regulated);
box-shadow: 0 0 0 1px rgba(99, 221, 200, 0.65);
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: -7px;
color: #789196;
font-size: 10px;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 15px;
}
button {
min-height: 34px;
padding: 7px 11px;
border: 1px solid var(--line);
border-radius: 9px;
color: #dce8e6;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
button:hover {
border-color: rgba(99, 221, 200, 0.48);
background: rgba(99, 221, 200, 0.09);
}
button:active { transform: translateY(1px); }
button:focus-visible,
select:focus-visible,
input:focus-visible {
outline: 2px solid var(--regulated);
outline-offset: 2px;
}
.fine-button { flex: 1; font-size: 12px; }
.nominal-button {
flex: 1.35;
color: #091a20;
border-color: var(--gold);
background: var(--gold);
font-weight: 800;
}
.nominal-button:hover {
color: #06141a;
background: #f6dda5;
}
.small-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 16px;
}
.metric {
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 10px;
background: rgba(255, 255, 255, 0.032);
}
.metric span {
display: block;
color: #789196;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 15px;
font-weight: 650;
}
.rate-card {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
margin-top: 12px;
padding: 15px;
border: 1px solid rgba(239, 208, 138, 0.22);
border-radius: 12px;
background:
radial-gradient(circle at 95% 0%, rgba(239, 208, 138, 0.11), transparent 50%),
rgba(255, 255, 255, 0.035);
}
#rateValue {
display: block;
color: var(--gold);
font-size: 29px;
font-weight: 700;
line-height: 1;
letter-spacing: -0.035em;
}
#ratePercent {
display: block;
margin-top: 7px;
color: #9fb4b8;
font-size: 11px;
}
#rateStatus {
padding: 6px 8px;
border-radius: 999px;
color: var(--gold);
background: rgba(239, 208, 138, 0.1);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
select {
width: 100%;
margin-top: 11px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 9px;
color: #e8f1ef;
background: #112833;
cursor: pointer;
}
.clock-readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 13px;
}
.clock-card {
min-width: 0;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.03);
}
.clock-card.reference { border-top: 2px solid var(--reference); }
.clock-card.regulated { border-top: 2px solid var(--regulated); }
.clock-card span {
display: block;
color: #8fa5a8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.clock-card strong {
display: block;
margin-top: 7px;
overflow: hidden;
font-size: 14px;
font-weight: 600;
white-space: nowrap;
}
.separation {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
padding: 10px 12px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.17);
}
.separation span {
color: #8fa5a8;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#separationValue {
font-size: 13px;
font-weight: 700;
}
.formula {
margin: 13px 0 0;
color: #799397;
font-size: 10px;
line-height: 1.55;
}
.formula code {
color: #b8ceca;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.warning {
padding: 13px;
border: 1px solid rgba(239, 208, 138, 0.22);
border-radius: 11px;
background: rgba(239, 208, 138, 0.055);
}
.warning strong {
display: block;
color: var(--gold);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.warning p {
margin: 7px 0 0;
color: #aabbb9;
font-size: 11px;
line-height: 1.55;
}
.warning ul {
margin: 9px 0 0;
padding-left: 16px;
color: #91a6a7;
font-size: 10px;
line-height: 1.55;
}
.view-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 15px;
}
.view-row span {
color: #789196;
font-size: 10px;
}
.view-row button { min-height: 30px; font-size: 11px; }
.scene-footer {
position: fixed;
z-index: 2;
left: 30px;
bottom: 25px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 13px;
max-width: calc(100vw - 450px);
color: #83999d;
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
}
.legend {
display: inline-flex;
align-items: center;
gap: 7px;
color: #c5d2d1;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
box-shadow: 0 0 12px currentColor;
}
.dot.reference { color: var(--reference); background: var(--reference); }
.dot.regulated { color: var(--regulated); background: var(--regulated); }
.divider {
width: 1px;
height: 15px;
background: rgba(255, 255, 255, 0.15);
}
@media (max-width: 800px) {
.hero {
top: 17px;
left: 18px;
width: calc(100vw - 36px);
}
h1 { font-size: 31px; }
.hero p { max-width: 310px; font-size: 12px; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 45vh;
padding: 17px;
border-radius: 15px;
}
.scene-footer {
display: none;
}
}
@media (max-height: 700px) and (min-width: 801px) {
.panel { top: 12px; right: 12px; max-height: calc(100vh - 24px); }
.hero { top: 18px; left: 20px; }
.scene-footer { bottom: 16px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly comparison of two mechanical clocks"></canvas>
<header class="hero">
<div class="eyebrow">Low-poly comparison study · 01</div>
<h1>The rhythm<br>between two clocks</h1>
<p>Change the regulating period driving the escapement. The reference clock stays fixed while the regulated mechanism gains or loses time.</p>
</header>
<aside class="panel" aria-label="Oscillator and time comparison controls">
<div class="panel-title">
<h2>Oscillator control</h2>
<span class="model-badge">Illustrative model</span>
</div>
<section class="section">
<div class="label-row">
<label for="period">Regulating period</label>
<output id="periodValue" for="period">2.000 s</output>
</div>
<input id="period" type="range" min="1.600" max="2.400" step="0.001" value="2.000"
aria-describedby="periodHelp">
<div class="range-labels">
<span>1.600 s · faster</span>
<span>2.400 s · slower</span>
</div>
<div class="button-row">
<button class="fine-button" id="minusPeriod" type="button" aria-label="Decrease period by 0.001 seconds">− 0.001 s</button>
<button class="fine-button" id="plusPeriod" type="button" aria-label="Increase period by 0.001 seconds">+ 0.001 s</button>
<button class="nominal-button" id="nominal" type="button">Nominal 2.000 s</button>
</div>
<div class="small-grid">
<div class="metric">
<span>Oscillator frequency</span>
<strong id="frequencyValue">0.500 Hz</strong>
</div>
<div class="metric">
<span>Ideal cycles / minute</span>
<strong id="cyclesValue">30.0</strong>
</div>
</div>
<div class="rate-card" aria-live="polite">
<div>
<span id="rateValue">0 ppm</span>
<span id="ratePercent">0.0000% of reference rate</span>
</div>
<span id="rateStatus">In step</span>
</div>
</section>
<section class="section">
<div class="section-title">Compare accumulated time</div>
<select id="comparisonWindow" aria-label="Comparison duration">
<option value="60">After 1 reference minute</option>
<option value="600">After 10 reference minutes</option>
<option value="3600" selected>After 1 reference hour</option>
<option value="86400">After 1 reference day</option>
</select>
<div class="clock-readouts">
<div class="clock-card reference">
<span>Reference clock</span>
<strong id="referenceTime">01:00:00.000</strong>
</div>
<div class="clock-card regulated">
<span>Regulated clock</span>
<strong id="regulatedTime">01:00:00.000</strong>
</div>
</div>
<div class="separation">
<span>Separation</span>
<strong id="separationValue">00:00:00.000</strong>
</div>
<div class="small-grid">
<div class="metric">
<span>Error per 24 hours</span>
<strong id="dailyError">00:00:00.000</strong>
</div>
<div class="metric">
<span>Model relationship</span>
<strong>P<sub>ref</sub> ÷ P</strong>
</div>
</div>
<p class="formula" id="periodHelp">
Ideal rule: model rate = <code>P_ref / P</code>. A longer oscillator period produces fewer
releases per second, so the regulated clock advances more slowly.
</p>
</section>
<section class="section">
<div class="warning">
<strong>Model, not a precision historical simulation</strong>
<p>
This scene demonstrates how oscillator rhythm can change clock rate. It is not a certified
horological simulation or a reconstruction of a specific historical mechanism.
</p>
<ul>
<li>No temperature or amplitude drift</li>
<li>No friction, beat error, or manufacturing tolerance</li>
<li>No tooth geometry, lubrication, or escapement recoil</li>
<li>No historical calibration tables or observatory records</li>
</ul>
</div>
<div class="view-row">
<span>Drag to orbit · scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
</aside>
<footer class="scene-footer">
<span class="legend"><i class="dot reference"></i>Reference · 2.000 s</span>
<span class="legend"><i class="dot regulated"></i>Regulated · adjustable</span>
<span class="divider"></span>
<span>IDEAL OSCILLATOR · DIRECT RATE RATIO · NO DRIFT MODEL</span>
</footer>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TAU = Math.PI * 2;
const REFERENCE_PERIOD = 2.000;
const $ = id => document.getElementById(id);
const periodInput = $("period");
const comparisonInput = $("comparisonWindow");
let currentPeriod = Number(periodInput.value);
let currentRatio = REFERENCE_PERIOD / currentPeriod;
function signedNumber(value, digits = 0) {
if (Math.abs(value) < 0.5 * Math.pow(10, -digits)) return (0).toFixed(digits);
const sign = value > 0 ? "+" : "−";
return sign + Math.abs(value).toLocaleString(undefined, {
minimumFractionDigits: digits,
maximumFractionDigits: digits
});
}
function formatDuration(seconds, signed = false) {
const negative = seconds < -0.0005;
const totalMs = Math.round(Math.abs(seconds) * 1000);
const days = Math.floor(totalMs / 86400000);
const hours = Math.floor((totalMs % 86400000) / 3600000);
const minutes = Math.floor((totalMs % 3600000) / 60000);
const secs = Math.floor((totalMs % 60000) / 1000);
const millis = totalMs % 1000;
const pad = n => String(n).padStart(2, "0");
const sign = signed ? (negative ? "−" : (seconds > 0.0005 ? "+" : "")) : "";
const time = `${pad(hours)}:${pad(minutes)}:${pad(secs)}.${String(millis).padStart(3, "0")}`;
return days > 0 ? `${sign}${days}d ${time}` : `${sign}${time}`;
}
function updateReadouts() {
currentPeriod = Number(periodInput.value);
currentRatio = REFERENCE_PERIOD / currentPeriod;
const ppm = (currentRatio - 1) * 1_000_000;
const percent = (currentRatio - 1) * 100;
const windowSeconds = Number(comparisonInput.value);
const regulatedSeconds = windowSeconds * currentRatio;
const separation = regulatedSeconds - windowSeconds;
const daily = 86400 * (currentRatio - 1);
$("periodValue").textContent = `${currentPeriod.toFixed(3)} s`;
$("frequencyValue").textContent = `${(1 / currentPeriod).toFixed(3)} Hz`;
$("cyclesValue").textContent = (60 / currentPeriod).toFixed(1);
$("rateValue").textContent = `${signedNumber(ppm)} ppm`;
$("ratePercent").textContent = `${signedNumber(percent, 4)}% of reference rate`;
const rateColor = Math.abs(ppm) < 1 ? "#efd08a" : (ppm > 0 ? "#63ddc8" : "#ff936f");
$("rateValue").style.color = rateColor;
$("rateStatus").style.color = rateColor;
$("rateStatus").style.background = `${rateColor}18`;
$("rateStatus").textContent =
Math.abs(ppm) < 1 ? "In step" : (ppm > 0 ? "Faster" : "Slower");
$("referenceTime").textContent = formatDuration(windowSeconds);
$("regulatedTime").textContent = formatDuration(regulatedSeconds);
$("separationValue").textContent = formatDuration(separation, true);
$("separationValue").style.color =
Math.abs(separation) < 0.0005 ? "#efd08a" : (separation > 0 ? "#63ddc8" : "#ff936f");
$("dailyError").textContent = formatDuration(daily, true);
const fill = ((currentPeriod - 1.6) / (2.4 - 1.6)) * 100;
periodInput.style.setProperty("--fill", `${fill}%`);
if (regulatedClock) {
regulatedClock.label.update(`REGULATED · ${currentPeriod.toFixed(3)} s`);
}
}
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const canvas = $("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 12, 26);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const palette = {
navy: 0x172a3a,
navyDark: 0x0c1b28,
cream: 0xf0e4c4,
gold: 0xd6aa58,
metal: 0x68818a,
darkMetal: 0x233a46
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.08,
flatShading: true,
...options
});
}
const materials = {
navy: standard(palette.navy),
navyDark: standard(palette.navyDark),
cream: standard(palette.cream, { roughness: 0.95 }),
gold: standard(palette.gold, { metalness: 0.3, roughness: 0.58 }),
metal: standard(palette.metal, { metalness: 0.42, roughness: 0.55 }),
darkMetal: standard(palette.darkMetal, { metalness: 0.28 })
};
const hemisphere = new THREE.HemisphereLight(0xc5e4ea, 0x101820, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd7, 3.3);
keyLight.position.set(3.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const referenceLight = new THREE.PointLight(0xff8e68, 22, 8, 2);
referenceLight.position.set(-4, 4.5, 3);
scene.add(referenceLight);
const regulatedLight = new THREE.PointLight(0x55dfc6, 24, 8, 2);
regulatedLight.position.set(4, 4.5, 3);
scene.add(regulatedLight);
function addBox(parent, size, position, material, rotation = null) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radius, height, position, material, segments = 8, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Studio floor and faceted platform.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
standard(0x091720, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.11;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.35, 5.55, 0.2, 48),
standard(0x102633, { roughness: 0.95 })
);
platform.position.y = 0;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(4.95, 0.018, 5, 64),
new THREE.MeshBasicMaterial({ color: 0x2a5960 })
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = 0.105;
scene.add(platformRing);
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(28, 14),
standard(0x0a1b27, { roughness: 1 })
);
backdrop.position.set(0, 5.5, -4.7);
scene.add(backdrop);
const archMaterial = new THREE.MeshBasicMaterial({
color: 0x1b3947,
transparent: true,
opacity: 0.92
});
const arch = new THREE.Mesh(
new THREE.TorusGeometry(3.0, 0.026, 4, 48, Math.PI),
archMaterial
);
arch.position.set(0, 0.12, -3.9);
arch.scale.y = 1.18;
scene.add(arch);
const outerArch = new THREE.Mesh(
new THREE.TorusGeometry(4.15, 0.018, 4, 48, Math.PI),
new THREE.MeshBasicMaterial({ color: 0x15313f })
);
outerArch.position.set(0, 0.12, -4.25);
outerArch.scale.y = 1.2;
scene.add(outerArch);
// A restrained row of faceted stones gives the platform a low-poly scale.
const stoneGeometry = new THREE.IcosahedronGeometry(0.12, 0);
const stoneMaterial = standard(0x193846);
for (let i = 0; i < 13; i++) {
const angle = (i / 13) * TAU + 0.2;
const radius = 4.7 + (i % 3) * 0.12;
const stone = new THREE.Mesh(stoneGeometry, stoneMaterial);
stone.position.set(
Math.cos(angle) * radius,
0.1 + (i % 2) * 0.025,
Math.sin(angle) * radius
);
stone.scale.setScalar(0.65 + (i % 4) * 0.17);
stone.rotation.set(i * 0.41, i * 0.67, i * 0.22);
stone.castShadow = true;
scene.add(stone);
}
function makeGear(radius, teeth, depth, material) {
const group = new THREE.Group();
const rootRadius = radius * 0.79;
const shape = new THREE.Shape();
for (let i = 0; i < teeth * 4; i++) {
const angle = (i / (teeth * 4)) * TAU;
const toothPhase = i % 4;
const r = (toothPhase === 1 || toothPhase === 2) ? radius : rootRadius;
const x = Math.cos(angle) * r;
const y = Math.sin(angle) * r;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
geometry.translate(0, 0, -depth / 2);
const gear = new THREE.Mesh(geometry, material);
gear.castShadow = true;
gear.receiveShadow = true;
group.add(gear);
const spokeGeometry = new THREE.BoxGeometry(radius * 1.12, 0.065, depth * 1.12);
for (let i = 0; i < 3; i++) {
const spoke = new THREE.Mesh(spokeGeometry, materials.darkMetal);
spoke.rotation.z = i * Math.PI / 3;
spoke.castShadow = true;
group.add(spoke);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.18, radius * 0.18, depth * 1.5, 10),
materials.gold
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
group.add(hub);
return group;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, accentColor) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 144;
const ctx = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = 4;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.75, 0.62, 1);
sprite.renderOrder = 20;
function update(value) {
ctx.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
ctx.fillStyle = "rgba(6, 18, 26, 0.88)";
roundedRect(ctx, 8, 8, 624, 128, 22);
ctx.fill();
ctx.strokeStyle = accentColor;
ctx.globalAlpha = 0.65;
ctx.lineWidth = 3;
roundedRect(ctx, 8, 8, 624, 128, 22);
ctx.stroke();
ctx.globalAlpha = 1;
ctx.fillStyle = accentColor;
roundedRect(ctx, 28, 30, 8, 84, 4);
ctx.fill();
ctx.fillStyle = "#edf5f1";
ctx.font = "700 34px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(value, 60, 73);
texture.needsUpdate = true;
}
update(text);
return { sprite, update };
}
function createClock(x, accentHex, initialLabel) {
const root = new THREE.Group();
root.position.set(x, 0.11, 0);
const accent = standard(accentHex, {
emissive: accentHex,
emissiveIntensity: 0.08,
roughness: 0.52
});
// Stepped pedestal.
addBox(root, [2.18, 0.27, 1.28], [0, 0.2, 0], materials.navyDark);
addBox(root, [1.94, 0.08, 1.08], [0, 0.38, 0], materials.navy);
addBox(root, [1.42, 0.055, 0.035], [0, 0.23, 0.665], accent);
// Open lower movement.
addBox(root, [0.16, 1.75, 0.78], [-0.76, 1.22, 0], materials.navy);
addBox(root, [0.16, 1.75, 0.78], [0.76, 1.22, 0], materials.navy);
addBox(root, [1.68, 0.14, 0.78], [0, 2.06, 0], materials.navy);
addBox(root, [1.55, 0.08, 0.79], [0, 0.47, 0], materials.navy);
// Upper clock case.
addBox(root, [1.72, 1.68, 0.72], [0, 2.95, 0], materials.navy);
addBox(root, [1.82, 0.10, 0.79], [0, 2.14, 0], materials.navyDark);
addBox(root, [0.055, 1.35, 0.045], [-0.8, 3.0, 0.383], accent);
addBox(root, [0.055, 1.35, 0.045], [0.8, 3.0, 0.383], accent);
// Faceted roof.
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.23, 0.83, 4),
materials.navyDark
);
roof.position.set(0, 4.2, 0);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
root.add(roof);
const roofBand = new THREE.Mesh(
new THREE.ConeGeometry(1.13, 0.16, 4),
accent
);
roofBand.position.set(0, 3.86, 0);
roofBand.rotation.y = Math.PI / 4;
root.add(roofBand);
const finial = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.11, 0),
materials.gold
);
finial.position.set(0, 4.72, 0);
finial.castShadow = true;
root.add(finial);
// Dial.
const dial = new THREE.Mesh(
new THREE.CircleGeometry(0.615, 32),
materials.cream
);
dial.position.set(0, 3.0, 0.395);
dial.receiveShadow = true;
root.add(dial);
const dialFrame = new THREE.Mesh(
new THREE.TorusGeometry(0.64, 0.055, 6, 32),
materials.gold
);
dialFrame.position.set(0, 3.0, 0.425);
dialFrame.castShadow = true;
root.add(dialFrame);
const tickGeometry = new THREE.BoxGeometry(0.026, 0.095, 0.026);
for (let i = 0; i < 12; i++) {
const angle = i / 12 * TAU;
const tick = new THREE.Mesh(tickGeometry, materials.navyDark);
tick.position.set(
Math.sin(angle) * 0.49,
3.0 + Math.cos(angle) * 0.49,
0.455
);
tick.rotation.z = -angle;
root.add(tick);
}
const handRoot = new THREE.Group();
handRoot.position.set(0, 3.0, 0.485);
root.add(handRoot);
function addHand(length, width, z, material) {
const group = new THREE.Group();
group.position.z = z;
const hand = new THREE.Mesh(
new THREE.BoxGeometry(width, length, 0.022),
material
);
hand.position.y = length * 0.40;
hand.castShadow = true;
group.add(hand);
handRoot.add(group);
return group;
}
const hourHand = addHand(0.29, 0.045, 0, materials.navyDark);
const minuteHand = addHand(0.43, 0.031, 0.015, materials.navyDark);
const secondHand = addHand(0.51, 0.014, 0.03, accent);
const handCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.035, 10),
accent
);
handCap.rotation.x = Math.PI / 2;
handCap.position.set(0, 3.0, 0.525);
root.add(handCap);
// Beat lamp.
const beatMaterial = standard(accentHex, {
emissive: accentHex,
emissiveIntensity: 0.35,
roughness: 0.35
});
const beatLamp = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.065, 0),
beatMaterial
);
beatLamp.position.set(0.64, 3.28, 0.455);
root.add(beatLamp);
// Gears.
const gearA = makeGear(0.32, 28, 0.11, materials.gold);
gearA.position.set(-0.37, 1.48, 0.51);
root.add(gearA);
const gearB = makeGear(0.235, 20, 0.10, accent);
gearB.position.set(0.30, 1.54, 0.53);
root.add(gearB);
// Pendulum.
const pendulum = new THREE.Group();
pendulum.position.set(0, 1.92, 0.57);
root.add(pendulum);
addBox(pendulum, [0.055, 1.02, 0.055], [0, -0.51, 0], materials.metal);
const bob = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.235, 1),
materials.gold
);
bob.position.set(0, -1.03, 0);
bob.castShadow = true;
pendulum.add(bob);
const bobBand = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.245, 8),
accent
);
bobBand.rotation.z = Math.PI / 2;
bobBand.position.set(0, -1.03, 0);
pendulum.add(bobBand);
const pivot = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.16, 10),
materials.darkMetal
);
pivot.rotation.x = Math.PI / 2;
pivot.position.set(0, 1.92, 0.55);
root.add(pivot);
// Simplified anchor escapement.
const anchor = new THREE.Group();
anchor.position.set(0, 1.88, 0.62);
root.add(anchor);
addBox(anchor, [0.48, 0.055, 0.05], [0, 0, 0], materials.metal);
const leftPallet = addBox(
anchor, [0.055, 0.22, 0.05], [-0.22, -0.08, 0], accent,
[0, 0, -0.42]
);
const rightPallet = addBox(
anchor, [0.055, 0.22, 0.05], [0.22, -0.08, 0], accent,
[0, 0, 0.42]
);
leftPallet.castShadow = rightPallet.castShadow = true;
const label = makeLabel(initialLabel, `#${accentHex.toString(16).padStart(6, "0")}`);
label.sprite.position.set(0, 5.08, 0.05);
root.add(label.sprite);
scene.add(root);
return {
root,
gearA,
gearB,
pendulum,
anchor,
beatMaterial,
label,
hourHand,
minuteHand,
secondHand
};
}
const referenceClock = createClock(
-1.72,
0xff936f,
"REFERENCE · 2.000 s"
);
const regulatedClock = createClock(
1.72,
0x63ddc8,
`REGULATED · ${currentPeriod.toFixed(3)} s`
);
function setClockHands(clock, elapsedSeconds) {
const hourAngle = -((elapsedSeconds % 43200) / 43200) * TAU;
const minuteAngle = -((elapsedSeconds % 3600) / 3600) * TAU;
const secondAngle = -((elapsedSeconds % 60) / 60) * TAU;
clock.hourHand.rotation.z = hourAngle;
clock.minuteHand.rotation.z = minuteAngle;
clock.secondHand.rotation.z = secondAngle;
}
function animateClock(clock, elapsed, period, displayedTime) {
const cycle = Math.floor(elapsed / period);
const phase = (elapsed % period) / period;
const swing = Math.sin((elapsed / period) * TAU);
clock.pendulum.rotation.z = swing * 0.31;
clock.anchor.rotation.z = swing * 0.055;
clock.gearA.rotation.z = -cycle * TAU / 28;
clock.gearB.rotation.z = cycle * TAU / 20;
const flash = Math.pow(1 - phase, 7);
clock.beatMaterial.emissiveIntensity = 0.28 + flash * 2.9;
setClockHands(clock, displayedTime);
}
// ---------------------------------------------------------------------
// Direct camera controls, implemented without Three.js addons.
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.45, 2.42, 0);
let cameraDistance = 9.6;
let cameraYaw = 0.055;
let cameraPitch = 0.215;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function applyCamera() {
const cp = Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * cp * cameraDistance,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * cp * cameraDistance
);
camera.lookAt(cameraTarget);
}
function resetView() {
cameraDistance = 9.6;
cameraYaw = 0.055;
cameraPitch = 0.215;
cameraTarget.x = window.innerWidth > 800 ? 0.45 : 0;
applyCamera();
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraYaw -= dx * 0.005;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.0035, -0.12, 0.78);
applyCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.007,
6.2,
14.5
);
applyCamera();
}, { passive: false });
$("resetView").addEventListener("click", resetView);
// ---------------------------------------------------------------------
// UI events and animation
// ---------------------------------------------------------------------
periodInput.addEventListener("input", updateReadouts);
comparisonInput.addEventListener("change", updateReadouts);
$("minusPeriod").addEventListener("click", () => {
periodInput.value = Math.max(1.6, currentPeriod - 0.001).toFixed(3);
updateReadouts();
});
$("plusPeriod").addEventListener("click", () => {
periodInput.value = Math.min(2.4, currentPeriod + 0.001).toFixed(3);
updateReadouts();
});
$("nominal").addEventListener("click", () => {
periodInput.value = "2.000";
updateReadouts();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
cameraTarget.x = width > 800 ? 0.45 : 0;
if (width <= 800) cameraDistance = Math.max(cameraDistance, 10.3);
applyCamera();
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
let elapsed = 0;
let referenceDisplayedTime = 0;
let regulatedDisplayedTime = 0;
function animate(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
elapsed += dt;
// Dial motion is accelerated 60× so rate differences are visible.
// Integrating the displayed time prevents jumps when the period changes.
referenceDisplayedTime += dt * 60;
regulatedDisplayedTime += dt * 60 * currentRatio;
animateClock(
referenceClock,
elapsed,
REFERENCE_PERIOD,
referenceDisplayedTime
);
animateClock(
regulatedClock,
elapsed,
currentPeriod,
regulatedDisplayedTime
);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateReadouts();
resize();
requestAnimationFrame(animate);
</script>
</body>
</html>
```