Prompt specification
Build or customize the Three.js 3D scene "A-B-A Phrase Block Sculpture" 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: A-B-A Phrase Block Sculpture
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/a-b-a-phrase-block-sculpture-x3313
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts musical phrases and repeated forms. Arrange colored and shaped phrase blocks in an A-B-A sequence on a rail. Preserve repeated motifs geometrically while making the contrasting middle section recognizable. Stylized solid forms.
Working Three.js Starter (a-b-a-phrase-block-sculpture-x3313):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Musical Form — A–B–A</title>
<style>
:root {
--ink: #263238;
--muted: #687579;
--paper: #f2efe7;
--teal: #176f73;
--coral: #e35d43;
--gold: #eeb64a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
max-width: 340px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
font-weight: 780;
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 290px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 5;
left: 26px;
bottom: 24px;
display: flex;
align-items: center;
gap: 14px;
padding: 11px 15px;
border: 1px solid rgba(38, 50, 56, 0.12);
border-radius: 999px;
background: rgba(255, 253, 248, 0.78);
box-shadow: 0 10px 35px rgba(40, 50, 52, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.dot.a {
background: var(--teal);
}
.dot.b {
background: var(--coral);
}
.controls {
position: fixed;
z-index: 5;
right: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid rgba(38, 50, 56, 0.12);
border-radius: 10px;
background: rgba(255, 253, 248, 0.78);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
text-align: right;
pointer-events: none;
backdrop-filter: blur(12px);
}
#label-layer {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 9px;
padding: 7px 11px 7px 7px;
border: 1px solid rgba(38, 50, 56, 0.11);
border-radius: 999px;
background: rgba(255, 253, 248, 0.9);
box-shadow: 0 9px 26px rgba(38, 50, 56, 0.09);
opacity: 0;
white-space: nowrap;
will-change: transform;
backdrop-filter: blur(10px);
}
.scene-label .letter {
display: grid;
width: 31px;
height: 31px;
place-items: center;
border-radius: 50%;
color: white;
font-size: 14px;
font-weight: 850;
}
.scene-label.a .letter {
background: var(--teal);
}
.scene-label.b .letter {
background: var(--coral);
}
.scene-label .caption {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.title-card {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 230px;
font-size: 12px;
}
.legend {
left: 16px;
bottom: 16px;
gap: 10px;
padding: 9px 12px;
}
.legend-item {
font-size: 9px;
}
.controls {
right: 16px;
bottom: 16px;
}
.scene-label .caption {
display: none;
}
.scene-label {
padding-right: 7px;
}
}
</style>
</head>
<body>
<main id="app"></main>
<header class="title-card">
<div class="eyebrow">Musical architecture</div>
<h1>A—B—A</h1>
<p class="subtitle">
A repeated teal note-motif, a contrasting angular phrase, then the
original motif returns on the rail.
</p>
</header>
<div id="label-layer">
<div class="scene-label a">
<span class="letter">A</span>
<span class="caption">Repeated note motif</span>
</div>
<div class="scene-label b">
<span class="letter">B</span>
<span class="caption">Contrasting angular phrase</span>
</div>
<div class="scene-label a">
<span class="letter">A</span>
<span class="caption">Repeated note motif</span>
</div>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="dot a"></span>A motif</div>
<div class="legend-item"><span class="dot b"></span>B contrast</div>
<div class="legend-item"><span class="dot a"></span>A returns</div>
</div>
<div class="controls">
Drag to orbit · Scroll to zoom<br>
Double-click to reset
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const labelElements = [...document.querySelectorAll(".scene-label")];
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2efe7);
scene.fog = new THREE.Fog(0xf2efe7, 27, 55);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"An interactive three-dimensional A-B-A musical form on a railway"
);
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfffbf1,
0x8c9a96,
2.2
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.2);
sun.position.set(-8, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0002;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xbde9ec, 1.1);
rimLight.position.set(9, 8, -13);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Ground and railway
// ---------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e4d9,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 46),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x3d4849,
roughness: 0.42,
metalness: 0.48
});
const sleeperMaterial = new THREE.MeshStandardMaterial({
color: 0x746d60,
roughness: 0.88,
metalness: 0
});
const track = new THREE.Group();
scene.add(track);
const railGeometry = new THREE.BoxGeometry(31, 0.13, 0.14);
for (const z of [-0.69, 0.69]) {
const rail = new THREE.Mesh(railGeometry, railMaterial);
rail.position.set(0, 0.16, z);
rail.castShadow = true;
rail.receiveShadow = true;
track.add(rail);
}
const sleeperGeometry = new THREE.BoxGeometry(0.34, 0.11, 1.72);
for (let x = -15; x <= 15; x += 0.76) {
const sleeper = new THREE.Mesh(
sleeperGeometry,
sleeperMaterial
);
sleeper.position.set(x, 0.035, 0);
sleeper.castShadow = true;
sleeper.receiveShadow = true;
track.add(sleeper);
}
// Small gold section markers make the three formal regions explicit.
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xe9b64d,
roughness: 0.5,
metalness: 0.15
});
const markerGeometry = new THREE.CylinderGeometry(
0.11,
0.15,
0.75,
12
);
for (const x of [-12.8, -4.25, 4.25, 12.8]) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(x, 0.34, -1.05);
marker.castShadow = true;
scene.add(marker);
}
// ---------------------------------------------------------------------
// Solid phrase geometry
// ---------------------------------------------------------------------
function extrudedShape(shape, depth = 0.48) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.055,
bevelThickness: 0.055
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
// A stylized eighth-note silhouette.
const noteShape = new THREE.Shape();
noteShape.moveTo(-0.55, 1.35);
noteShape.lineTo(0.52, 1.35);
noteShape.lineTo(0.52, -0.25);
noteShape.lineTo(0.28, -0.60);
noteShape.lineTo(-0.30, -0.72);
noteShape.lineTo(-0.62, -0.48);
noteShape.lineTo(-0.62, -0.12);
noteShape.lineTo(0.05, -0.12);
noteShape.lineTo(0.05, 0.92);
noteShape.lineTo(-0.55, 0.92);
noteShape.closePath();
const noteGeometry = extrudedShape(noteShape, 0.5);
// A sharp lightning/chevron silhouette for the contrasting B phrase.
const angularShape = new THREE.Shape();
angularShape.moveTo(-0.57, -0.44);
angularShape.lineTo(0.19, -0.44);
angularShape.lineTo(0.57, 0);
angularShape.lineTo(0.19, 0.44);
angularShape.lineTo(0.57, 0.88);
angularShape.lineTo(-0.57, 0.88);
angularShape.lineTo(-0.19, 0.44);
angularShape.lineTo(-0.57, 0);
angularShape.closePath();
const angularGeometry = extrudedShape(angularShape, 0.58);
const noteMaterial = new THREE.MeshStandardMaterial({
color: 0x176f73,
roughness: 0.38,
metalness: 0.10
});
const coralMaterial = new THREE.MeshStandardMaterial({
color: 0xe35d43,
roughness: 0.43,
metalness: 0.06
});
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xee9640,
roughness: 0.45,
metalness: 0.04
});
const pulses = [];
function addBeatPulses(centerX, sectionIndex, color) {
const beatPositions = [-1.65, -0.55, 0.55, 1.65];
beatPositions.forEach((x, beatIndex) => {
const material = new THREE.MeshStandardMaterial({
color: 0xf3c35d,
emissive: color,
emissiveIntensity: 0.05,
roughness: 0.38,
metalness: 0.12
});
const puck = new THREE.Mesh(
new THREE.CylinderGeometry(0.135, 0.135, 0.09, 24),
material
);
puck.position.set(centerX + x, 0.28, 0.69);
puck.castShadow = true;
scene.add(puck);
pulses.push({
mesh: puck,
material,
sectionIndex,
beatIndex
});
});
}
// The exact same geometry, scale pattern, and color are used for both A
// phrases, making the return of the motif visually unambiguous.
function buildAPhrase(centerX, sectionIndex) {
const phrase = new THREE.Group();
phrase.position.set(centerX, 0.91, 0);
const pattern = [
{ x: -1.65, scale: 0.78 },
{ x: -0.55, scale: 1.08 },
{ x: 0.55, scale: 0.78 },
{ x: 1.65, scale: 1.08 }
];
for (const item of pattern) {
const note = new THREE.Mesh(noteGeometry, noteMaterial);
note.position.x = item.x;
note.scale.set(item.scale, item.scale, item.scale);
note.castShadow = true;
note.receiveShadow = true;
phrase.add(note);
}
scene.add(phrase);
addBeatPulses(centerX, sectionIndex, 0x176f73);
}
function buildBPhrase(centerX, sectionIndex) {
const phrase = new THREE.Group();
phrase.position.set(centerX, 0.77, 0);
const pattern = [
{ x: -1.65, scale: 0.75, material: coralMaterial },
{ x: -0.55, scale: 1.18, material: orangeMaterial },
{ x: 0.55, scale: 0.95, material: coralMaterial },
{ x: 1.65, scale: 0.72, material: orangeMaterial }
];
for (const item of pattern) {
const block = new THREE.Mesh(angularGeometry, item.material);
block.position.x = item.x;
block.scale.set(item.scale, item.scale, item.scale);
block.castShadow = true;
block.receiveShadow = true;
phrase.add(block);
}
scene.add(phrase);
addBeatPulses(centerX, sectionIndex, 0xe35d43);
}
buildAPhrase(-8.45, 0);
buildBPhrase(0, 1);
buildAPhrase(8.45, 2);
// ---------------------------------------------------------------------
// Labels projected from 3D anchors
// ---------------------------------------------------------------------
const labels = [
{
element: labelElements[0],
anchor: new THREE.Vector3(-8.45, 3.25, 0)
},
{
element: labelElements[1],
anchor: new THREE.Vector3(0, 3.05, 0)
},
{
element: labelElements[2],
anchor: new THREE.Vector3(8.45, 3.25, 0)
}
];
// ---------------------------------------------------------------------
// Custom camera controls, implemented without camera-control addons
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
let dragging = false;
let previousX = 0;
let previousY = 0;
function defaultCameraDistance() {
return window.innerWidth / window.innerHeight < 0.85 ? 39 : 24;
}
function resetCamera() {
spherical.radius = defaultCameraDistance();
spherical.phi = 1.02;
spherical.theta = 0.48;
}
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.42,
1.43
);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
13,
48
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.005;
spherical.phi -= dy * 0.0045;
previousX = event.clientX;
previousY = event.clientY;
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
renderer.domElement.hasPointerCapture &&
event.pointerId !== undefined
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetCamera();
updateCamera();
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = camera.aspect < 0.85 ? 46 : 40;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// The gold beat markers travel through A, B, and then A again.
const phraseDuration = 2.25;
const totalDuration = phraseDuration * 3;
const sequenceTime = elapsed % totalDuration;
const activeSection = Math.floor(sequenceTime / phraseDuration);
const localTime = sequenceTime % phraseDuration;
const activeBeat = Math.min(
3,
Math.floor((localTime / phraseDuration) * 4)
);
const beatFraction =
((localTime / phraseDuration) * 4) % 1;
for (const pulse of pulses) {
const isActive =
pulse.sectionIndex === activeSection &&
pulse.beatIndex === activeBeat;
const strength = isActive
? Math.pow(1 - beatFraction, 2)
: 0;
pulse.material.emissiveIntensity =
0.04 + strength * 2.6;
const scale = 1 + strength * 0.42;
pulse.mesh.scale.set(scale, 1, scale);
}
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```