Prompt specification
Build or customize the Three.js 3D scene "Equal-Tension String Length Board" 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: Equal-Tension String Length Board
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-tension-string-length-board-x3325
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing equal-tension strings of different lengths. Show three strings with equal material and tension but different vibrating lengths. Mark endpoints and relative lengths so the comparison conditions are visible. Low-poly.
Working Three.js Starter (equal-tension-string-length-board-x3325):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Equal-Tension Strings</title>
<style>
:root {
color-scheme: dark;
--cyan: #57e3ca;
--yellow: #ffd166;
--orange: #ff9f43;
--panel: rgba(7, 17, 29, 0.88);
--border: rgba(87, 227, 202, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #eafffb;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: min(330px, calc(100vw - 36px));
padding: 17px 18px 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0 0 13px;
font-size: 22px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-bottom: 13px;
}
.chip {
padding: 5px 8px;
border: 1px solid rgba(87, 227, 202, 0.28);
border-radius: 6px;
color: #bff9ee;
background: rgba(87, 227, 202, 0.07);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.04em;
}
.chip.warm {
border-color: rgba(255, 159, 67, 0.35);
color: #ffd1a3;
background: rgba(255, 159, 67, 0.08);
}
dl {
display: grid;
grid-template-columns: auto 1fr;
gap: 7px 15px;
margin: 0;
font-size: 12px;
}
dt {
color: #8fa8b7;
}
dd {
margin: 0;
color: #f1fffc;
text-align: right;
font-weight: 650;
}
.rule {
height: 1px;
margin: 13px 0 11px;
background: linear-gradient(
90deg,
rgba(87, 227, 202, 0.42),
rgba(87, 227, 202, 0.04)
);
}
.formula {
color: #c5f8ef;
font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.note {
margin-top: 7px;
color: #829aa8;
font-size: 10px;
line-height: 1.45;
}
.legend {
position: fixed;
left: 18px;
bottom: 18px;
z-index: 10;
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
max-width: min(610px, calc(100vw - 36px));
padding: 10px 13px;
border: 1px solid rgba(126, 166, 184, 0.18);
border-radius: 10px;
background: rgba(7, 17, 29, 0.78);
color: #c1d1d9;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(10px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.endpoint-icon {
width: 9px;
height: 9px;
transform: rotate(45deg);
border: 1px solid #ffe3a0;
background: var(--yellow);
box-shadow: 0 0 9px rgba(255, 209, 102, 0.35);
}
.tension-icon {
position: relative;
width: 20px;
height: 2px;
background: var(--orange);
}
.tension-icon::after {
content: "";
position: absolute;
right: -1px;
top: -3px;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 6px solid var(--orange);
}
.length-icon {
width: 20px;
height: 2px;
background: #c8fff3;
}
.toolbar {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 20;
display: flex;
align-items: center;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(87, 227, 202, 0.3);
border-radius: 8px;
padding: 9px 12px;
color: #dffff9;
background: rgba(10, 28, 43, 0.94);
font: 700 11px/1 system-ui, sans-serif;
cursor: pointer;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}
button:hover {
border-color: rgba(87, 227, 202, 0.72);
background: rgba(17, 45, 62, 0.98);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.hint {
position: fixed;
right: 18px;
top: 18px;
z-index: 10;
padding: 8px 10px;
border: 1px solid rgba(126, 166, 184, 0.16);
border-radius: 8px;
color: #90a8b5;
background: rgba(7, 17, 29, 0.64);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: min(300px, calc(100vw - 20px));
padding: 13px 14px;
}
h1 {
font-size: 18px;
}
.hint {
display: none;
}
.legend {
left: 10px;
bottom: 62px;
max-width: calc(100vw - 20px);
gap: 7px 12px;
padding: 8px 10px;
}
.toolbar {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<section class="panel" aria-label="Comparison conditions">
<div class="eyebrow">Equal-condition comparison</div>
<h1>Strings under the same tension</h1>
<div class="chips">
<span class="chip">SAME STEEL STRAND</span>
<span class="chip warm">T = 40 N</span>
</div>
<dl>
<dt>Material</dt>
<dd>Steel</dd>
<dt>Linear density, μ</dt>
<dd>0.006 kg/m</dd>
<dt>Strand diameter</dt>
<dd>Identical</dd>
<dt>Supports</dt>
<dd>Fixed at both ends</dd>
</dl>
<div class="rule"></div>
<div class="formula">
f₁ = (1 / 2L) √(T / μ)
</div>
<div class="note">
Lengths: 4.0, 6.0, and 8.0 m. Relative fundamental frequencies:
<strong>1 : ⅔ : ½</strong>. Animation is slowed for clarity;
endpoint spacing is drawn to scale.
</div>
</section>
<div class="hint">Drag to orbit · Wheel to zoom · Arrow keys to rotate</div>
<div class="legend" aria-label="Scene legend">
<span class="legend-item">
<i class="endpoint-icon"></i>
fixed endpoint
</span>
<span class="legend-item">
<i class="tension-icon"></i>
equal tension: 40 N
</span>
<span class="legend-item">
<i class="length-icon"></i>
vibrating length
</span>
</div>
<div class="toolbar">
<button id="motionButton" type="button">Pause motion</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 19, 36);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 80);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of three equal-tension strings"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0xa9dbe4, 0x101923, 1.35));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.4);
keyLight.position.set(4, 8, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x43d9c2, 28, 18, 2);
rimLight.position.set(-5, 2, 5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffaa55, 18, 14, 2);
warmLight.position.set(5, -1, 4);
scene.add(warmLight);
// Low-poly floor and grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(22, 12, 1, 1),
new THREE.MeshStandardMaterial({
color: 0x0b1925,
roughness: 0.95,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.78;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(14, 28, 0x245060, 0x17333f);
grid.position.y = -2.765;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// Shared low-poly materials
const stringMaterial = new THREE.MeshStandardMaterial({
color: 0x57e3ca,
emissive: 0x0b5048,
emissiveIntensity: 0.55,
roughness: 0.34,
metalness: 0.25,
flatShading: true
});
const endpointMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6e4300,
emissiveIntensity: 0.45,
roughness: 0.42,
metalness: 0.12,
flatShading: true
});
const dimensionMaterial = new THREE.MeshStandardMaterial({
color: 0xc8fff3,
emissive: 0x194b45,
emissiveIntensity: 0.25,
roughness: 0.7,
metalness: 0.05
});
// Canvas-based labels use only core Three.js features.
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.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextSprite(
text,
{
scale = [2.4, 0.48],
foreground = "#eafffb",
background = "rgba(7, 17, 29, 0.84)",
border = "rgba(87, 227, 202, 0.35)",
fontSize = 42
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (background !== "transparent") {
roundedRect(ctx, 5, 5, canvas.width - 10, canvas.height - 10, 26);
ctx.fillStyle = background;
ctx.fill();
if (border !== "transparent") {
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.stroke();
}
}
let size = fontSize;
ctx.font = `700 ${size}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`;
while (
ctx.measureText(text).width > canvas.width - 60 &&
size > 20
) {
size -= 2;
ctx.font = `700 ${size}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`;
}
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
function addCylinderBetweenX(
startX,
endX,
y,
z = 0,
radius = 0.018,
material = dimensionMaterial
) {
const length = Math.abs(endX - startX);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6, 1, false),
material
);
mesh.rotation.z = Math.PI / 2;
mesh.position.set((startX + endX) / 2, y, z);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function addDimensionLine(length, y, labelText) {
const left = -length / 2;
const right = length / 2;
const lineY = y - 0.39;
addCylinderBetweenX(left, right, lineY);
// End ticks
for (const x of [left, right]) {
const tick = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.18, 6),
dimensionMaterial
);
tick.position.set(x, lineY, 0);
scene.add(tick);
}
// Low-poly inward arrowheads
const leftHead = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.17, 4),
dimensionMaterial
);
leftHead.rotation.z = -Math.PI / 2;
leftHead.position.set(left + 0.12, lineY, 0);
scene.add(leftHead);
const rightHead = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.17, 4),
dimensionMaterial
);
rightHead.rotation.z = Math.PI / 2;
rightHead.position.set(right - 0.12, lineY, 0);
scene.add(rightHead);
const label = makeTextSprite(labelText, {
scale: [2.55, 0.48],
foreground: "#d8fff7"
});
label.position.set(0, y - 0.77, 0.04);
scene.add(label);
}
const endpointGeometry = new THREE.OctahedronGeometry(0.13, 0);
const endpointRingGeometry = new THREE.TorusGeometry(
0.19,
0.022,
4,
8
);
function addFixedEndpoint(x, y) {
const diamond = new THREE.Mesh(
endpointGeometry,
endpointMaterial
);
diamond.position.set(x, y, 0);
diamond.castShadow = true;
scene.add(diamond);
const ring = new THREE.Mesh(
endpointRingGeometry,
endpointMaterial
);
ring.position.set(x, y, 0);
ring.rotation.y = Math.PI / 2;
scene.add(ring);
}
function addTensionArrow(x, y, direction) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(direction, 0, 0),
new THREE.Vector3(x, y, 0),
0.66,
0xff9f43,
0.18,
0.11
);
scene.add(arrow);
}
// A dynamic low-poly tube. The centerline is the first standing-wave
// mode, so the endpoints remain fixed while the interior oscillates.
function createVibratingString(length, baseY) {
const segments = 48;
const radialSegments = 5;
const radius = 0.036;
const vertexCount = (segments + 1) * (radialSegments + 1);
const positions = new Float32Array(vertexCount * 3);
const indices = [];
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = (i + 1) * (radialSegments + 1) + j + 1;
const d = i * (radialSegments + 1) + j + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
const mesh = new THREE.Mesh(geometry, stringMaterial);
mesh.castShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
return {
length,
baseY,
segments,
radialSegments,
radius,
geometry,
mesh
};
}
function updateStringGeometry(string, phase) {
const {
length,
baseY,
segments,
radialSegments,
radius,
geometry
} = string;
const amplitude = 0.20;
const positions = geometry.attributes.position.array;
for (let i = 0; i <= segments; i++) {
const u = i / segments;
const x = -length / 2 + length * u;
const standingWave = Math.sin(Math.PI * u);
const offsetY =
amplitude * standingWave * Math.sin(phase);
const centerY = baseY + offsetY;
// dy/dx for the current centerline.
const slope =
(amplitude * Math.PI * Math.cos(Math.PI * u) *
Math.sin(phase)) / length;
// Tangent and two perpendicular cross-section directions.
const tangent = new THREE.Vector3(1, slope, 0).normalize();
const normalA = new THREE.Vector3(0, 0, 1);
const normalB = new THREE.Vector3()
.crossVectors(tangent, normalA)
.normalize();
for (let j = 0; j <= radialSegments; j++) {
const theta = (j / radialSegments) * Math.PI * 2;
const ringOffset = normalA
.clone()
.multiplyScalar(Math.cos(theta) * radius)
.add(
normalB.clone().multiplyScalar(
Math.sin(theta) * radius
)
);
const index = (i * (radialSegments + 1) + j) * 3;
positions[index] = x + ringOffset.x;
positions[index + 1] = centerY + ringOffset.y;
positions[index + 2] = ringOffset.z;
}
}
geometry.attributes.position.needsUpdate = true;
geometry.computeVertexNormals();
}
const strings = [];
const rows = [
{
name: "STRING A",
length: 4,
y: 1.8,
ratio: "1.0×",
frequency: "10.2 Hz"
},
{
name: "STRING B",
length: 6,
y: 0,
ratio: "1.5×",
frequency: "6.8 Hz"
},
{
name: "STRING C",
length: 8,
y: -1.8,
ratio: "2.0×",
frequency: "5.1 Hz"
}
];
for (const row of rows) {
const string = createVibratingString(row.length, row.y);
strings.push(string);
addFixedEndpoint(-row.length / 2, row.y);
addFixedEndpoint(row.length / 2, row.y);
addTensionArrow(-row.length / 2, row.y, -1);
addTensionArrow(row.length / 2, row.y, 1);
addDimensionLine(
row.length,
row.y,
`L = ${row.length.toFixed(1)} m • ${row.ratio}`
);
const rowLabel = makeTextSprite(row.name, {
scale: [1.35, 0.32],
foreground: "#a9fff0",
background: "transparent",
border: "transparent",
fontSize: 44
});
rowLabel.position.set(
-row.length / 2 + 0.85,
row.y + 0.38,
0.05
);
scene.add(rowLabel);
}
// Custom camera controls: no addons are used.
const controls = {
target: new THREE.Vector3(0, -0.05, 0),
yaw: 0.075,
pitch: 0.075,
distance: 18,
zoom: 1,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontalDistance =
controls.distance * Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
Math.sin(controls.yaw) * horizontalDistance,
controls.target.y +
Math.sin(controls.pitch) * controls.distance,
controls.target.z +
Math.cos(controls.yaw) * horizontalDistance
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
function resetView() {
controls.yaw = 0.075;
controls.pitch = 0.075;
controls.zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.yaw -= dx * 0.005;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.004,
-0.55,
0.65
);
updateCamera();
});
function endPointerDrag(event) {
controls.dragging = false;
if (
event.pointerType !== "mouse" &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.8
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.yaw += 0.08;
break;
case "ArrowRight":
controls.yaw -= 0.08;
break;
case "ArrowUp":
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + 0.06,
-0.55,
0.65
);
break;
case "ArrowDown":
controls.pitch = THREE.MathUtils.clamp(
controls.pitch - 0.06,
-0.55,
0.65
);
break;
case "+":
case "=":
controls.zoom = Math.min(1.8, controls.zoom * 1.08);
break;
case "-":
controls.zoom = Math.max(0.65, controls.zoom / 1.08);
break;
case "0":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
let running = true;
const motionButton = document.getElementById("motionButton");
motionButton.addEventListener("click", () => {
running = !running;
motionButton.textContent = running
? "Pause motion"
: "Resume motion";
});
document
.getElementById("resetButton")
.addEventListener("click", resetView);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
// Preserve a minimum world-space width so the 8 m string and
// its tension arrows always fit.
const halfHeight = Math.max(3.35, 5.9 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const clock = new THREE.Clock();
let simulationTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
simulationTime += delta;
}
strings.forEach((string, index) => {
// Visual frequency follows 1/L. The shared factor slows the
// animation while preserving the physical comparison.
const visualFrequency = 0.28 * (4 / string.length);
const phase = simulationTime * visualFrequency * Math.PI * 2;
updateStringGeometry(string, phase);
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```