Prompt specification
Build or customize the Three.js 3D scene "Clock regulation museum corner" 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: Clock regulation museum corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/clock-regulation-museum-corner-x1415
Scene Description Prompt:
Clock regulation museum corner. Compose a pendulum clock model, length-adjustment scale, and timing markers; connect longer length to slower ideal oscillation without modeling a full escapement mechanism. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (clock-regulation-museum-corner-x1415):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock Regulation — Museum Corner</title>
<style>
:root {
color-scheme: dark;
--ink: #f3e8ce;
--muted: #c8bca4;
--gold: #e4a84b;
--teal: #55b9b1;
--panel: rgba(30, 27, 24, 0.91);
--line: rgba(228, 168, 75, 0.42);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9aa91;
font-family: "Courier New", Courier, monospace;
}
#scene {
position: fixed;
inset: 0;
display: block;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(330px, calc(100vw - 36px));
padding: 18px;
color: var(--ink);
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
border: 1px solid var(--line);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.30),
inset 0 0 0 3px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(12px);
}
#hud::before {
content: "";
position: absolute;
top: 7px;
right: 7px;
width: 7px;
height: 7px;
background: var(--gold);
box-shadow:
-13px 0 0 rgba(228, 168, 75, 0.45),
-26px 0 0 rgba(228, 168, 75, 0.22);
}
h1 {
margin: 0 0 8px;
color: var(--gold);
font-size: 18px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#lengthValue {
color: var(--gold);
font-size: 16px;
font-weight: bold;
}
input[type="range"] {
width: 100%;
margin: 0 0 7px;
accent-color: var(--gold);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 16px 0 12px;
}
.stat {
min-height: 60px;
padding: 9px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.075);
}
.stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat strong {
color: var(--ink);
font-size: 15px;
}
#comparison {
margin: 0 0 13px;
padding: 9px 10px;
color: var(--ink);
background: rgba(228, 168, 75, 0.09);
border-left: 3px solid var(--gold);
font-size: 11px;
line-height: 1.45;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
padding: 10px 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(228, 168, 75, 0.45);
border-radius: 0;
font: bold 10px "Courier New", Courier, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
color: #1d1a17;
background: var(--gold);
}
.note {
margin: 13px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
#museumTag {
position: fixed;
z-index: 8;
top: 18px;
right: 18px;
padding: 10px 13px;
color: #40372c;
background: rgba(239, 227, 197, 0.88);
border: 1px solid rgba(70, 57, 39, 0.28);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
font-size: 10px;
font-weight: bold;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 15px;
transform: translateX(-50%);
padding: 8px 13px;
color: #f5e9cd;
background: rgba(35, 30, 25, 0.75);
border: 1px solid rgba(255, 255, 255, 0.12);
font-size: 9px;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: #f3e8ce;
background: #28231e;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 700px) {
#hud {
top: 10px;
left: 10px;
width: min(285px, calc(100vw - 20px));
padding: 14px;
}
#museumTag {
display: none;
}
.stats {
margin-top: 12px;
}
#hint {
max-width: calc(100vw - 20px);
white-space: normal;
}
}
</style>
</head>
<body>
<section id="hud" aria-label="Pendulum clock controls">
<h1>Clock Regulation</h1>
<p class="subtitle">
Museum study of the ideal small-angle pendulum. Change the effective
length and watch the beat markers spread apart.
</p>
<label class="control-label" for="lengthSlider">
<span>Effective length</span>
<output id="lengthValue" for="lengthSlider">1.00 m</output>
</label>
<input
id="lengthSlider"
type="range"
min="0.60"
max="1.60"
step="0.01"
value="1.00"
aria-label="Pendulum length in meters"
/>
<div class="range-ends">
<span>0.60 m · faster</span>
<span>1.60 m · slower</span>
</div>
<div class="stats">
<div class="stat">
<span>Ideal period</span>
<strong id="periodValue">2.01 s</strong>
</div>
<div class="stat">
<span>Frequency</span>
<strong id="frequencyValue">0.499 Hz</strong>
</div>
<div class="stat">
<span>Beats / minute</span>
<strong id="bpmValue">29.9</strong>
</div>
<div class="stat">
<span>Relative rate</span>
<strong id="rateValue">100%</strong>
</div>
</div>
<p id="comparison">
At the 1.00 m reference length, this pendulum has the reference rate.
</p>
<div class="buttons">
<button id="pauseButton" type="button">Pause motion</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<p class="note">
T = 2π√(L/g), with g = 9.81 m/s². The model intentionally omits a full
escapement mechanism; it demonstrates ideal oscillation and regulation.
</p>
</section>
<div id="museumTag">Museum Corner · Precision Study 04</div>
<div id="hint">
Drag to orbit · Shift-drag to pan · Wheel to zoom · Adjust the length slider
</div>
<div id="loading">Assembling the museum study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.domElement.id = "scene";
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9aa91");
scene.fog = new THREE.Fog("#b9aa91", 15, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight("#fff0d2", "#514b43", 1.55);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff0cf", 3.1);
keyLight.position.set(4.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.PointLight("#efc078", 24, 18, 2);
fillLight.position.set(-5, 4.8, 4);
scene.add(fillLight);
const rimLight = new THREE.PointLight("#8ccac3", 12, 15, 2);
rimLight.position.set(5, 5.8, -1.6);
scene.add(rimLight);
// Shared unit cube: every modeled object remains visibly block-built.
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, roughness = 0.78, metalness = 0.0) {
const key = `${color}|${roughness}|${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function block(
parent,
x,
y,
z,
width,
height,
depth,
color,
options = {}
) {
const material =
options.material ||
(color && color.isMaterial ? color : getMaterial(color));
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
for (let i = group.children.length - 1; i >= 0; i--) {
group.remove(group.children[i]);
}
}
// -------------------------------------------------------------------------
// Canvas-backed block signs
// -------------------------------------------------------------------------
function makeTexture(width = 1024, height = 256) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
return { canvas, context, texture };
}
function paintSign(
textureData,
title,
subtitle = "",
options = {}
) {
const { context: ctx, canvas, texture } = textureData;
const w = canvas.width;
const h = canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = options.background || "#e9ddbd";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = options.border || "#755b35";
ctx.lineWidth = options.lineWidth || 10;
ctx.strokeRect(7, 7, w - 14, h - 14);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.titleColor || "#342a20";
if (subtitle) {
ctx.font = `700 ${options.titleSize || 62}px monospace`;
ctx.fillText(title, w / 2, h * 0.39, w - 70);
ctx.font = `700 ${options.subtitleSize || 28}px monospace`;
ctx.fillStyle = options.subtitleColor || "#6b5030";
ctx.fillText(subtitle, w / 2, h * 0.72, w - 60);
} else {
ctx.font = `700 ${options.titleSize || 58}px monospace`;
ctx.fillText(title, w / 2, h / 2, w - 60);
}
texture.needsUpdate = true;
}
function signFromTexture(
parent,
x,
y,
z,
width,
height,
textureData,
sideColor = "#30271f",
depth = 0.07
) {
const side = getMaterial(sideColor, 0.82);
const front = new THREE.MeshStandardMaterial({
map: textureData.texture,
roughness: 0.88,
metalness: 0
});
const mesh = new THREE.Mesh(
unitBox,
[side, side, side, side, front, side]
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeSign(
parent,
x,
y,
z,
width,
height,
title,
subtitle = "",
options = {}
) {
const textureData = makeTexture(
options.textureWidth || 1024,
options.textureHeight || 256
);
paintSign(textureData, title, subtitle, options);
return signFromTexture(
parent,
x,
y,
z,
width,
height,
textureData,
options.sideColor,
options.depth
);
}
// -------------------------------------------------------------------------
// Museum corner: tiled floor, walls, baseboards, display plinth
// -------------------------------------------------------------------------
const floorColors = ["#8c806f", "#918674", "#847a69", "#978b78"];
const wallColors = ["#c6b99f", "#c1b39a", "#cbbda2", "#b9aa91"];
for (let x = -7; x <= 7; x++) {
for (let z = -4; z <= 5; z++) {
const color = floorColors[(x * 3 + z * 5 + 40) % floorColors.length];
block(scene, x, -0.11, z, 0.965, 0.2, 0.965, color, {
cast: false
});
}
}
for (let row = 0; row < 8; row++) {
for (let x = -7; x <= 7; x++) {
const color = wallColors[(row * 2 + x + 28) % wallColors.length];
block(
scene,
x,
0.35 + row * 0.7,
-3.82,
0.965,
0.675,
0.25,
color,
{ cast: false }
);
}
}
for (let row = 0; row < 8; row++) {
for (let z = -3; z <= 4; z++) {
const color = wallColors[(row + z + 32) % wallColors.length];
block(
scene,
-7.32,
0.35 + row * 0.7,
z,
0.25,
0.675,
0.965,
color,
{ cast: false }
);
}
}
for (let x = -7; x <= 7; x++) {
block(scene, x, 0.2, -3.57, 0.98, 0.38, 0.18, "#675442", {
cast: false
});
}
for (let z = -3; z <= 4; z++) {
block(scene, -7.16, 0.2, z, 0.18, 0.38, 0.98, "#675442", {
cast: false
});
}
// Display plinth assembled from stone blocks.
for (let x = 0; x < 4; x++) {
for (let z = 0; z < 2; z++) {
block(
scene,
-4.55 + x * 0.96,
0.16,
-0.78 + z * 0.96,
0.92,
0.3,
0.92,
(x + z) % 2 ? "#6d685e" : "#767066",
{ cast: false }
);
}
}
// Wall gallery heading.
makeSign(
scene,
2.25,
4.83,
-3.62,
5.45,
0.72,
"CLOCK REGULATION",
"THE MUSEUM CORNER / IDEAL PENDULUM STUDY",
{
textureWidth: 1400,
textureHeight: 220,
titleSize: 64,
subtitleSize: 27,
background: "#e8dbb9",
border: "#8d6132",
sideColor: "#503b27"
}
);
makeSign(
scene,
-5.35,
1.55,
-3.62,
2.45,
0.82,
"IDEAL MOTION",
"ESCAPEMENT INTENTIONALLY OMITTED",
{
textureWidth: 900,
textureHeight: 280,
titleSize: 46,
subtitleSize: 22,
background: "#d8c9a9",
border: "#765736",
sideColor: "#4a3929"
}
);
// -------------------------------------------------------------------------
// Voxel pendulum clock
// -------------------------------------------------------------------------
const clockX = -3.0;
const pivotY = 3.23;
const darkWood = "#493025";
const midWood = "#674431";
const lightWood = "#8a5c3b";
const trimWood = "#b07a46";
const brass = getMaterial("#d5a348", 0.34, 0.62);
const darkBrass = getMaterial("#8e652b", 0.42, 0.58);
// Feet.
block(scene, clockX - 0.81, 0.57, -0.05, 0.42, 0.48, 0.78, darkWood);
block(scene, clockX + 0.81, 0.57, -0.05, 0.42, 0.48, 0.78, darkWood);
block(scene, clockX - 0.81, 0.37, 0.12, 0.58, 0.14, 0.88, midWood);
block(scene, clockX + 0.81, 0.37, 0.12, 0.58, 0.14, 0.88, midWood);
// Back wall of the case, built from narrow planks.
for (let i = 0; i < 9; i++) {
const color = i % 3 === 0 ? midWood : darkWood;
block(
scene,
clockX - 0.9 + i * 0.225,
2.78,
-0.43,
0.21,
3.75,
0.15,
color
);
}
// Case columns.
block(scene, clockX - 1.04, 2.9, -0.02, 0.3, 4.1, 0.78, midWood);
block(scene, clockX + 1.04, 2.9, -0.02, 0.3, 4.1, 0.78, midWood);
block(scene, clockX - 1.08, 2.88, 0.39, 0.12, 4.08, 0.12, trimWood);
block(scene, clockX + 1.08, 2.88, 0.39, 0.12, 4.08, 0.12, trimWood);
// Lower and upper rails.
block(scene, clockX, 0.89, 0.02, 2.35, 0.22, 0.84, darkWood);
block(scene, clockX, 3.47, 0.0, 2.35, 0.2, 0.82, midWood);
block(scene, clockX, 4.95, 0.0, 2.42, 0.24, 0.87, darkWood);
// Stepped crown.
block(scene, clockX, 5.12, -0.01, 2.55, 0.2, 0.92, lightWood);
block(scene, clockX, 5.3, -0.02, 2.31, 0.16, 0.84, midWood);
block(scene, clockX, 5.46, -0.02, 2.03, 0.16, 0.73, lightWood);
block(scene, clockX, 5.61, -0.02, 0.28, 0.24, 0.28, trimWood);
block(scene, clockX, 5.78, -0.02, 0.13, 0.13, 0.13, brass);
// Dial: a tiled square face made from individual cream voxel blocks.
const faceY = 4.28;
const faceZ = 0.45;
const tileSize = 0.18;
const tileGap = 0.014;
const dialSpan = 9;
for (let row = 0; row < dialSpan; row++) {
for (let col = 0; col < dialSpan; col++) {
const color =
(row + col) % 5 === 0 ? "#eee5ce" : "#f4ecd8";
block(
scene,
clockX + (col - 4) * (tileSize + tileGap),
faceY + (4 - row) * (tileSize + tileGap),
faceZ,
tileSize,
tileSize,
0.09,
color,
{ cast: false }
);
}
}
// Square dial frame.
block(scene, clockX - 0.9, faceY, 0.48, 0.14, 1.98, 0.2, lightWood);
block(scene, clockX + 0.9, faceY, 0.48, 0.14, 1.98, 0.2, lightWood);
block(scene, clockX, faceY + 0.91, 0.48, 1.94, 0.14, 0.2, lightWood);
block(scene, clockX, faceY - 0.91, 0.48, 1.94, 0.14, 0.2, lightWood);
// Twelve visible block markers.
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const major = i % 3 === 0;
const radius = 0.67;
const marker = block(
scene,
clockX + Math.sin(angle) * radius,
faceY + Math.cos(angle) * radius,
0.55,
major ? 0.075 : 0.055,
major ? 0.22 : 0.14,
0.065,
major ? "#392d23" : "#655440",
{ cast: false }
);
marker.rotation.z = -angle;
}
// Hands are rectangular blocks pivoting around the dial center.
const hourHand = new THREE.Group();
const minuteHand = new THREE.Group();
hourHand.position.set(clockX, faceY, 0.61);
minuteHand.position.set(clockX, faceY, 0.67);
scene.add(hourHand, minuteHand);
block(hourHand, 0, 0.18, 0, 0.09, 0.42, 0.05, "#7a2f25");
block(minuteHand, 0, 0.28, 0, 0.065, 0.62, 0.05, "#302720");
block(scene, clockX, faceY, 0.73, 0.18, 0.18, 0.11, brass);
// Fixed pivot and bearing.
block(scene, clockX, pivotY, 0.43, 0.46, 0.2, 0.32, darkBrass);
block(scene, clockX, pivotY, 0.62, 0.16, 0.16, 0.12, brass);
const pendulum = new THREE.Group();
pendulum.position.set(clockX, pivotY, 0.58);
scene.add(pendulum);
const pendulumParts = new THREE.Group();
const lengthGuide = new THREE.Group();
pendulum.add(pendulumParts);
scene.add(lengthGuide);
// -------------------------------------------------------------------------
// Physical length-adjustment scale
// -------------------------------------------------------------------------
const scaleX = -1.26;
block(scene, scaleX, 2.49, 0.18, 0.32, 1.98, 0.22, darkWood);
block(scene, scaleX, 2.49, 0.34, 0.23, 1.83, 0.08, "#d5c59e", {
cast: false
});
block(scene, scaleX, 0.59, 0.08, 0.18, 0.75, 0.18, darkWood);
block(scene, scaleX, 0.28, 0.08, 0.72, 0.14, 0.58, midWood);
makeSign(
scene,
scaleX,
3.63,
0.32,
1.3,
0.32,
"LENGTH / m",
"",
{
textureWidth: 700,
textureHeight: 180,
titleSize: 44,
background: "#e5d8b7",
border: "#775735",
sideColor: "#4b3525"
}
);
for (let tenth = 6; tenth <= 16; tenth++) {
const length = tenth / 10;
const y = pivotY - length;
const major = tenth % 2 === 0;
block(
scene,
scaleX - 0.13,
y,
0.42,
major ? 0.25 : 0.16,
major ? 0.045 : 0.035,
0.08,
major ? "#382b21" : "#735e42",
{ cast: false }
);
if (major) {
makeSign(
scene,
scaleX + 0.35,
y,
0.39,
0.45,
0.2,
length.toFixed(1),
"",
{
textureWidth: 220,
textureHeight: 120,
titleSize: 43,
background: "#e9ddbd",
border: "#a38a62",
sideColor: "#59432e",
depth: 0.045
}
);
}
}
const scaleCarriage = block(
scene,
scaleX,
pivotY - 1,
0.49,
0.48,
0.12,
0.18,
"#e79b36",
{ material: getMaterial("#e79b36", 0.45, 0.2) }
);
const lengthText = makeTexture(520, 180);
paintSign(lengthText, "1.00 m", "CURRENT LENGTH", {
titleSize: 62,
subtitleSize: 20,
background: "#e9ddbd",
border: "#9b703d"
});
signFromTexture(
scene,
scaleX,
1.23,
0.37,
1.06,
0.38,
lengthText,
"#4b3525",
0.07
);
// -------------------------------------------------------------------------
// Timing board with markers recomputed for the current period
// -------------------------------------------------------------------------
const boardX = 2.25;
const timelineStart = 0.55;
const timelineWidth = 3.60;
const timelineY = 2.17;
block(scene, boardX, 2.65, -3.53, 4.9, 2.8, 0.22, darkWood);
block(scene, boardX, 2.65, -3.38, 4.58, 2.47, 0.08, "#e5d8b8", {
cast: false
});
block(scene, boardX, 3.88, -3.33, 4.7, 0.1, 0.12, trimWood);
block(scene, boardX, 1.42, -3.33, 4.7, 0.1, 0.12, trimWood);
makeSign(
scene,
boardX,
3.68,
-3.31,
4.25,
0.38,
"TIMING MARKERS / FIXED 6 SECOND WINDOW",
"",
{
textureWidth: 1300,
textureHeight: 160,
titleSize: 40,
background: "#e9ddbd",
border: "#987044",
sideColor: "#4b3525"
}
);
const formulaTexture = makeTexture(1200, 240);
const formulaSign = signFromTexture(
scene,
boardX,
3.16,
-3.30,
4.18,
0.46,
formulaTexture,
"#4b3525",
0.065
);
makeSign(
scene,
boardX,
2.73,
-3.30,
4.1,
0.28,
"LONGER LENGTH => WIDER BEAT SPACING",
"",
{
textureWidth: 1200,
textureHeight: 130,
titleSize: 31,
background: "#e5d8b8",
border: "#a88a61",
sideColor: "#4b3525"
}
);
// Fixed half-second ruler.
for (let t = 0; t <= 6.0001; t += 0.5) {
const x = timelineStart + (t / 6) * timelineWidth;
block(
scene,
x,
timelineY,
-3.18,
0.035,
t % 1 === 0 ? 0.15 : 0.09,
0.07,
"#9c8c6d",
{ cast: false }
);
}
block(
scene,
timelineStart + timelineWidth / 2,
timelineY,
-3.22,
timelineWidth + 0.08,
0.045,
0.08,
"#66533b",
{ cast: false }
);
const timingMarkers = new THREE.Group();
scene.add(timingMarkers);
makeSign(
scene,
timelineStart - 0.03,
1.76,
-3.28,
0.72,
0.25,
"0 s",
"",
{
textureWidth: 300,
textureHeight: 110,
titleSize: 38,
background: "#e9ddbd",
border: "#a58a62",
sideColor: "#4b3525",
depth: 0.045
}
);
makeSign(
scene,
timelineStart + timelineWidth / 2,
1.76,
-3.28,
0.72,
0.25,
"3 s",
"",
{
textureWidth: 300,
textureHeight: 110,
titleSize: 38,
background: "#e9ddbd",
border: "#a58a62",
sideColor: "#4b3525",
depth: 0.045
}
);
makeSign(
scene,
timelineStart + timelineWidth + 0.03,
1.76,
-3.28,
0.72,
0.25,
"6 s",
"",
{
textureWidth: 300,
textureHeight: 110,
titleSize: 38,
background: "#e9ddbd",
border: "#a58a62",
sideColor: "#4b3525",
depth: 0.045
}
);
makeSign(
scene,
boardX,
1.48,
-3.29,
3.9,
0.25,
"ORANGE = IDEAL BEAT / TEAL = HALF BEAT",
"",
{
textureWidth: 1200,
textureHeight: 120,
titleSize: 26,
background: "#e5d8b8",
border: "#a58a62",
sideColor: "#4b3525",
depth: 0.045
}
);
const cursor = new THREE.Group();
scene.add(cursor);
block(cursor, 0, 0, 0, 0.13, 0.58, 0.12, "#e23e32", {
material: getMaterial("#e23e32", 0.42, 0.08)
});
block(cursor, 0, 0.25, -0.02, 0.22, 0.13, 0.16, "#e23e32", {
material: getMaterial("#e23e32", 0.42, 0.08)
});
// -------------------------------------------------------------------------
// Dynamic length and timing logic
// -------------------------------------------------------------------------
const GRAVITY = 9.81;
const REFERENCE_LENGTH = 1.0;
const REFERENCE_PERIOD =
2 * Math.PI * Math.sqrt(REFERENCE_LENGTH / GRAVITY);
let lengthMeters = 1.0;
let paused = false;
let simulationTime = 0;
function idealPeriod(length) {
return 2 * Math.PI * Math.sqrt(length / GRAVITY);
}
function rebuildPendulum() {
clearGroup(pendulumParts);
clearGroup(lengthGuide);
const segmentCount = 16;
const segmentHeight = lengthMeters / segmentCount;
for (let i = 0; i < segmentCount; i++) {
block(
pendulumParts,
0,
-lengthMeters + segmentHeight * (i + 0.5),
0,
0.052,
segmentHeight * 0.84,
0.052,
"#b8893e",
{ material: darkBrass }
);
}
// A stepped voxel bob.
const bob = new THREE.Group();
bob.position.y = -lengthMeters;
pendulumParts.add(bob);
block(bob, 0, 0, 0, 0.42, 0.28, 0.28, "#d5a348", {
material: brass
});
block(bob, 0, 0.14, 0, 0.3, 0.12, 0.24, "#e0b15b", {
material: brass
});
block(bob, 0, -0.14, 0, 0.3, 0.1, 0.24, "#b27c31", {
material: darkBrass
});
block(bob, -0.25, 0, 0, 0.12, 0.26, 0.22, "#b27c31", {
material: darkBrass
});
block(bob, 0.25, 0, 0, 0.12, 0.26, 0.22, "#b27c31", {
material: darkBrass
});
block(bob, 0, 0, 0.18, 0.13, 0.11, 0.08, "#7f5627", {
material: darkBrass
});
// Thin dotted vertical guide showing the measured pivot-to-bob distance.
for (let i = 0; i < 22; i++) {
const y = pivotY - (lengthMeters * (i + 0.5)) / 22;
block(
lengthGuide,
clockX - 0.04,
y,
0.37,
0.026,
0.026,
0.026,
"#bda979",
{ cast: false }
);
}
scaleCarriage.position.y = pivotY - lengthMeters;
}
function rebuildTimingMarkers() {
clearGroup(timingMarkers);
const period = idealPeriod(lengthMeters);
// Ideal full beats.
for (let beat = 0; beat * period <= 6.0001; beat++) {
const time = beat * period;
const x = timelineStart + (time / 6) * timelineWidth;
block(
timingMarkers,
x,
timelineY,
-3.13,
0.075,
0.45,
0.1,
"#e58d32",
{ material: getMaterial("#e58d32", 0.48, 0.08) }
);
}
// Ideal half beats.
for (let beat = 0; beat + 0.5 <= 6.0001; beat++) {
const time = (beat + 0.5) * period;
const x = timelineStart + (time / 6) * timelineWidth;
block(
timingMarkers,
x,
timelineY,
-3.14,
0.052,
0.25,
0.09,
"#4ba9a2",
{ material: getMaterial("#4ba9a2", 0.48, 0.08) }
);
}
}
function updateFormulaPanel() {
const period = idealPeriod(lengthMeters);
const { context: ctx, canvas, texture } = formulaTexture;
const w = canvas.width;
const h = canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#eee2c4";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#9a7445";
ctx.lineWidth = 10;
ctx.strokeRect(7, 7, w - 14, h - 14);
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#342a20";
ctx.font = "700 58px monospace";
ctx.fillText("T = 2π√(L/g)", 55, 73);
ctx.fillStyle = "#6f4927";
ctx.font = "700 47px monospace";
ctx.fillText(
`L = ${lengthMeters.toFixed(2)} m => T = ${period.toFixed(2)} s`,
55,
166
);
texture.needsUpdate = true;
}
function updateLengthLabel() {
const { context: ctx, canvas, texture } = lengthText;
const w = canvas.width;
const h = canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#e9ddbd";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#9b703d";
ctx.lineWidth = 9;
ctx.strokeRect(6, 6, w - 12, h - 12);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#342a20";
ctx.font = "700 58px monospace";
ctx.fillText(`${lengthMeters.toFixed(2)} m`, w / 2, h * 0.38);
ctx.fillStyle = "#75522e";
ctx.font = "700 21px monospace";
ctx.fillText("CURRENT LENGTH", w / 2, h * 0.73);
texture.needsUpdate = true;
}
function updateReadouts() {
const period = idealPeriod(lengthMeters);
const frequency = 1 / period;
const bpm = 60 * frequency;
const relativeRate = (REFERENCE_PERIOD / period) * 100;
const comparison = period > REFERENCE_PERIOD
? "slower"
: period < REFERENCE_PERIOD
? "faster"
: "at the reference rate";
$("lengthValue").textContent = `${lengthMeters.toFixed(2)} m`;
$("periodValue").textContent = `${period.toFixed(2)} s`;
$("frequencyValue").textContent = `${frequency.toFixed(3)} Hz`;
$("bpmValue").textContent = bpm.toFixed(1);
$("rateValue").textContent = `${relativeRate.toFixed(0)}%`;
$("comparison").textContent =
`This pendulum is ${comparison} than the 1.00 m reference. ` +
`Its beat interval is ${(period / REFERENCE_PERIOD).toFixed(2)}× the reference interval.`;
}
function applyLength() {
rebuildPendulum();
rebuildTimingMarkers();
updateFormulaPanel();
updateLengthLabel();
updateReadouts();
}
$("lengthSlider").addEventListener("input", (event) => {
lengthMeters = Number.parseFloat(event.target.value);
applyLength();
});
// -------------------------------------------------------------------------
// Direct camera controls: no addons or OrbitControls dependency
// -------------------------------------------------------------------------
const defaultCamera = {
target: new THREE.Vector3(-0.15, 2.4, -0.15),
radius: 13.6,
theta: 0.49,
phi: 1.22
};
const cameraState = {
target: defaultCamera.target.clone(),
radius: defaultCamera.radius,
theta: defaultCamera.theta,
phi: defaultCamera.phi
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
let dragMode = null;
let lastPointerX = 0;
let lastPointerY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (activePointerId !== null) return;
activePointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
dragMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (event.pointerId !== activePointerId || !dragMode) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (dragMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.72,
1.52
);
} else {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const scale = cameraState.radius * 0.0016;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId === activePointerId) {
activePointerId = null;
dragMode = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.0,
21.0
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
});
$("resetButton").addEventListener("click", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
});
$("pauseButton").addEventListener("click", () => {
paused = !paused;
$("pauseButton").textContent = paused
? "Resume motion"
: "Pause motion";
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
simulationTime += delta;
}
const period = idealPeriod(lengthMeters);
const phase = (simulationTime / period) * Math.PI * 2;
const amplitude = 0.19; // About 11 degrees, an illustrative small angle.
pendulum.rotation.z = amplitude * Math.cos(phase);
// The dial hands provide a quiet clock-time reference.
const totalMinutes = 10 + simulationTime / 60;
minuteHand.rotation.z = -(totalMinutes / 60) * Math.PI * 2;
hourHand.rotation.z = -((10 + totalMinutes / 60) / 12) * Math.PI * 2;
// Cursor traverses the fixed six-second timing window.
const cursorTime = simulationTime % 6;
cursor.position.set(
timelineStart + (cursorTime / 6) * timelineWidth,
timelineY,
-3.04
);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
applyLength();
updateCamera();
$("loading").style.display = "none";
requestAnimationFrame(animate);
</script>
</body>
</html>
```