Prompt specification
Build or customize the Three.js 3D scene "Instrument Maker's Tuning Bench" 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: Instrument Maker's Tuning Bench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/instrument-maker-s-tuning-bench-x3327
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows string length, pitch, and musical ratios. Create a workbench comparing strings and tubes with explicitly different idealized models. Keep labels and animations separate so their boundary conditions are not conflated. Voxel style.
Working Three.js Starter (instrument-maker-s-tuning-bench-x3327):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>String / Tube — Acoustic Ratio Workbench</title>
<style>
:root {
color-scheme: dark;
--bg: #0c1017;
--panel: #141a24;
--panel-2: #19212d;
--line: #344154;
--text: #edf3fa;
--muted: #9aa9bb;
--string: #ffb84d;
--string-soft: #ffdf9d;
--tube: #50ddd0;
--tube-soft: #b3fff7;
--closed: #ff8b68;
--shadow: 8px 8px 0 #05070a;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html {
background: var(--bg);
}
body {
margin: 0;
min-width: 320px;
color: var(--text);
background:
linear-gradient(90deg, #ffffff05 1px, transparent 1px) 0 0 / 24px 24px,
linear-gradient(#ffffff05 1px, transparent 1px) 0 0 / 24px 24px,
var(--bg);
font-family: var(--sans);
}
button,
input,
select {
font: inherit;
}
button,
select {
color: var(--text);
}
.shell {
width: min(1540px, calc(100% - 32px));
margin: 0 auto;
padding: 28px 0 48px;
}
.masthead {
display: grid;
grid-template-columns: 1fr auto;
gap: 24px;
align-items: end;
padding: 22px 24px 24px;
margin-bottom: 20px;
background: #111722;
border: 2px solid var(--line);
box-shadow: var(--shadow);
}
.eyebrow,
.micro-label,
.metric-label,
.boundary-badge,
.model-index,
.control-label,
.ratio-heading,
.assumption-title {
font-family: var(--mono);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.eyebrow {
color: var(--tube);
margin-bottom: 9px;
}
h1 {
margin: 0;
font-size: clamp(2rem, 5vw, 4.6rem);
line-height: 0.94;
letter-spacing: -0.055em;
text-transform: uppercase;
}
h1 span {
color: var(--muted);
font-weight: 400;
}
.masthead-copy {
max-width: 760px;
margin: 14px 0 0;
color: #b5c2d1;
line-height: 1.55;
}
.isolation-note {
max-width: 350px;
padding: 14px;
background: #0b1018;
border: 2px solid var(--line);
color: #aebdcb;
font: 0.78rem/1.55 var(--mono);
}
.isolation-note strong {
display: block;
margin-bottom: 5px;
color: var(--text);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.workbench {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
align-items: stretch;
}
.model-panel {
min-width: 0;
overflow: hidden;
background: var(--panel);
border: 2px solid var(--line);
box-shadow: var(--shadow);
}
.model-panel.string {
--accent: var(--string);
--accent-soft: var(--string-soft);
}
.model-panel.tube {
--accent: var(--tube);
--accent-soft: var(--tube-soft);
}
.panel-head {
padding: 20px;
background: var(--panel-2);
border-bottom: 2px solid var(--line);
}
.panel-title-row {
display: flex;
justify-content: space-between;
gap: 16px;
align-items: flex-start;
}
.model-index {
color: var(--accent);
margin-bottom: 7px;
}
h2 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2.4rem);
line-height: 1;
letter-spacing: -0.04em;
}
.boundary-badge {
display: inline-block;
flex: 0 0 auto;
padding: 8px 9px;
color: var(--accent-soft);
background: #090d13;
border: 1px solid var(--accent);
text-align: center;
}
.boundary-badge.closed {
color: #ffd1c3;
border-color: var(--closed);
}
.model-statement {
margin: 14px 0 12px;
color: #b7c4d2;
font-size: 0.94rem;
line-height: 1.55;
}
.formula {
display: block;
padding: 11px 12px;
overflow-x: auto;
color: var(--accent-soft);
background: #0a0f16;
border-left: 4px solid var(--accent);
font: 0.82rem/1.5 var(--mono);
white-space: nowrap;
}
.view {
position: relative;
height: clamp(350px, 44vh, 510px);
overflow: hidden;
background: #111722;
border-bottom: 2px solid var(--line);
isolation: isolate;
}
.three-canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
.three-canvas:active {
cursor: grabbing;
}
.three-canvas:focus-visible {
outline: 3px solid var(--accent);
outline-offset: -5px;
}
.view-hud {
position: absolute;
z-index: 2;
top: 12px;
left: 12px;
right: 12px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 10px;
pointer-events: none;
}
.hud-block {
padding: 9px 10px;
background: #090d13dc;
border: 1px solid #526176;
font: 0.69rem/1.45 var(--mono);
text-transform: uppercase;
letter-spacing: 0.07em;
}
.hud-block strong {
display: block;
color: var(--accent);
font-size: 0.75rem;
}
.view-buttons {
display: flex;
gap: 7px;
pointer-events: auto;
}
.block-button {
min-height: 34px;
padding: 7px 10px;
border: 1px solid #647286;
border-radius: 0;
background: #0b1018e8;
font: 0.68rem/1 var(--mono);
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
.block-button:hover,
.block-button:focus-visible {
color: #071018;
background: var(--accent);
border-color: var(--accent);
outline: none;
}
.view-legend {
position: absolute;
z-index: 2;
left: 12px;
right: 12px;
bottom: 12px;
padding: 10px 12px;
color: #c9d4df;
background: #090d13df;
border: 1px solid #526176;
font: 0.72rem/1.45 var(--mono);
pointer-events: none;
}
.view-legend strong {
color: var(--accent);
}
.controls {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px 18px;
padding: 20px;
border-bottom: 1px solid var(--line);
}
.control {
min-width: 0;
}
.control-label {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 10px;
margin-bottom: 8px;
color: #aebccc;
}
.control-label output {
color: var(--accent-soft);
font-size: 0.73rem;
letter-spacing: 0;
text-align: right;
text-transform: none;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
accent-color: var(--accent);
cursor: ew-resize;
}
select {
width: 100%;
min-height: 38px;
padding: 8px 10px;
background: #0b1018;
border: 1px solid #56647a;
border-radius: 0;
font-family: var(--mono);
font-size: 0.78rem;
cursor: pointer;
}
.metrics {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 1px;
background: var(--line);
border-bottom: 1px solid var(--line);
}
.metric {
min-width: 0;
padding: 14px 12px;
background: #101620;
}
.metric-label {
display: block;
margin-bottom: 7px;
color: #8291a4;
font-size: 0.62rem;
letter-spacing: 0.08em;
}
.metric-value {
display: block;
overflow-wrap: anywhere;
color: var(--accent-soft);
font: 800 0.91rem/1.25 var(--mono);
}
.ratio-section {
padding: 16px 20px 18px;
}
.ratio-heading {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
color: #9cabc0;
font-size: 0.65rem;
}
.ratio-heading span:last-child {
color: #718096;
font-weight: 500;
letter-spacing: 0.03em;
text-transform: none;
}
.ratio-grid {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 7px;
}
.ratio-btn {
min-width: 0;
padding: 9px 5px;
color: #b5c2d1;
background: #0b1018;
border: 1px solid #46546a;
border-radius: 0;
font: 800 0.77rem/1 var(--mono);
cursor: pointer;
}
.ratio-btn:hover,
.ratio-btn:focus-visible {
border-color: var(--accent);
outline: none;
}
.ratio-btn.active {
color: #081018;
background: var(--accent);
border-color: var(--accent);
box-shadow: 3px 3px 0 #000;
}
.assumptions {
padding: 16px 20px 20px;
background: #0d121a;
border-top: 1px solid var(--line);
}
.assumption-title {
margin-bottom: 8px;
color: var(--accent);
font-size: 0.62rem;
}
.assumptions ul {
margin: 0;
padding-left: 18px;
color: #8998aa;
font-size: 0.76rem;
line-height: 1.6;
}
.comparison {
margin-top: 20px;
padding: 18px 20px;
background: #111722;
border: 2px solid var(--line);
box-shadow: var(--shadow);
}
.comparison-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
margin-bottom: 14px;
}
.comparison-head h2 {
font-size: 1.15rem;
letter-spacing: -0.02em;
text-transform: uppercase;
}
.comparison-head p {
margin: 0;
color: #8695a8;
font: 0.69rem/1.4 var(--mono);
text-align: right;
}
.comparison-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1px;
background: var(--line);
}
.comparison-cell {
padding: 13px;
background: #0b1018;
}
.comparison-cell span {
display: block;
margin-bottom: 6px;
color: #7e8da1;
font: 700 0.64rem/1.3 var(--mono);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.comparison-cell strong {
color: var(--text);
font: 800 0.9rem/1.35 var(--mono);
}
.footer-note {
margin: 18px 2px 0;
color: #718095;
font: 0.72rem/1.6 var(--mono);
}
@media (max-width: 1120px) {
.metrics {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.masthead {
grid-template-columns: 1fr;
}
.isolation-note {
max-width: none;
}
}
@media (max-width: 850px) {
.workbench {
grid-template-columns: 1fr;
}
.view {
height: 410px;
}
}
@media (max-width: 560px) {
.shell {
width: min(100% - 18px, 1540px);
padding-top: 12px;
}
.masthead,
.panel-head,
.controls,
.ratio-section,
.assumptions,
.comparison {
padding-left: 14px;
padding-right: 14px;
}
.controls {
grid-template-columns: 1fr;
}
.metrics {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ratio-grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.comparison-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.comparison-head {
align-items: flex-start;
flex-direction: column;
}
.comparison-head p {
text-align: left;
}
.view-hud {
align-items: stretch;
flex-direction: column;
}
.view-buttons {
align-self: flex-end;
}
}
</style>
</head>
<body>
<main class="shell">
<header class="masthead">
<div>
<div class="eyebrow">Acoustic model workbench / 01</div>
<h1>String <span>/</span> Tube</h1>
<p class="masthead-copy">
A voxel laboratory for comparing string length, pitch, and exact
frequency ratios. The two panels use physically different boundary
conditions, parameter sets, cameras, and animation conventions.
</p>
</div>
<aside class="isolation-note">
<strong>Model isolation</strong>
No shared boundary conditions. No acoustic coupling. Each panel’s
ratios are relative only to its own fundamental.
</aside>
</header>
<section class="workbench" aria-label="Independent acoustic models">
<!-- STRING MODEL -->
<article class="model-panel string" aria-labelledby="string-title">
<header class="panel-head">
<div class="panel-title-row">
<div>
<div class="model-index">Model S / Transverse wave</div>
<h2 id="string-title">Ideal fixed string</h2>
</div>
<div class="boundary-badge">
Fixed / fixed
<br />
displacement nodes
</div>
</div>
<p class="model-statement" id="s-model-line">
A uniform, taut string clamped at x = 0 and x = L. The animation
shows transverse displacement only. Stiffness, damping, and coupling
are omitted.
</p>
<code class="formula" id="s-formula">
fₙ = n/(2L) · √(T/μ), n = 1, 2, 3…
</code>
</header>
<div class="view" id="s-view">
<div class="view-hud">
<div class="hud-block">
String animation
<strong>transverse / Y axis</strong>
</div>
<div class="view-buttons">
<button class="block-button" id="s-pause" type="button">
Pause motion
</button>
<button class="block-button" id="s-reset" type="button">
Reset camera
</button>
</div>
</div>
<div class="view-legend" id="s-anim-note">
<strong>Motion label:</strong>
amber voxels move transversely. Both clamps remain fixed.
Motion speed is slowed and normalized.
</div>
</div>
<div class="controls">
<label class="control">
<span class="control-label">
<span>String length L</span>
<output id="s-length-out" for="s-length">1.00 m</output>
</span>
<input id="s-length" type="range" min="0.40" max="3.00" step="0.01" value="1.00">
</label>
<label class="control">
<span class="control-label">
<span>Tension T</span>
<output id="s-tension-out" for="s-tension">80 N</output>
</span>
<input id="s-tension" type="range" min="10" max="300" step="1" value="80">
</label>
<label class="control">
<span class="control-label">
<span>Linear density μ</span>
<output id="s-density-out" for="s-density">0.006 kg/m</output>
</span>
<input id="s-density" type="range" min="0.001" max="0.020" step="0.001" value="0.006">
</label>
<label class="control">
<span class="control-label">
<span>Standing-wave mode n</span>
<output id="s-mode-out" for="s-mode">1 : 1</output>
</span>
<select id="s-mode">
<option value="1">1st mode · 1 : 1</option>
<option value="2">2nd mode · 2 : 1</option>
<option value="3">3rd mode · 3 : 1</option>
<option value="4">4th mode · 4 : 1</option>
<option value="5">5th mode · 5 : 1</option>
</select>
</label>
<label class="control">
<span class="control-label">
<span>Visual amplitude</span>
<output id="s-amplitude-out" for="s-amplitude">0.22</output>
</span>
<input id="s-amplitude" type="range" min="0.04" max="0.42" step="0.01" value="0.22">
</label>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">String length</span>
<strong class="metric-value" id="s-metric-length">1.00 m</strong>
</div>
<div class="metric">
<span class="metric-label">Fundamental f₁</span>
<strong class="metric-value" id="s-f0">57.7 Hz</strong>
</div>
<div class="metric">
<span class="metric-label">Active pitch</span>
<strong class="metric-value" id="s-active">57.7 Hz</strong>
</div>
<div class="metric">
<span class="metric-label">Mode ratio</span>
<strong class="metric-value" id="s-ratio">1 : 1</strong>
</div>
<div class="metric">
<span class="metric-label">Nearest equal-tempered note</span>
<strong class="metric-value" id="s-note">A1 · +0.0¢</strong>
</div>
</div>
<section class="ratio-section">
<div class="ratio-heading">
<span>Exact ratios to string fundamental</span>
<span>Select a ratio to set the mode</span>
</div>
<div class="ratio-grid" id="s-ladder"></div>
</section>
<footer class="assumptions">
<div class="assumption-title">String idealization</div>
<ul>
<li>Uniform linear density and constant tension.</li>
<li>Ideal fixed ends: y(0,t) = y(L,t) = 0.</li>
<li>Only transverse modes are represented.</li>
<li>Visual length is schematic; the numerical length is physical.</li>
</ul>
</footer>
</article>
<!-- TUBE MODEL -->
<article class="model-panel tube" aria-labelledby="tube-title">
<header class="panel-head">
<div class="panel-title-row">
<div>
<div class="model-index">Model T / Longitudinal wave</div>
<h2 id="tube-title">Ideal air tube</h2>
</div>
<div class="boundary-badge" id="t-boundary-badge">
Open / open
<br />
pressure nodes
</div>
</div>
<p class="model-statement" id="t-model-line">
A lossless, rigid-walled air column with an open end at each side.
The animation represents longitudinal air-particle displacement,
not transverse string motion.
</p>
<code class="formula" id="t-formula">
fₕ = h·c / [2(L + 2e)], h = 1, 2, 3…
</code>
</header>
<div class="view" id="t-view">
<div class="view-hud">
<div class="hud-block">
Tube animation
<strong>longitudinal / X axis</strong>
</div>
<div class="view-buttons">
<button class="block-button" id="t-pause" type="button">
Pause motion
</button>
<button class="block-button" id="t-reset" type="button">
Reset camera
</button>
</div>
</div>
<div class="view-legend" id="t-anim-note">
<strong>Motion label:</strong>
cyan air parcels move longitudinally. Open ends are pressure
nodes and displacement antinodes. Motion speed is slowed.
</div>
</div>
<div class="controls">
<label class="control">
<span class="control-label">
<span>Physical tube length L</span>
<output id="t-length-out" for="t-length">1.00 m</output>
</span>
<input id="t-length" type="range" min="0.40" max="3.00" step="0.01" value="1.00">
</label>
<label class="control">
<span class="control-label">
<span>Air temperature</span>
<output id="t-temp-out" for="t-temp">20 °C · 343.4 m/s</output>
</span>
<input id="t-temp" type="range" min="0" max="40" step="1" value="20">
</label>
<label class="control">
<span class="control-label">
<span>End correction e</span>
<output id="t-end-out" for="t-end">0.06 m</output>
</span>
<input id="t-end" type="range" min="0" max="0.20" step="0.01" value="0.06">
</label>
<label class="control">
<span class="control-label">
<span>Tube boundary condition</span>
<output id="t-boundary-out" for="t-boundary">open / open</output>
</span>
<select id="t-boundary">
<option value="open">Open / open</option>
<option value="closed">Closed / open</option>
</select>
</label>
<label class="control">
<span class="control-label">
<span>Supported harmonic h</span>
<output id="t-mode-out" for="t-mode">1 : 1</output>
</span>
<select id="t-mode"></select>
</label>
<label class="control">
<span class="control-label">
<span>Visual air amplitude</span>
<output id="t-amplitude-out" for="t-amplitude">0.08</output>
</span>
<input id="t-amplitude" type="range" min="0.02" max="0.18" step="0.01" value="0.08">
</label>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Tube length</span>
<strong class="metric-value" id="t-metric-length">1.00 m</strong>
</div>
<div class="metric">
<span class="metric-label">Fundamental f₁</span>
<strong class="metric-value" id="t-f0">153.4 Hz</strong>
</div>
<div class="metric">
<span class="metric-label">Active pitch</span>
<strong class="metric-value" id="t-active">153.4 Hz</strong>
</div>
<div class="metric">
<span class="metric-label">Harmonic ratio</span>
<strong class="metric-value" id="t-ratio">1 : 1</strong>
</div>
<div class="metric">
<span class="metric-label">Nearest equal-tempered note</span>
<strong class="metric-value" id="t-note">D3 · −2.8¢</strong>
</div>
</div>
<section class="ratio-section">
<div class="ratio-heading">
<span>Exact ratios to tube fundamental</span>
<span>Select a ratio to set the harmonic</span>
</div>
<div class="ratio-grid" id="t-ladder"></div>
</section>
<footer class="assumptions">
<div class="assumption-title">Tube idealization</div>
<ul>
<li>Lossless air, rigid walls, and one-dimensional plane waves.</li>
<li>Open ends have pressure nodes; a closed end has a pressure antinode.</li>
<li>Square voxel pipes stylize an idealized cylindrical tube.</li>
<li>Air-particle motion is schematic and is not wall or string motion.</li>
</ul>
</footer>
</article>
</section>
<section class="comparison" aria-labelledby="comparison-title">
<div class="comparison-head">
<h2 id="comparison-title">Derived fundamental comparison</h2>
<p>READ-ONLY COMPARISON · does not couple either model</p>
</div>
<div class="comparison-grid">
<div class="comparison-cell">
<span>String fundamental</span>
<strong id="cmp-string">57.7 Hz</strong>
</div>
<div class="comparison-cell">
<span>Tube fundamental</span>
<strong id="cmp-tube">153.4 Hz</strong>
</div>
<div class="comparison-cell">
<span>Tube : string frequency ratio</span>
<strong id="cmp-ratio">2.658 : 1</strong>
</div>
<div class="comparison-cell">
<span>Nearest common simple ratio</span>
<strong id="cmp-simple">—</strong>
</div>
</div>
</section>
<p class="footer-note">
Camera: drag to orbit, wheel or +/− to zoom, arrow keys to rotate,
Home to reset. All geometry is generated from boxes. The animations are
intentionally slowed and are not intended to represent the actual audio
frequencies in real time.
</p>
</main>
<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);
const NOTE_NAMES = [
"C", "C♯", "D", "D♯", "E", "F",
"F♯", "G", "G♯", "A", "A♯", "B"
];
function formatFrequency(value) {
if (!Number.isFinite(value)) return "—";
return value >= 1000
? `${value.toFixed(0)} Hz`
: `${value.toFixed(1)} Hz`;
}
function pitchDescription(frequency) {
if (!Number.isFinite(frequency) || frequency <= 0) return "—";
const exactMidi = 69 + 12 * Math.log2(frequency / 440);
const midi = Math.round(exactMidi);
const cents = (exactMidi - midi) * 100;
const name = NOTE_NAMES[((midi % 12) + 12) % 12];
const octave = Math.floor(midi / 12) - 1;
const sign = cents < 0 ? "−" : "+";
return `${name}${octave} · ${sign}${Math.abs(cents).toFixed(1)}¢`;
}
function visualLength(physicalLength) {
// A schematic mapping keeps both physical lengths visually legible.
return 1.8 + physicalLength * 1.35;
}
function makeView(hostId, backgroundColor) {
const host = $(hostId);
const scene = new THREE.Scene();
scene.background = new THREE.Color(backgroundColor);
scene.fog = new THREE.Fog(backgroundColor, 10, 21);
const camera = new THREE.PerspectiveCamera(
42,
1,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(backgroundColor, 1);
renderer.domElement.className = "three-canvas";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel visualization. Drag to orbit and scroll to zoom."
);
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xe9f3ff,
0x18202d,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(4, 7, 5);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6bdcff, 1.3);
rimLight.position.set(-5, 2, -4);
scene.add(rimLight);
const grid = new THREE.Group();
const tileGeometry = new THREE.BoxGeometry(0.46, 0.045, 0.46);
const tileMaterials = [
new THREE.MeshStandardMaterial({
color: 0x18212d,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x1e2937,
roughness: 0.95,
flatShading: true
})
];
for (let x = -6; x <= 6; x++) {
for (let z = -6; z <= 6; z++) {
const tile = new THREE.Mesh(
tileGeometry,
tileMaterials[(x + z + 20) % 2]
);
tile.position.set(x * 0.49, -1.18, z * 0.49);
grid.add(tile);
}
}
scene.add(grid);
function resize() {
const width = Math.max(1, host.clientWidth);
const height = Math.max(1, host.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
if ("ResizeObserver" in window) {
const observer = new ResizeObserver(resize);
observer.observe(host);
} else {
window.addEventListener("resize", resize);
}
resize();
return {
scene,
camera,
renderer,
canvas: renderer.domElement
};
}
/*
* Camera controls are implemented directly here.
* No examples, addons, OrbitControls, or legacy scripts are used.
*/
function attachOrbitControls(canvas, camera, resetButton) {
const target = new THREE.Vector3(0, -0.05, 0);
const orbit = {
theta: 0.62,
phi: 1.17,
radius: 7.5
};
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
function apply() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
function reset() {
orbit.theta = 0.62;
orbit.phi = 1.17;
orbit.radius = 7.5;
apply();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.theta -= dx * 0.008;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.006,
0.30,
2.45
);
apply();
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
4.2,
12
);
apply();
},
{ passive: false }
);
canvas.addEventListener("dblclick", reset);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta += 0.10;
break;
case "ArrowRight":
orbit.theta -= 0.10;
break;
case "ArrowUp":
orbit.phi = THREE.MathUtils.clamp(orbit.phi - 0.08, 0.30, 2.45);
break;
case "ArrowDown":
orbit.phi = THREE.MathUtils.clamp(orbit.phi + 0.08, 0.30, 2.45);
break;
case "+":
case "=":
orbit.radius = THREE.MathUtils.clamp(orbit.radius * 0.90, 4.2, 12);
break;
case "-":
case "_":
orbit.radius = THREE.MathUtils.clamp(orbit.radius * 1.10, 4.2, 12);
break;
case "Home":
reset();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
apply();
}
});
resetButton.addEventListener("click", reset);
apply();
return reset;
}
function createVoxelString(scene) {
const root = new THREE.Group();
scene.add(root);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const stringMaterial = new THREE.MeshStandardMaterial({
color: 0xffb84d,
emissive: 0x6b3500,
emissiveIntensity: 0.22,
roughness: 0.48,
metalness: 0.05,
flatShading: true
});
const alternateStringMaterial = new THREE.MeshStandardMaterial({
color: 0xffd78b,
emissive: 0x5c2f00,
emissiveIntensity: 0.18,
roughness: 0.55,
flatShading: true
});
const clampMaterial = new THREE.MeshStandardMaterial({
color: 0xe5edf5,
roughness: 0.72,
flatShading: true
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x59687b,
roughness: 0.85,
metalness: 0.08,
flatShading: true
});
const nodeCount = 54;
const nodes = [];
const xPositions = new Float32Array(nodeCount);
for (let i = 0; i < nodeCount; i++) {
const node = new THREE.Mesh(
unitBox,
i === 0 || i === nodeCount - 1
? clampMaterial
: (i % 3 === 0 ? alternateStringMaterial : stringMaterial)
);
root.add(node);
nodes.push(node);
}
function makeSupport() {
const support = new THREE.Group();
const base = new THREE.Mesh(unitBox, supportMaterial);
base.scale.set(0.86, 0.13, 0.72);
base.position.y = -0.92;
const post = new THREE.Mesh(unitBox, supportMaterial);
post.scale.set(0.17, 1.12, 0.17);
post.position.y = -0.40;
const jaw = new THREE.Mesh(unitBox, clampMaterial);
jaw.scale.set(0.30, 0.24, 0.34);
jaw.position.y = 0.08;
support.add(base, post, jaw);
root.add(support);
return support;
}
const leftSupport = makeSupport();
const rightSupport = makeSupport();
function setLength(physicalLength) {
const length = visualLength(physicalLength);
const spacing = length / (nodeCount - 1);
const cubeSize = Math.min(0.13, spacing * 0.74);
for (let i = 0; i < nodeCount; i++) {
const x = -length / 2 + i * spacing;
xPositions[i] = x;
nodes[i].position.x = x;
nodes[i].scale.set(cubeSize, cubeSize, cubeSize);
}
leftSupport.position.x = -length / 2;
rightSupport.position.x = length / 2;
}
function setTension(tension) {
stringMaterial.emissiveIntensity = 0.12 + (tension / 300) * 0.38;
alternateStringMaterial.emissiveIntensity = 0.10 + (tension / 300) * 0.30;
}
function update(phase, mode, amplitude) {
for (let i = 0; i < nodeCount; i++) {
const s = i / (nodeCount - 1);
const shape = Math.sin(mode * Math.PI * s);
const displacement = shape * amplitude * Math.cos(phase);
nodes[i].position.set(
xPositions[i],
i === 0 || i === nodeCount - 1 ? 0 : displacement,
0
);
}
}
return { root, setLength, setTension, update };
}
function createVoxelTube(scene) {
const root = new THREE.Group();
scene.add(root);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x7d99aa,
roughness: 0.68,
metalness: 0.18,
flatShading: true
});
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x51cfc7,
emissive: 0x0a3f43,
emissiveIntensity: 0.25,
transparent: true,
opacity: 0.10,
depthWrite: false,
roughness: 0.6,
flatShading: true
});
const openMaterial = new THREE.MeshStandardMaterial({
color: 0x67eadc,
emissive: 0x0e5555,
emissiveIntensity: 0.34,
roughness: 0.5,
flatShading: true
});
const closedMaterial = new THREE.MeshStandardMaterial({
color: 0xff8b68,
emissive: 0x5b1800,
emissiveIntensity: 0.30,
roughness: 0.64,
flatShading: true
});
const parcelMaterial = new THREE.MeshStandardMaterial({
color: 0x50ddd0,
emissive: 0x0b5a58,
emissiveIntensity: 0.48,
roughness: 0.42,
flatShading: true
});
const shell = new THREE.Mesh(unitBox, shellMaterial);
root.add(shell);
const rails = [];
const railOffsets = [
[0.39, 0.30],
[0.39, -0.30],
[-0.39, 0.30],
[-0.39, -0.30]
];
for (const [y, z] of railOffsets) {
const rail = new THREE.Mesh(unitBox, wallMaterial);
rail.position.set(0, y, z);
root.add(rail);
rails.push(rail);
}
function makeOpenRing() {
const ring = new THREE.Group();
const top = new THREE.Mesh(unitBox, openMaterial);
top.scale.set(0.17, 0.12, 0.78);
top.position.y = 0.43;
const bottom = new THREE.Mesh(unitBox, openMaterial);
bottom.scale.set(0.17, 0.12, 0.78);
bottom.position.y = -0.43;
const front = new THREE.Mesh(unitBox, openMaterial);
front.scale.set(0.17, 0.74, 0.12);
front.position.z = 0.32;
const back = new THREE.Mesh(unitBox, openMaterial);
back.scale.set(0.17, 0.74, 0.12);
back.position.z = -0.32;
ring.add(top, bottom, front, back);
root.add(ring);
return ring;
}
const leftRing = makeOpenRing();
const rightRing = makeOpenRing();
const closedCap = new THREE.Mesh(unitBox, closedMaterial);
closedCap.scale.set(0.18, 0.88, 0.76);
root.add(closedCap);
const parcelCount = 48;
const parcels = [];
const baseX = new Float32Array(parcelCount);
for (let i = 0; i < parcelCount; i++) {
const parcel = new THREE.Mesh(unitBox, parcelMaterial);
root.add(parcel);
parcels.push(parcel);
}
function setLength(physicalLength) {
const length = visualLength(physicalLength);
const spacing = length / (parcelCount - 1);
const cubeSize = Math.min(0.13, spacing * 0.72);
shell.scale.set(length, 0.78, 0.64);
shell.position.set(0, 0, 0);
for (const rail of rails) {
rail.scale.set(length, 0.075, 0.075);
}
for (let i = 0; i < parcelCount; i++) {
const x = -length / 2 + i * spacing;
baseX[i] = x;
parcels[i].position.x = x;
parcels[i].scale.set(cubeSize, cubeSize, cubeSize);
}
leftRing.position.x = -length / 2;
rightRing.position.x = length / 2;
closedCap.position.x = -length / 2;
}
function setBoundary(type) {
const isClosed = type === "closed";
leftRing.visible = !isClosed;
closedCap.visible = isClosed;
}
function update(phase, harmonic, amplitude, type) {
for (let i = 0; i < parcelCount; i++) {
const s = i / (parcelCount - 1);
let particleShape;
if (type === "closed") {
// Closed at s=0; open at s=1.
// Pressure: cos(hπs/2), particle displacement: sin(hπs/2).
particleShape = -Math.sin(harmonic * Math.PI * s / 2);
} else {
// Open at both ends.
// Pressure: sin(hπs), particle displacement: cos(hπs).
particleShape = Math.cos(harmonic * Math.PI * s);
}
const displacement = amplitude * particleShape * Math.cos(phase);
parcels[i].position.set(baseX[i] + displacement, 0, 0);
}
}
return { root, setLength, setBoundary, update };
}
const stringView = makeView("s-view", 0x111722);
const tubeView = makeView("t-view", 0x101923);
const stringModel = createVoxelString(stringView.scene);
const tubeModel = createVoxelTube(tubeView.scene);
attachOrbitControls(
stringView.canvas,
stringView.camera,
$("s-reset")
);
attachOrbitControls(
tubeView.canvas,
tubeView.camera,
$("t-reset")
);
const stringMotion = {
paused: false,
phase: 0.35
};
const tubeMotion = {
paused: false,
phase: 2.15
};
const stringState = {
length: 1,
tension: 80,
density: 0.006,
mode: 1,
amplitude: 0.22,
fundamental: 0
};
const tubeState = {
length: 1,
temperature: 20,
endCorrection: 0.06,
boundary: "open",
harmonic: 1,
amplitude: 0.08,
soundSpeed: 343.4,
effectiveLength: 1.12,
fundamental: 0
};
function rebuildRatioLadder(container, values, onSelect) {
container.replaceChildren();
for (const value of values) {
const button = document.createElement("button");
button.type = "button";
button.className = "ratio-btn";
button.dataset.value = String(value);
button.textContent = `${value} : 1`;
button.setAttribute("aria-label", `Select harmonic ratio ${value} to 1`);
button.addEventListener("click", () => onSelect(value));
container.appendChild(button);
}
}
function markRatioLadder(container, selectedValue) {
for (const button of container.querySelectorAll(".ratio-btn")) {
const active = Number(button.dataset.value) === selectedValue;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
}
function updateComparison() {
const ratio = tubeState.fundamental / stringState.fundamental;
const simpleRatios = [
{ ratio: 1 / 2, label: "1 : 2" },
{ ratio: 2 / 3, label: "2 : 3" },
{ ratio: 3 / 4, label: "3 : 4" },
{ ratio: 1, label: "1 : 1" },
{ ratio: 6 / 5, label: "6 : 5" },
{ ratio: 5 / 4, label: "5 : 4" },
{ ratio: 4 / 3, label: "4 : 3" },
{ ratio: 3 / 2, label: "3 : 2" },
{ ratio: 5 / 3, label: "5 : 3" },
{ ratio: 2, label: "2 : 1" },
{ ratio: 5 / 2, label: "5 : 2" },
{ ratio: 3, label: "3 : 1" },
{ ratio: 4, label: "4 : 1" },
{ ratio: 5, label: "5 : 1" }
];
let closest = simpleRatios[0];
let closestDistance = Infinity;
for (const candidate of simpleRatios) {
const distance = Math.abs(
Math.log2(ratio / candidate.ratio)
);
if (distance < closestDistance) {
closest = candidate;
closestDistance = distance;
}
}
const deviation = 1200 * Math.log2(ratio / closest.ratio);
const sign = deviation < 0 ? "−" : "+";
$("cmp-string").textContent = formatFrequency(stringState.fundamental);
$("cmp-tube").textContent = formatFrequency(tubeState.fundamental);
$("cmp-ratio").textContent = `${ratio.toFixed(3)} : 1`;
$("cmp-simple").textContent =
`${closest.label} · ${sign}${Math.abs(deviation).toFixed(1)}¢ off exact`;
}
function updateString() {
stringState.length = Number($("s-length").value);
stringState.tension = Number($("s-tension").value);
stringState.density = Number($("s-density").value);
stringState.mode = Number($("s-mode").value);
stringState.amplitude = Number($("s-amplitude").value);
const {
length,
tension,
density,
mode,
amplitude
} = stringState;
const fundamental =
Math.sqrt(tension / density) / (2 * length);
const active = fundamental * mode;
stringState.fundamental = fundamental;
stringModel.setLength(length);
stringModel.setTension(tension);
$("s-length-out").textContent = `${length.toFixed(2)} m`;
$("s-tension-out").textContent = `${tension.toFixed(0)} N`;
$("s-density-out").textContent = `${density.toFixed(3)} kg/m`;
$("s-mode-out").textContent = `${mode} : 1`;
$("s-amplitude-out").textContent = amplitude.toFixed(2);
$("s-metric-length").textContent = `${length.toFixed(2)} m`;
$("s-f0").textContent = formatFrequency(fundamental);
$("s-active").textContent = formatFrequency(active);
$("s-ratio").textContent = `${mode} : 1`;
$("s-note").textContent = pitchDescription(active);
$("s-formula").textContent =
`fₙ = n/(2L) · √(T/μ), n = ${mode} | ` +
`fₙ = ${formatFrequency(active)}`;
markRatioLadder($("s-ladder"), mode);
updateComparison();
}
function updateTube() {
tubeState.length = Number($("t-length").value);
tubeState.temperature = Number($("t-temp").value);
tubeState.endCorrection = Number($("t-end").value);
tubeState.boundary = $("t-boundary").value;
tubeState.harmonic = Number($("t-mode").value);
tubeState.amplitude = Number($("t-amplitude").value);
const {
length,
temperature,
endCorrection,
boundary,
harmonic,
amplitude
} = tubeState;
const soundSpeed = 331.3 + 0.606 * temperature;
const effectiveLength = boundary === "open"
? length + 2 * endCorrection
: length + endCorrection;
const fundamental = boundary === "open"
? soundSpeed / (2 * effectiveLength)
: soundSpeed / (4 * effectiveLength);
const active = fundamental * harmonic;
tubeState.soundSpeed = soundSpeed;
tubeState.effectiveLength = effectiveLength;
tubeState.fundamental = fundamental;
tubeModel.setLength(length);
tubeModel.setBoundary(boundary);
$("t-length-out").textContent =
`${length.toFixed(2)} m · Lₑ ${effectiveLength.toFixed(2)} m`;
$("t-temp-out").textContent =
`${temperature} °C · ${soundSpeed.toFixed(1)} m/s`;
$("t-end-out").textContent = `${endCorrection.toFixed(2)} m`;
$("t-boundary-out").textContent =
boundary === "open" ? "open / open" : "closed / open";
$("t-mode-out").textContent = `${harmonic} : 1`;
$("t-amplitude-out").textContent = amplitude.toFixed(2);
$("t-metric-length").textContent = `${length.toFixed(2)} m`;
$("t-f0").textContent = formatFrequency(fundamental);
$("t-active").textContent = formatFrequency(active);
$("t-ratio").textContent = `${harmonic} : 1`;
$("t-note").textContent = pitchDescription(active);
const badge = $("t-boundary-badge");
badge.classList.toggle("closed", boundary === "closed");
if (boundary === "open") {
badge.innerHTML = "Open / open<br>pressure nodes";
$("t-model-line").textContent =
"A lossless, rigid-walled air column with an open end at each side. " +
"The animation represents longitudinal air-particle displacement, " +
"not transverse string motion.";
$("t-formula").textContent =
`fₕ = h·c / [2(L + 2e)], h = ${harmonic} | ` +
`fₕ = ${formatFrequency(active)}`;
$("t-anim-note").innerHTML =
"<strong>Motion label:</strong> cyan air parcels move " +
"longitudinally. Both open ends are pressure nodes and " +
"displacement antinodes. Motion speed is slowed.";
} else {
badge.innerHTML = "Closed / open<br>pressure A / N";
$("t-model-line").textContent =
"A lossless, rigid-walled air column closed at the left and open " +
"at the right. The animation represents longitudinal air-particle " +
"displacement, not transverse string motion.";
$("t-formula").textContent =
`fₕ = h·c / [4(L + e)], h = ${harmonic} (odd) | ` +
`fₕ = ${formatFrequency(active)}`;
$("t-anim-note").innerHTML =
"<strong>Motion label:</strong> cyan air parcels move " +
"longitudinally. The closed wall is a pressure antinode and " +
"displacement node; the open end is a pressure node and " +
"displacement antinode. Motion speed is slowed.";
}
markRatioLadder($("t-ladder"), harmonic);
updateComparison();
}
function populateTubeModes() {
const values = tubeState.boundary === "open"
? [1, 2, 3, 4, 5]
: [1, 3, 5, 7];
const select = $("t-mode");
select.replaceChildren();
for (const value of values) {
const option = document.createElement("option");
option.value = String(value);
option.textContent = `${value}${ordinalSuffix(value)} harmonic · ${value} : 1`;
select.appendChild(option);
}
select.value = "1";
tubeState.harmonic = 1;
}
function ordinalSuffix(value) {
const mod100 = value % 100;
if (mod100 >= 11 && mod100 <= 13) return "th";
switch (value % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
function bindPauseButton(button, motion) {
button.addEventListener("click", () => {
motion.paused = !motion.paused;
button.textContent = motion.paused ? "Resume motion" : "Pause motion";
button.setAttribute("aria-pressed", String(motion.paused));
});
}
bindPauseButton($("s-pause"), stringMotion);
bindPauseButton($("t-pause"), tubeMotion);
rebuildRatioLadder($("s-ladder"), [1, 2, 3, 4, 5], (value) => {
$("s-mode").value = String(value);
updateString();
});
populateTubeModes();
rebuildRatioLadder(
$("t-ladder"),
[1, 2, 3, 4, 5],
(value) => {
$("t-mode").value = String(value);
updateTube();
}
);
$("t-boundary").addEventListener("change", () => {
tubeState.boundary = $("t-boundary").value;
populateTubeModes();
const values = tubeState.boundary === "open"
? [1, 2, 3, 4, 5]
: [1, 3, 5, 7];
rebuildRatioLadder($("t-ladder"), values, (value) => {
$("t-mode").value = String(value);
updateTube();
});
updateTube();
});
for (const id of ["s-length", "s-tension", "s-density", "s-mode", "s-amplitude"]) {
$(id).addEventListener("input", updateString);
}
for (const id of ["t-length", "t-temp", "t-end", "t-mode", "t-amplitude"]) {
$(id).addEventListener("input", updateTube);
}
updateString();
updateTube();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!stringMotion.paused) {
stringMotion.phase += delta * 2.15;
}
if (!tubeMotion.paused) {
tubeMotion.phase += delta * 1.72;
}
stringModel.update(
stringMotion.phase,
stringState.mode,
stringState.amplitude
);
tubeModel.update(
tubeMotion.phase,
tubeState.harmonic,
tubeState.amplitude,
tubeState.boundary
);
stringView.renderer.render(stringView.scene, stringView.camera);
tubeView.renderer.render(tubeView.scene, tubeView.camera);
}
animate();
</script>
</body>
</html>
```