Prompt specification
Build or customize the Three.js 3D scene "Three-Beat and Four-Beat Clappers" 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: Three-Beat and Four-Beat Clappers
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-beat-and-four-beat-clappers-x3342
Scene Description Prompt:
Animate two rows of mechanical clappers following the same pulse but different accent cycles. Provide silent visual playback and align their shared cycle boundaries. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (three-beat-and-four-beat-clappers-x3342):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mechanical Clapper Array</title>
<style>
:root {
--bg: #071018;
--panel: rgba(8, 18, 28, 0.78);
--line: rgba(176, 218, 234, 0.18);
--text: #e8f1f4;
--muted: #8299a5;
--cyan: #35d6e8;
--amber: #ffb35c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 38%, rgba(1, 5, 9, 0.43) 100%);
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
user-select: none;
}
.topbar {
position: absolute;
top: 26px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 40px);
font-weight: 700;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.06em;
}
.status {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 9px;
color: #c5d5dc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px rgba(53, 214, 232, 0.9);
transform-origin: center;
}
.silent {
margin-top: 8px;
color: #617681;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.2em;
text-align: right;
}
#transport {
position: absolute;
left: 50%;
bottom: 22px;
width: min(920px, calc(100% - 32px));
transform: translateX(-50%);
padding: 16px 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
}
.transport-main {
display: grid;
grid-template-columns: 190px minmax(260px, 1fr) auto;
align-items: center;
gap: 22px;
}
.readout-label,
.transport-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#cycle {
display: block;
font-size: 17px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.04em;
}
#event {
display: block;
min-height: 13px;
margin-top: 4px;
color: #9eb2bc;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.beat-area {
min-width: 0;
}
.beat-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.beat-heading span:last-child {
color: #6f8793;
font-size: 9px;
letter-spacing: 0.1em;
}
.beat-dots {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 8px;
}
.beat-dot {
position: relative;
height: 10px;
overflow: hidden;
border: 1px solid rgba(151, 185, 198, 0.18);
border-radius: 999px;
background: rgba(140, 171, 183, 0.08);
transition: background 100ms ease, border-color 100ms ease;
}
.beat-dot::before,
.beat-dot::after {
content: "";
position: absolute;
top: 2px;
bottom: 2px;
width: 3px;
border-radius: 3px;
opacity: var(--a, 0);
}
.beat-dot::before {
left: 3px;
background: var(--cyan);
}
.beat-dot::after {
right: 3px;
background: var(--amber);
}
.beat-dot.active {
border-color: rgba(230, 248, 255, 0.68);
background: rgba(230, 248, 255, 0.82);
}
.progress-track {
position: relative;
height: 2px;
margin-top: 9px;
overflow: hidden;
border-radius: 2px;
background: rgba(148, 182, 195, 0.12);
}
#progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
background: linear-gradient(90deg, var(--cyan), #eafcff);
box-shadow: 0 0 12px rgba(53, 214, 232, 0.6);
}
.transport-actions {
display: flex;
gap: 8px;
}
button {
pointer-events: auto;
height: 36px;
padding: 0 13px;
border: 1px solid rgba(161, 201, 214, 0.22);
border-radius: 9px;
background: rgba(144, 189, 205, 0.08);
color: #dce9ed;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(53, 214, 232, 0.55);
background: rgba(53, 214, 232, 0.12);
}
.patterns {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(154, 191, 203, 0.11);
}
.pattern {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 10px;
min-width: 0;
}
.swatch {
width: 7px;
height: 26px;
border-radius: 3px;
}
.swatch.cyan {
background: var(--cyan);
box-shadow: 0 0 12px rgba(53, 214, 232, 0.55);
}
.swatch.amber {
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 179, 92, 0.55);
}
.pattern b,
.pattern small {
display: block;
}
.pattern b {
font-size: 10px;
letter-spacing: 0.12em;
}
.pattern small {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.mini-dots {
display: flex;
gap: 5px;
}
.mini-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: rgba(175, 205, 215, 0.18);
}
.pattern.cyan .mini-dot.active {
background: var(--cyan);
box-shadow: 0 0 9px var(--cyan);
}
.pattern.amber .mini-dot.active {
background: var(--amber);
box-shadow: 0 0 9px var(--amber);
}
.pattern.dual {
filter: brightness(1.18);
}
.hint {
position: absolute;
right: 28px;
bottom: 27px;
color: rgba(139, 167, 179, 0.65);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.topbar {
top: 18px;
left: 18px;
right: 18px;
}
.subtitle {
max-width: 210px;
line-height: 1.45;
}
.status {
font-size: 8px;
}
#transport {
bottom: 12px;
padding: 13px;
}
.transport-main {
grid-template-columns: 1fr auto;
gap: 12px;
}
.beat-area {
grid-column: 1 / -1;
grid-row: 2;
}
.patterns {
gap: 8px;
}
.pattern {
gap: 7px;
}
.pattern small {
letter-spacing: 0.05em;
}
.hint {
display: none;
}
}
@media (max-width: 440px) {
.silent,
.status-text {
display: none;
}
.patterns {
grid-template-columns: 1fr;
}
.mini-dots {
justify-content: flex-end;
}
.transport-actions button:last-child {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div class="ui">
<header class="topbar">
<div>
<div class="eyebrow">Mechanical Rhythm Study</div>
<h1>Clapper Array</h1>
<p class="subtitle">Two rows · one transport · offset accent cycles</p>
</div>
<div>
<div class="status">
<span class="status-dot" id="statusDot"></span>
<span class="status-text" id="statusText">Visual playback</span>
</div>
<div class="silent">Silent · no audio</div>
</div>
</header>
<section id="transport" aria-label="Shared pulse transport">
<div class="transport-main">
<div>
<span class="readout-label">Shared cycle</span>
<strong id="cycle">Pulse 01 / 06</strong>
<span id="event">Shared boundary · dual accent</span>
</div>
<div class="beat-area">
<div class="beat-heading">
<span class="transport-label">Common pulse</span>
<span>6-beat phrase</span>
</div>
<div class="beat-dots" id="beatDots"></div>
<div class="progress-track"><div id="progress"></div></div>
</div>
<div class="transport-actions">
<button id="toggle" type="button" aria-label="Pause animation">Ⅱ Pause</button>
<button id="resetView" type="button">Reset view</button>
</div>
</div>
<div class="patterns">
<div class="pattern cyan" id="patternA">
<span class="swatch cyan"></span>
<div>
<b>Row A</b>
<small>2-beat accent cycle</small>
</div>
<div class="mini-dots" id="miniA"></div>
</div>
<div class="pattern amber" id="patternB">
<span class="swatch amber"></span>
<div>
<b>Row B</b>
<small>3-beat accent cycle</small>
</div>
<div class="mini-dots" id="miniB"></div>
</div>
</div>
</section>
<div class="hint">Drag to orbit · scroll to zoom · R to reset</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 container = document.getElementById("scene");
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Two rows of animated mechanical clappers on a shared six-beat pulse"
);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 15, 33);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.35, -0.45);
const initialRadius = window.innerWidth < 700 ? 23 : 15.5;
const initialTheta = 0.22;
const initialPhi = 0.82;
let cameraTheta = initialTheta;
let cameraPhi = initialPhi;
let cameraRadius = initialRadius;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xa7dcff, 0x10131b, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xf4fbff, 3.2);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x35d6e8, 24, 16, 2);
cyanLight.position.set(-7, 4, -4);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa94f, 22, 16, 2);
amberLight.position.set(7, 3, 5);
scene.add(amberLight);
// Shared materials
const upperSlateMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e3d7,
roughness: 0.68,
metalness: 0.08,
flatShading: true
});
const stripeMaterial = new THREE.MeshStandardMaterial({
color: 0x10161c,
roughness: 0.58,
metalness: 0.16,
flatShading: true
});
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0x9caab0,
roughness: 0.28,
metalness: 0.82,
flatShading: true
});
const hingeDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x26323a,
roughness: 0.36,
metalness: 0.68,
flatShading: true
});
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x121b23,
roughness: 0.72,
metalness: 0.38,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x8aa0aa,
transparent: true,
opacity: 0.18
});
function addEdges(mesh, color = 0x8aa0aa) {
const material = color === 0x8aa0aa
? edgeMaterial
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.24
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
material
);
mesh.add(edges);
return edges;
}
// Floor and low-poly stage
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x08121a,
roughness: 0.95,
metalness: 0.08
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.44;
floor.receiveShadow = true;
scene.add(floor);
const stageMaterial = new THREE.MeshStandardMaterial({
color: 0x101c27,
roughness: 0.76,
metalness: 0.28,
flatShading: true
});
const stage = new THREE.Mesh(
new THREE.BoxGeometry(10.6, 0.34, 6.9),
stageMaterial
);
stage.position.set(0, -0.24, -0.85);
stage.receiveShadow = true;
scene.add(stage);
const grid = new THREE.GridHelper(10.4, 20, 0x4c7180, 0x263d49);
grid.position.set(0, -0.058, -0.85);
grid.scale.z = 0.65;
grid.material.transparent = true;
grid.material.opacity = 0.17;
scene.add(grid);
// The shared phrase boundary is drawn around the stage.
const boundaryMaterial = new THREE.MeshBasicMaterial({
color: 0xc9f7ff,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const boundaryBars = [
new THREE.Mesh(
new THREE.BoxGeometry(10.15, 0.018, 0.035),
boundaryMaterial
),
new THREE.Mesh(
new THREE.BoxGeometry(10.15, 0.018, 0.035),
boundaryMaterial
),
new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.018, 6.42),
boundaryMaterial
),
new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.018, 6.42),
boundaryMaterial
)
];
boundaryBars[0].position.set(0, -0.045, 2.52);
boundaryBars[1].position.set(0, -0.045, -4.22);
boundaryBars[2].position.set(-5.18, -0.045, -0.85);
boundaryBars[3].position.set(5.18, -0.045, -0.85);
boundaryBars.forEach((bar) => scene.add(bar));
// Shared timing:
// Row A accents every 2 beats.
// Row B accents every 3 beats.
// Their common boundaries therefore reset every LCM(2, 3) = 6 beats.
const BEAT_DURATION = 0.9;
const PULSE_COUNT = 6;
const PHRASE_DURATION = BEAT_DURATION * PULSE_COUNT;
const rowDefinitions = [
{
name: "A",
z: -2.52,
color: 0x35d6e8,
accentEvery: 2,
normalAngle: 0.34,
accentAngle: 0.77
},
{
name: "B",
z: 0.42,
color: 0xffb35c,
accentEvery: 3,
normalAngle: 0.30,
accentAngle: 0.85
}
];
const columnPositions = [-3.2, -1.6, 0, 1.6, 3.2];
function createClapper(row, column, columnIndex) {
const group = new THREE.Group();
group.position.set(column, 0, row.definition.z);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: row.index === 0 ? 0x172a38 : 0x202b34,
roughness: 0.58,
metalness: 0.36,
flatShading: true
});
// Lower slate
const lowerSlate = new THREE.Mesh(
new THREE.BoxGeometry(1.18, 0.18, 1.64),
bodyMaterial
);
lowerSlate.position.set(0, 0.38, 0);
lowerSlate.castShadow = true;
lowerSlate.receiveShadow = true;
addEdges(lowerSlate);
group.add(lowerSlate);
// Front accent strip
const frontTrim = new THREE.Mesh(
new THREE.BoxGeometry(0.96, 0.055, 0.055),
row.trimMaterial
);
frontTrim.position.set(0, 0.405, 0.825);
group.add(frontTrim);
// Mechanical support blocks
const supportGeometry = new THREE.BoxGeometry(0.23, 0.23, 0.48);
for (const x of [-0.42, 0.42]) {
const support = new THREE.Mesh(supportGeometry, standMaterial);
support.position.set(x, 0.16, 0.08);
support.castShadow = true;
support.receiveShadow = true;
group.add(support);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.07, 0.68),
hingeDarkMaterial
);
foot.position.set(x, 0.045, 0.08);
foot.castShadow = true;
group.add(foot);
}
// Hinged upper slate. The pivot is exactly at its rear hinge line.
const topPivot = new THREE.Group();
topPivot.position.set(0, 0.50, -0.84);
group.add(topPivot);
const upperSlate = new THREE.Mesh(
new THREE.BoxGeometry(1.18, 0.16, 1.64),
upperSlateMaterial
);
upperSlate.position.set(0, 0.08, 0.82);
upperSlate.castShadow = true;
upperSlate.receiveShadow = true;
addEdges(upperSlate);
topPivot.add(upperSlate);
// Traditional diagonal clapper stripes, built from low-poly boxes.
const stripeGeometry = new THREE.BoxGeometry(0.14, 0.022, 1.10);
for (const x of [-0.21, -0.07, 0.07, 0.21]) {
const stripe = new THREE.Mesh(stripeGeometry, stripeMaterial);
stripe.position.set(x, 0.171, 0.82);
stripe.rotation.y = -0.55;
stripe.castShadow = true;
topPivot.add(stripe);
}
const frontCap = new THREE.Mesh(
new THREE.BoxGeometry(1.14, 0.13, 0.055),
stripeMaterial
);
frontCap.position.set(0, 0.08, 1.635);
frontCap.castShadow = true;
topPivot.add(frontCap);
// Hinge barrel and end caps
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 1.25, 10),
hingeMaterial
);
hinge.rotation.z = Math.PI / 2;
hinge.castShadow = true;
topPivot.add(hinge);
for (const x of [-0.65, 0.65]) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.135, 0.135, 0.075, 10),
hingeDarkMaterial
);
cap.rotation.z = Math.PI / 2;
cap.position.x = x;
cap.castShadow = true;
topPivot.add(cap);
}
// Small faceted status indicator.
const led = new THREE.Mesh(
new THREE.OctahedronGeometry(0.085, 0),
row.ledMaterial
);
led.position.set(0.72, 0.05, 0.08);
topPivot.add(led);
scene.add(group);
return {
group,
topPivot,
led,
weight: 1 + (columnIndex - 2) * 0.012
};
}
const rows = rowDefinitions.map((definition, index) => {
const color = new THREE.Color(definition.color);
const trimMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.36,
metalness: 0.28
});
const ledMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.0,
roughness: 0.25,
metalness: 0.22,
flatShading: true
});
const railMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const row = {
index,
definition,
trimMaterial,
ledMaterial,
railMaterial,
clappers: []
};
row.clappers = columnPositions.map((x, columnIndex) =>
createClapper(row, x, columnIndex)
);
// Colored rail under the hinge line.
const rail = new THREE.Mesh(
new THREE.BoxGeometry(7.8, 0.035, 0.07),
railMaterial
);
rail.position.set(0, 0.20, definition.z - 0.91);
scene.add(rail);
return row;
});
// Six physical pulse markers along the front edge of the stage.
const beatMarkers = [];
const inactiveMarker = new THREE.Color(0x10232d);
const baseMarker = new THREE.Color(0x78909c);
const cyanColor = new THREE.Color(0x35d6e8);
const amberColor = new THREE.Color(0xffb35c);
const whiteColor = new THREE.Color(0xeafcff);
for (let i = 0; i < PULSE_COUNT; i++) {
const material = new THREE.MeshStandardMaterial({
color: inactiveMarker,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.42,
metalness: 0.36
});
const marker = new THREE.Mesh(
new THREE.BoxGeometry(1.04, 0.027, 0.095),
material
);
marker.position.set(-3.75 + i * 1.5, -0.035, 2.18);
scene.add(marker);
beatMarkers.push(marker);
}
// UI elements
const cycleElement = document.getElementById("cycle");
const eventElement = document.getElementById("event");
const progressElement = document.getElementById("progress");
const statusDot = document.getElementById("statusDot");
const statusText = document.getElementById("statusText");
const toggleButton = document.getElementById("toggle");
const resetViewButton = document.getElementById("resetView");
const beatDotElements = [];
for (let i = 0; i < PULSE_COUNT; i++) {
const dot = document.createElement("div");
dot.className = "beat-dot";
beatDotElements.push(dot);
document.getElementById("beatDots").appendChild(dot);
}
function createMiniDots(elementId, count) {
const dots = [];
const container = document.getElementById(elementId);
for (let i = 0; i < count; i++) {
const dot = document.createElement("span");
dot.className = "mini-dot";
dots.push(dot);
container.appendChild(dot);
}
return dots;
}
const miniA = createMiniDots("miniA", 3);
const miniB = createMiniDots("miniB", 2);
const patternA = document.getElementById("patternA");
const patternB = document.getElementById("patternB");
// Animation state
let elapsed = 0;
let paused = false;
let lastTime = performance.now();
function smoothStep(edge0, edge1, value) {
const x = THREE.MathUtils.clamp(
(value - edge0) / (edge1 - edge0),
0,
1
);
return x * x * (3 - 2 * x);
}
function clapEnvelope(phase, accent) {
const attackEnd = accent ? 0.10 : 0.075;
const holdEnd = attackEnd + (accent ? 0.22 : 0.075);
const closeEnd = accent ? 0.77 : 0.63;
if (phase < attackEnd) {
const x = phase / attackEnd;
return 1 - Math.pow(1 - x, 3);
}
if (phase < holdEnd) {
return 1;
}
if (phase < closeEnd) {
const x = (phase - holdEnd) / (closeEnd - holdEnd);
const closing = 1 - smoothStep(0, 1, x);
const recoil =
0.035 *
Math.sin(x * Math.PI * 3) *
Math.exp(-x * 4);
return Math.max(0, closing + recoil);
}
return 0;
}
function updateScene(time) {
const phraseElapsed = time % PHRASE_DURATION;
const beatIndex = Math.min(
PULSE_COUNT - 1,
Math.floor(phraseElapsed / BEAT_DURATION)
);
const beatPhase =
(phraseElapsed % BEAT_DURATION) / BEAT_DURATION;
const accentA = beatIndex % 2 === 0;
const accentB = beatIndex % 3 === 0;
const sharedBoundary =
beatIndex === 0 && phraseElapsed < 0.42;
for (const row of rows) {
const accent =
row.index === 0 ? accentA : accentB;
const envelope = clapEnvelope(beatPhase, accent);
const maximumAngle =
(accent
? row.definition.accentAngle
: row.definition.normalAngle) * envelope;
for (const clapper of row.clappers) {
clapper.topPivot.rotation.x =
-maximumAngle * clapper.weight;
clapper.led.rotation.y =
elapsed * 0.65 + clapper.group.position.x;
}
row.trimMaterial.emissiveIntensity =
0.35 +
envelope * 1.6 +
(accent ? 1.9 : 0);
row.ledMaterial.emissiveIntensity =
0.65 +
envelope * 2.8 +
(accent ? 2.8 : 0);
row.railMaterial.opacity =
0.15 +
envelope * 0.42 +
(accent ? 0.22 : 0);
}
// A brighter perimeter marks the common cycle reset.
const boundaryPulse = sharedBoundary
? 1 - phraseElapsed / 0.42
: 0;
boundaryMaterial.opacity =
0.10 + boundaryPulse * 0.72;
boundaryMaterial.color.set(
sharedBoundary ? 0xe7fbff : 0x91bdc8
);
// Physical beat markers.
for (let i = 0; i < beatMarkers.length; i++) {
const marker = beatMarkers[i];
const active = i === beatIndex;
const markerAccentA = active && i % 2 === 0;
const markerAccentB = active && i % 3 === 0;
let color = baseMarker;
if (active) {
if (markerAccentA && markerAccentB) {
color = whiteColor;
} else if (markerAccentA) {
color = cyanColor;
} else if (markerAccentB) {
color = amberColor;
}
}
marker.material.color.copy(
active ? color : inactiveMarker
);
marker.material.emissive.copy(color);
marker.material.emissiveIntensity = active
? (markerAccentA || markerAccentB ? 2.6 : 1.25)
: 0;
}
// DOM transport
cycleElement.textContent =
`Pulse ${String(beatIndex + 1).padStart(2, "0")} / 06`;
if (sharedBoundary) {
eventElement.textContent = "Shared boundary · dual accent";
} else if (accentA && accentB) {
eventElement.textContent = "Dual accent";
} else if (accentA) {
eventElement.textContent = "Row A accent";
} else if (accentB) {
eventElement.textContent = "Row B accent";
} else {
eventElement.textContent = "Base pulse";
}
progressElement.style.width =
`${(phraseElapsed / PHRASE_DURATION) * 100}%`;
for (let i = 0; i < beatDotElements.length; i++) {
const dot = beatDotElements[i];
const active = i === beatIndex;
dot.classList.toggle("active", active);
dot.style.setProperty(
"--a",
active && i % 2 === 0 ? "1" : "0"
);
dot.style.setProperty(
"--b",
active && i % 3 === 0 ? "1" : "0"
);
}
for (let i = 0; i < miniA.length; i++) {
const accentBeat = i * 2;
miniA[i].classList.toggle(
"active",
beatIndex === accentBeat
);
}
for (let i = 0; i < miniB.length; i++) {
const accentBeat = i * 3;
miniB[i].classList.toggle(
"active",
beatIndex === accentBeat
);
}
patternA.classList.toggle("dual", accentA && accentB);
patternB.classList.toggle("dual", accentA && accentB);
const globalEnvelope = clapEnvelope(
beatPhase,
accentA || accentB
);
statusDot.style.transform =
`scale(${1 + globalEnvelope * 0.65})`;
statusDot.style.opacity =
`${0.55 + globalEnvelope * 0.45}`;
}
// Playback control
function updateToggleLabel() {
toggleButton.textContent = paused ? "▶ Play" : "Ⅱ Pause";
toggleButton.setAttribute(
"aria-label",
paused ? "Resume animation" : "Pause animation"
);
statusText.textContent = paused
? "Playback paused"
: "Visual playback";
}
toggleButton.addEventListener("click", () => {
paused = !paused;
updateToggleLabel();
});
// Camera controls implemented directly, without external controls modules.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) {
return;
}
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.005;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.004,
0.36,
1.28
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10,
29
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraTheta = initialTheta;
cameraPhi = initialPhi;
cameraRadius = initialRadius;
updateCamera();
}
resetViewButton.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "KeyR") {
resetCamera();
}
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
paused = !paused;
updateToggleLabel();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
});
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
elapsed += delta;
}
updateScene(elapsed);
renderer.render(scene, camera);
}
updateToggleLabel();
requestAnimationFrame(animate);
</script>
</body>
</html>
```