Prompt specification
Build or customize the Three.js 3D scene "Small Ensemble Call and Response" 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: Small Ensemble Call and Response
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-ensemble-call-and-response-x3315
Scene Description Prompt:
In standalone HTML using Three.js from cdnjs, animate two voxel ensembles exchanging visual rhythmic calls and responses across distinct phrase boundaries.
Working Three.js Starter (small-ensemble-call-and-response-x3315):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#050812">
<title>Voxel Call & Response</title>
<style>
:root {
--a: #35d8ff;
--b: #ff4edb;
--ink: #d9f7ff;
--muted: #718ba4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #050812;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 25%, rgba(0, 0, 0, .22) 67%),
linear-gradient(180deg, rgba(4, 8, 18, .15), rgba(2, 4, 10, .55));
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 32px;
letter-spacing: .2em;
text-transform: uppercase;
}
.brand h1 {
margin: 0 0 7px;
font-size: clamp(18px, 2vw, 27px);
font-weight: 650;
letter-spacing: .16em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 10px;
letter-spacing: .25em;
}
.readout {
position: absolute;
top: 27px;
right: 32px;
min-width: 220px;
text-align: right;
}
.readout .phrase {
color: #f4fbff;
font-size: 12px;
font-weight: 700;
letter-spacing: .25em;
}
.readout .phase {
margin-top: 9px;
color: #8eabc1;
font-size: 10px;
letter-spacing: .2em;
}
.readout .roles {
margin-top: 8px;
font-size: 9px;
letter-spacing: .16em;
color: #536d82;
}
#reset {
pointer-events: auto;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(144, 204, 231, .24);
border-radius: 3px;
background: rgba(9, 19, 32, .54);
color: #91b9cd;
font: inherit;
font-size: 9px;
letter-spacing: .16em;
cursor: pointer;
}
#reset:hover {
border-color: rgba(144, 224, 255, .65);
color: white;
}
.ensemble-label {
position: absolute;
z-index: 12;
transform: translate(-50%, -100%);
padding: 8px 12px;
border: 1px solid rgba(130, 191, 219, .18);
border-radius: 4px;
background: rgba(4, 10, 20, .64);
backdrop-filter: blur(8px);
text-align: center;
white-space: nowrap;
transition: opacity .15s;
}
.ensemble-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: linear-gradient(currentColor, transparent);
opacity: .55;
}
.ensemble-label strong {
display: block;
font-size: 11px;
letter-spacing: .22em;
}
.ensemble-label small {
display: block;
margin-top: 4px;
color: #738b9d;
font-size: 8px;
letter-spacing: .18em;
}
#label-a {
color: var(--a);
}
#label-b {
color: var(--b);
}
.bottom {
position: absolute;
left: 50%;
bottom: 25px;
width: min(720px, calc(100vw - 40px));
transform: translateX(-50%);
}
.timeline-labels {
display: grid;
grid-template-columns: 1fr 1fr;
margin-bottom: 10px;
font-size: 9px;
letter-spacing: .19em;
color: #6f889b;
}
.timeline-labels span:last-child {
text-align: right;
}
#timeline {
display: grid;
grid-template-columns: repeat(16, 1fr);
gap: 4px;
height: 27px;
padding: 5px 7px;
border: 1px solid rgba(119, 175, 201, .2);
border-radius: 4px;
background: rgba(5, 13, 24, .72);
backdrop-filter: blur(12px);
box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.tick {
position: relative;
border-radius: 2px;
background: color-mix(in srgb, var(--tick-color) 18%, transparent);
opacity: .35;
transition: opacity .08s, background .08s, transform .08s;
}
.tick:nth-child(8) {
margin-right: 7px;
}
.tick.passed {
opacity: .62;
}
.tick.active {
opacity: 1;
background: var(--tick-color);
transform: scaleY(1.35);
box-shadow: 0 0 13px var(--tick-color);
}
.timeline-foot {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #52697a;
font-size: 8px;
letter-spacing: .17em;
}
.hint {
position: absolute;
left: 32px;
bottom: 30px;
color: #526b7e;
font-size: 9px;
line-height: 1.8;
letter-spacing: .12em;
}
#boundary-flash {
position: fixed;
inset: 0;
z-index: 8;
pointer-events: none;
opacity: 0;
border: 1px solid rgba(175, 226, 255, .65);
box-shadow:
inset 0 0 70px rgba(100, 193, 255, .1),
0 0 28px rgba(100, 193, 255, .12);
}
@media (max-width: 700px) {
.brand {
top: 19px;
left: 18px;
}
.brand p {
display: none;
}
.readout {
top: 18px;
right: 18px;
min-width: 155px;
}
.readout .roles,
#reset {
display: none;
}
.hint {
display: none;
}
.bottom {
bottom: 17px;
}
.ensemble-label {
padding: 6px 8px;
}
}
</style>
</head>
<body>
<div id="boundary-flash"></div>
<div id="hud">
<header class="brand">
<h1>Voxel Call / Response</h1>
<p>Two ensembles · alternating phrase cycles</p>
</header>
<section class="readout">
<div class="phrase" id="phrase-number">PHRASE 01</div>
<div class="phase" id="phase-name">A CALL</div>
<div class="roles" id="role-name">LEAD A · ANSWER B</div>
<button id="reset" type="button">RESET VIEW</button>
</section>
<div class="ensemble-label" id="label-a">
<strong>ENSEMBLE A</strong>
<small id="label-a-role">LEAD</small>
</div>
<div class="ensemble-label" id="label-b">
<strong>ENSEMBLE B</strong>
<small id="label-b-role">ANSWER</small>
</div>
<div class="hint">
DRAG TO ORBIT<br />
SCROLL TO ZOOM
</div>
<div class="bottom">
<div class="timeline-labels">
<span id="call-label">A / CALL</span>
<span id="response-label">B / RESPONSE</span>
</div>
<div id="timeline"></div>
<div class="timeline-foot">
<span>16 BEATS / PHRASE</span>
<span>CALL + RESPONSE · PHRASE BOUNDARY</span>
</div>
</div>
</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(0x050812);
scene.fog = new THREE.FogExp2(0x050812, 0.045);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
document.body.prepend(renderer.domElement);
// ------------------------------------------------------------------
// Custom camera controls. No examples or addons are used.
// ------------------------------------------------------------------
const controls = {
radius: 14.2,
theta: 0,
phi: 1.13,
target: new THREE.Vector3(0, 0.9, 0)
};
const desired = {
radius: controls.radius,
theta: controls.theta,
phi: controls.phi,
target: controls.target.clone()
};
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desired.theta -= dx * 0.005;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.004,
0.58,
1.46
);
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.009,
9,
21
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
desired.radius = 14.2;
desired.theta = 0;
desired.phi = 1.13;
desired.target.set(0, 0.9, 0);
});
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 10);
controls.radius = THREE.MathUtils.lerp(
controls.radius,
desired.radius,
damping
);
controls.theta = THREE.MathUtils.lerp(
controls.theta,
desired.theta,
damping
);
controls.phi = THREE.MathUtils.lerp(
controls.phi,
desired.phi,
damping
);
controls.target.lerp(desired.target, damping);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
// ------------------------------------------------------------------
// Lighting and environment
// ------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9cdfff, 0x12091f, 1.25));
const keyLight = new THREE.DirectionalLight(0xd8f4ff, 2.1);
keyLight.position.set(4, 8, 7);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x9b58ff, 1.4);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x07101c,
roughness: 0.86,
metalness: 0.22
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.12;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
38,
38,
0x17435a,
0x0a1b2c
);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.46;
scene.add(grid);
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(300 * 3);
for (let i = 0; i < 300; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 32;
dustPositions[i * 3 + 1] = Math.random() * 11;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 20;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x6099b5,
size: 0.025,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------------
// Voxel ensembles
// ------------------------------------------------------------------
const A_COLOR = new THREE.Color(0x35d8ff);
const B_COLOR = new THREE.Color(0xff4edb);
const WHITE = new THREE.Color(0xffffff);
const VOXEL_GEOMETRY = new THREE.BoxGeometry(0.43, 0.43, 0.43);
function createEnsemble(name, color, x, mirror) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const positions = [];
// Each ensemble is a 5 × 3 × 3 voxel lattice with a stepped crown.
for (let layer = 0; layer < 3; layer++) {
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 5; column++) {
const topCorner =
layer === 2 &&
((column === 0 && row === 0) ||
(column === 4 && row === 2));
if (topCorner) continue;
const skew = mirror ? -1 : 1;
positions.push({
x: (column - 2) * 0.53 + skew * (2 - layer) * 0.035,
y: 0.36 + layer * 0.49,
z: (row - 1) * 0.53
});
}
}
}
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.3,
metalness: 0.18,
emissive: new THREE.Color(color).multiplyScalar(0.1),
emissiveIntensity: 0.7
});
const voxels = new THREE.InstancedMesh(
VOXEL_GEOMETRY,
material,
positions.length
);
voxels.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
voxels.castShadow = true;
voxels.receiveShadow = true;
group.add(voxels);
const initialColor = color.clone().multiplyScalar(0.22);
for (let i = 0; i < positions.length; i++) {
voxels.setColorAt(i, initialColor);
}
voxels.instanceColor.setUsage(THREE.DynamicDrawUsage);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.05, 2.2, 0.2, 48),
new THREE.MeshStandardMaterial({
color: 0x09121f,
roughness: 0.55,
metalness: 0.48,
emissive: new THREE.Color(color).multiplyScalar(0.015)
})
);
platform.position.y = -0.01;
platform.receiveShadow = true;
group.add(platform);
const underglow = new THREE.Mesh(
new THREE.CircleGeometry(2.12, 64),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.045,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
underglow.rotation.x = -Math.PI / 2;
underglow.position.y = -0.105;
group.add(underglow);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(2.02, 0.025, 8, 80),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.36,
blending: THREE.AdditiveBlending
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.1;
group.add(rim);
const light = new THREE.PointLight(color, 4, 8, 2);
light.position.set(0, 1.3, 1);
group.add(light);
return {
name,
color,
group,
voxels,
positions,
rim,
underglow,
light,
material,
centerRank: -1,
activity: 0
};
}
const ensembleA = createEnsemble("A", A_COLOR, -4.05, false);
const ensembleB = createEnsemble("B", B_COLOR, 4.05, true);
// ------------------------------------------------------------------
// Central phrase threshold and boundary effect
// ------------------------------------------------------------------
const thresholdMaterial = new THREE.MeshBasicMaterial({
color: 0xb9efff,
transparent: true,
opacity: 0.18,
blending: THREE.AdditiveBlending
});
const threshold = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 2.9, 0.025),
thresholdMaterial
);
threshold.position.set(0, 1.25, 0);
scene.add(threshold);
const thresholdFoot = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.025, 4.2),
thresholdMaterial
);
thresholdFoot.position.set(0, -0.085, 0);
scene.add(thresholdFoot);
const boundaryMaterial = new THREE.MeshBasicMaterial({
color: 0xc8f2ff,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const boundaryRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.028, 8, 96),
boundaryMaterial
);
boundaryRing.position.set(0, 1.35, 0);
scene.add(boundaryRing);
const boundaryFloor = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.025, 8, 96),
boundaryMaterial
);
boundaryFloor.rotation.x = Math.PI / 2;
boundaryFloor.position.set(0, -0.07, 0);
scene.add(boundaryFloor);
// A faint path shows the direction of the response.
const pathCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.05, 1.25, 0),
new THREE.Vector3(-2.1, 1.5, 0),
new THREE.Vector3(0, 1.95, 0),
new THREE.Vector3(2.1, 1.5, 0),
new THREE.Vector3(4.05, 1.25, 0)
]);
const path = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(pathCurve.getPoints(90)),
new THREE.LineBasicMaterial({
color: 0x6b9cb2,
transparent: true,
opacity: 0.2,
blending: THREE.AdditiveBlending
})
);
scene.add(path);
// ------------------------------------------------------------------
// Traveling response signal
// ------------------------------------------------------------------
const signalBeads = [];
const beadGeometry = new THREE.SphereGeometry(0.12, 12, 8);
for (let i = 0; i < 8; i++) {
const bead = new THREE.Mesh(
beadGeometry,
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
bead.visible = false;
scene.add(bead);
signalBeads.push(bead);
}
const signalLight = new THREE.PointLight(0xffffff, 0, 4, 2);
scene.add(signalLight);
// ------------------------------------------------------------------
// Floor rhythm strip
// ------------------------------------------------------------------
const floorTicks = [];
const tickGeometry = new THREE.BoxGeometry(0.42, 0.035, 0.13);
for (let i = 0; i < 16; i++) {
const mesh = new THREE.Mesh(
tickGeometry,
new THREE.MeshBasicMaterial({
color: 0x35516a,
transparent: true,
opacity: 0.28
})
);
mesh.position.set(-4.2 + i * 0.56, -0.065, 2.65);
scene.add(mesh);
floorTicks.push(mesh);
}
// ------------------------------------------------------------------
// DOM timeline
// ------------------------------------------------------------------
const timeline = document.getElementById("timeline");
const domTicks = [];
for (let i = 0; i < 16; i++) {
const tick = document.createElement("div");
tick.className = "tick";
timeline.appendChild(tick);
domTicks.push(tick);
}
const phraseNumber = document.getElementById("phrase-number");
const phaseName = document.getElementById("phase-name");
const roleName = document.getElementById("role-name");
const callLabel = document.getElementById("call-label");
const responseLabel = document.getElementById("response-label");
const labelARole = document.getElementById("label-a-role");
const labelBRole = document.getElementById("label-b-role");
const boundaryFlash = document.getElementById("boundary-flash");
const labelA = document.getElementById("label-a");
const labelB = document.getElementById("label-b");
// ------------------------------------------------------------------
// Rhythmic patterns. Each phrase has an eight-beat call followed by
// an eight-beat response. The lead/answer roles swap every phrase.
// ------------------------------------------------------------------
const CALL_PATTERNS = {
A: [0, 4, 2, 5, 1, 4, 3, 6],
B: [1, 4, 0, 5, 2, 4, 1, 6]
};
const RESPONSE_PATTERNS = {
A: [3, 1, 4, 2, 5, 1, 3, 4],
B: [2, 4, 1, 5, 3, 1, 4, 2]
};
const BEAT_DURATION = 0.56;
const BEATS_PER_PHRASE = 16;
const PHRASE_DURATION = BEAT_DURATION * BEATS_PER_PHRASE;
function rankAtBeat(beat, pattern, count) {
let offset = 0;
for (let i = 0; i < beat; i++) {
offset += pattern[i % pattern.length];
}
return ((offset % count) + count) % count;
}
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
const signalPoint = new THREE.Vector3();
let previousBeat = -1;
let previousPhrase = -1;
function updateEnsemble(ensemble, centerRank, active, time, beatPulse) {
const count = ensemble.positions.length;
ensemble.centerRank = centerRank;
ensemble.activity = 0;
for (let i = 0; i < count; i++) {
const position = ensemble.positions[i];
let activity = 0;
if (centerRank >= 0) {
const distance = (centerRank - i + count) % count;
if (distance < 7) {
activity = Math.exp(-distance * 0.82);
}
}
ensemble.activity = Math.max(ensemble.activity, activity);
const idle = 0.1 + 0.025 *
(0.5 + 0.5 * Math.sin(time * 2.2 + i * 0.41));
const strength = active
? 0.3 + idle + activity * 0.8 + beatPulse * 0.08
: idle;
tempColor
.copy(ensemble.color)
.multiplyScalar(strength)
.lerp(WHITE, activity * 0.76);
ensemble.voxels.setColorAt(i, tempColor);
const scale = 1 + activity * 0.22;
const verticalScale = 1 + activity * 0.6;
dummy.position.set(
position.x,
position.y,
position.z + activity * 0.045
);
dummy.scale.set(scale, verticalScale, scale);
dummy.updateMatrix();
ensemble.voxels.setMatrixAt(i, dummy.matrix);
}
ensemble.voxels.instanceMatrix.needsUpdate = true;
ensemble.voxels.instanceColor.needsUpdate = true;
ensemble.rim.material.opacity =
0.25 + ensemble.activity * 0.55 + beatPulse * 0.08;
ensemble.underglow.material.opacity =
0.035 + ensemble.activity * 0.12;
ensemble.light.intensity =
2.5 + ensemble.activity * 13 + beatPulse * 2;
const ringScale = 1 + beatPulse * 0.055 + ensemble.activity * 0.025;
ensemble.rim.scale.setScalar(ringScale);
}
function updateSignal(source, target, progress) {
const from = new THREE.Vector3(
source.group.position.x,
1.35,
source.group.position.z
);
const to = new THREE.Vector3(
target.group.position.x,
1.35,
target.group.position.z
);
for (let i = 0; i < signalBeads.length; i++) {
const bead = signalBeads[i];
const p = THREE.MathUtils.clamp(
progress - i * 0.055,
0,
1
);
bead.visible = true;
bead.material.color.copy(source.color);
bead.material.opacity = (1 - i / signalBeads.length) * 0.9;
signalPoint.lerpVectors(from, to, p);
signalPoint.y += Math.sin(p * Math.PI) * 1.35;
bead.position.copy(signalPoint);
const scale = 1 - i * 0.075;
bead.scale.setScalar(scale);
if (i === 0) {
signalLight.position.copy(signalPoint);
}
}
signalLight.color.copy(source.color);
signalLight.intensity = 7;
}
function hideSignal() {
for (const bead of signalBeads) {
bead.visible = false;
}
signalLight.intensity = 0;
}
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateCamera(dt);
const phrase = Math.floor(time / PHRASE_DURATION);
const phraseTime = time % PHRASE_DURATION;
const beatFloat = phraseTime / BEAT_DURATION;
const beat = Math.min(
BEATS_PER_PHRASE - 1,
Math.floor(beatFloat)
);
const beatProgress = beatFloat - Math.floor(beatFloat);
const beatPulse = Math.exp(-beatProgress * 7.5);
const leader = phrase % 2 === 0 ? ensembleA : ensembleB;
const responder = phrase % 2 === 0 ? ensembleB : ensembleA;
const callCenter = rankAtBeat(
beat,
CALL_PATTERNS[leader.name],
leader.positions.length
);
const responseCenter = rankAtBeat(
beat - 8,
RESPONSE_PATTERNS[responder.name],
responder.positions.length
);
const transferring = beat === 8 && beatProgress < 0.48;
const responseHasArrived = beat > 8 || beatProgress >= 0.48;
updateEnsemble(
leader,
beat < 8 ? callCenter : -1,
beat < 8 && !transferring,
time,
beatPulse
);
updateEnsemble(
responder,
beat >= 8 && responseHasArrived ? responseCenter : -1,
beat >= 8 && responseHasArrived,
time,
beatPulse
);
if (transferring) {
updateSignal(
leader,
responder,
THREE.MathUtils.clamp(beatProgress / 0.48, 0, 1)
);
} else {
hideSignal();
}
// A distinct phrase-boundary pulse resets the visual field.
const boundaryAge = phraseTime;
const boundaryFlashAmount =
boundaryAge < 0.9 ? Math.exp(-boundaryAge * 4.2) : 0;
boundaryMaterial.opacity = boundaryFlashAmount * 0.85;
boundaryRing.scale.setScalar(
0.55 + (1 - boundaryFlashAmount) * 3.8
);
boundaryFloor.scale.setScalar(
0.55 + (1 - boundaryFlashAmount) * 4.8
);
thresholdMaterial.opacity =
0.14 + boundaryFlashAmount * 0.62;
boundaryFlash.style.opacity =
String(boundaryFlashAmount * 0.2);
// Floor rhythm strip.
for (let i = 0; i < floorTicks.length; i++) {
const active = i === beat;
const tone = i < 8 ? leader.color : responder.color;
const inactiveColor = tone.clone().multiplyScalar(0.2);
floorTicks[i].material.color.copy(
active ? tone : inactiveColor
);
floorTicks[i].material.opacity =
active ? 0.85 + beatPulse * 0.15 : 0.22;
floorTicks[i].scale.y = active ? 1 + beatPulse * 3.2 : 1;
}
// DOM state.
if (phrase !== previousPhrase) {
previousPhrase = phrase;
phraseNumber.textContent =
`PHRASE ${String(phrase + 1).padStart(2, "0")}`;
callLabel.textContent = `${leader.name} / CALL`;
responseLabel.textContent = `${responder.name} / RESPONSE`;
roleName.textContent =
`LEAD ${leader.name} · ANSWER ${responder.name}`;
labelARole.textContent =
leader.name === "A" ? "LEAD" : "ANSWER";
labelBRole.textContent =
responder.name === "B" ? "ANSWER" : "LEAD";
for (let i = 0; i < domTicks.length; i++) {
const tone = i < 8 ? leader.color : responder.color;
domTicks[i].style.setProperty(
"--tick-color",
`#${tone.getHexString()}`
);
}
}
if (beat !== previousBeat) {
previousBeat = beat;
for (let i = 0; i < domTicks.length; i++) {
domTicks[i].classList.toggle("active", i === beat);
domTicks[i].classList.toggle("passed", i < beat);
}
}
if (phraseTime < 0.78) {
phaseName.textContent = "PHRASE BOUNDARY";
} else if (beat < 8) {
phaseName.textContent = `${leader.name} CALL`;
} else if (transferring) {
phaseName.textContent = `${leader.name} → ${responder.name}`;
} else {
phaseName.textContent = `${responder.name} RESPONSE`;
}
dust.rotation.y = time * 0.012;
dust.position.y = Math.sin(time * 0.11) * 0.14;
const labelAWorld = new THREE.Vector3(
ensembleA.group.position.x,
2.38,
ensembleA.group.position.z
);
const labelBWorld = new THREE.Vector3(
ensembleB.group.position.x,
2.38,
ensembleB.group.position.z
);
projectLabel(labelA, labelAWorld);
projectLabel(labelB, labelBWorld);
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
animate();
</script>
</body>
</html>
```