Prompt specification
Build or customize the Three.js 3D scene "Polyrhythm Courtyard Explorer" 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: Polyrhythm Courtyard Explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/polyrhythm-courtyard-explorer-x3344
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing regular pulses, accents, and rhythmic grouping. Create a courtyard installation comparing three equally spaced beats against two over one cycle. Let users slow playback and observe recurring alignments without confusing tempo with meter. Voxel style.
Working Three.js Starter (polyrhythm-courtyard-explorer-x3344):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three, Then Two — Voxel Rhythm Courtyard</title>
<style>
:root {
--ink: #20312e;
--muted: #60716c;
--paper: rgba(248, 245, 235, 0.92);
--paper-solid: #f8f5eb;
--line: rgba(32, 49, 46, 0.16);
--teal: #2a9d8f;
--coral: #e76f51;
--gold: #e9c46a;
--gold-deep: #b98721;
--shadow: 0 18px 50px rgba(37, 53, 49, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e3dd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.title-card,
.console,
.view-hint {
pointer-events: auto;
}
.title-card {
position: absolute;
top: 22px;
left: 24px;
width: min(430px, calc(100vw - 48px));
padding: 20px 22px 19px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--gold-deep);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 43px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
}
.title-card p {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.console {
position: absolute;
top: 22px;
right: 24px;
width: 350px;
max-height: calc(100vh - 44px);
overflow: auto;
padding: 18px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
.console::-webkit-scrollbar {
width: 7px;
}
.console::-webkit-scrollbar-thumb {
background: rgba(32, 49, 46, 0.18);
border-radius: 10px;
}
.panel-row,
.transport,
.speed-header,
.timeline-heading,
.legend,
.anchor-row {
display: flex;
align-items: center;
}
.panel-row,
.speed-header,
.timeline-heading,
.anchor-row {
justify-content: space-between;
}
.panel-title {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live-badge {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(42, 157, 143, 0.13);
}
.console section {
margin-top: 17px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.transport {
gap: 8px;
}
button {
border: 0;
cursor: pointer;
color: var(--ink);
transition:
transform 120ms ease,
background 120ms ease,
box-shadow 120ms ease;
}
button:hover {
transform: translateY(-1px);
}
button:active {
transform: translateY(1px);
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(233, 196, 106, 0.52);
outline-offset: 2px;
}
.primary-button {
flex: 1;
min-height: 42px;
border-radius: 11px;
background: var(--ink);
color: #fffdf4;
font-size: 12px;
font-weight: 750;
}
.secondary-button {
min-height: 42px;
padding: 0 14px;
border-radius: 11px;
background: rgba(32, 49, 46, 0.08);
font-size: 12px;
font-weight: 700;
}
.speed-header {
margin-bottom: 10px;
}
.speed-header label {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
#speedValue {
color: var(--ink);
font-size: 13px;
font-weight: 800;
}
#speed {
width: 100%;
height: 6px;
margin: 0;
border-radius: 10px;
appearance: none;
background:
linear-gradient(
90deg,
var(--gold-deep) 0%,
var(--gold-deep) var(--speed-fill, 44.4%),
rgba(32, 49, 46, 0.13) var(--speed-fill, 44.4%)
);
cursor: pointer;
}
#speed::-webkit-slider-thumb {
width: 19px;
height: 19px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
appearance: none;
background: var(--gold-deep);
box-shadow: 0 2px 7px rgba(32, 49, 46, 0.25);
}
#speed::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--gold-deep);
box-shadow: 0 2px 7px rgba(32, 49, 46, 0.25);
}
.speed-presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 11px;
}
.speed-presets button {
padding: 7px 4px;
border-radius: 9px;
background: rgba(32, 49, 46, 0.065);
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.speed-presets button.active {
background: rgba(233, 196, 106, 0.35);
color: #725114;
}
.fact-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 14px;
}
.fact {
min-height: 69px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.35);
}
.fact span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.fact strong {
display: block;
font-size: 13px;
line-height: 1.3;
}
.explanation {
margin: 12px 0 0;
padding: 11px 12px;
border-left: 3px solid var(--gold);
border-radius: 0 10px 10px 0;
background: rgba(233, 196, 106, 0.12);
color: #5d5a43;
font-size: 11px;
line-height: 1.5;
}
.timeline {
position: relative;
margin-top: 13px;
padding-left: 37px;
}
.timeline-plot {
position: relative;
height: 65px;
}
.tl-row {
position: relative;
height: 32px;
}
.tl-label {
position: absolute;
left: -37px;
top: 8px;
width: 25px;
color: var(--muted);
font-size: 11px;
font-weight: 850;
text-align: center;
}
.tl-line {
position: absolute;
top: 14px;
right: 0;
left: 0;
height: 2px;
border-radius: 2px;
background: rgba(32, 49, 46, 0.15);
}
.tl-dot {
--pulse: 0;
position: absolute;
top: 9px;
width: 12px;
height: 12px;
border: 2px solid var(--paper-solid);
border-radius: 3px;
background: var(--teal);
box-shadow:
0 0 0 rgba(233, 196, 106, 0),
0 0 calc(var(--pulse) * 12px) rgba(233, 196, 106, calc(var(--pulse) * 0.75));
transform: translateX(-50%) scale(calc(1 + var(--pulse) * 0.42));
}
.tl-dot.coral {
background: var(--coral);
}
.tl-dot.accent {
width: 15px;
height: 15px;
top: 7px;
background: var(--gold);
border-color: #fff9e9;
}
.tl-playhead {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 2px;
border-radius: 2px;
background: var(--gold-deep);
box-shadow: 0 0 10px rgba(233, 196, 106, 0.8);
transform: translateX(-1px);
pointer-events: none;
}
.tl-playhead::before {
content: "";
position: absolute;
top: -2px;
left: -4px;
width: 10px;
height: 6px;
clip-path: polygon(0 0, 100% 0, 50% 100%);
background: var(--gold-deep);
}
.timeline-foot {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.legend {
flex-wrap: wrap;
gap: 8px 13px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend-swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--teal);
}
.legend-swatch.coral {
background: var(--coral);
}
.legend-swatch.gold {
background: var(--gold);
box-shadow: 0 0 7px rgba(233, 196, 106, 0.65);
}
.check-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 13px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.check-row input {
width: 17px;
height: 17px;
accent-color: var(--gold-deep);
}
.anchor-row {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.anchor-pips {
display: flex;
gap: 4px;
min-height: 12px;
}
.anchor-pip {
width: 8px;
height: 8px;
border-radius: 2px;
background: rgba(185, 135, 33, 0.28);
}
.anchor-pip.newest {
background: var(--gold);
box-shadow: 0 0 8px rgba(233, 196, 106, 0.85);
}
.next-readout {
margin-top: 10px;
padding: 10px 11px;
border-radius: 10px;
background: rgba(32, 49, 46, 0.065);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.next-readout strong {
color: var(--ink);
}
.view-hint {
position: absolute;
left: 24px;
bottom: 22px;
display: flex;
gap: 9px;
align-items: center;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 999px;
background: rgba(248, 245, 235, 0.76);
color: var(--muted);
box-shadow: 0 7px 24px rgba(37, 53, 49, 0.12);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 700;
}
.view-hint button {
padding: 5px 8px;
border-radius: 999px;
background: rgba(32, 49, 46, 0.08);
color: var(--ink);
font-size: 10px;
font-weight: 750;
}
.view-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--gold);
}
@media (max-width: 850px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.title-card p {
display: none;
}
.console {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 15px;
}
.view-hint {
display: none;
}
}
@media (max-height: 720px) and (min-width: 851px) {
.console {
top: 12px;
right: 12px;
max-height: calc(100vh - 24px);
}
.title-card {
top: 12px;
left: 12px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel courtyard comparing three beats and two beats"></div>
<div class="hud">
<header class="title-card">
<div class="eyebrow">Voxel courtyard · rhythm study</div>
<h1>Three, then two</h1>
<p>
Two ways of grouping the same four-second cycle. Follow the colored
pulses, then watch the gold anchors return together at every seam.
</p>
</header>
<aside class="console" aria-label="Playback and comparison controls">
<div class="panel-row">
<div class="panel-title">Shared cycle clock</div>
<div class="live-badge">
<span class="live-dot"></span>
<span id="playState">Playing</span>
</div>
</div>
<section>
<div class="transport">
<button id="playButton" class="primary-button" type="button">Pause</button>
<button id="restartButton" class="secondary-button" type="button">Restart</button>
</div>
<div class="speed-header" style="margin-top: 14px;">
<label for="speed">Playback speed</label>
<output id="speedValue" for="speed">0.50×</output>
</div>
<input
id="speed"
type="range"
min="0.10"
max="1"
step="0.05"
value="0.50"
aria-label="Playback speed"
/>
<div class="speed-presets" aria-label="Playback speed presets">
<button type="button" data-speed="0.25">0.25×</button>
<button type="button" data-speed="0.50" class="active">0.50×</button>
<button type="button" data-speed="1">1.00×</button>
</div>
<div class="fact-grid">
<div class="fact">
<span>Meter</span>
<strong>3 groups / 2 groups</strong>
</div>
<div class="fact">
<span>Tempo · shared clock</span>
<strong id="tempoValue">7.5 cycles/min</strong>
</div>
<div class="fact">
<span>Current cycle</span>
<strong id="cycleValue">01</strong>
</div>
<div class="fact">
<span>Cycle clock</span>
<strong id="clockValue">0.00 / 4.00 s</strong>
</div>
</div>
<p class="explanation">
<strong>Meter</strong> changes what is counted: three pulses or two
pulses fill the same cycle. <strong>Tempo</strong> changes how fast
that shared cycle runs. The shorter pulse spacing in THREE is derived
from the meter, not a separate tempo control.
</p>
</section>
<section>
<div class="timeline-heading">
<div class="panel-title">One cycle, two groups</div>
<div id="spacingValue" style="color: var(--muted); font-size: 9px;">
0.67 s · 1.00 s pulse spacing
</div>
</div>
<div class="timeline">
<div class="timeline-plot">
<div class="tl-row">
<div class="tl-label">3</div>
<div class="tl-line"></div>
<span
class="tl-dot accent"
data-track="3"
data-index="0"
style="left: 0%;"
></span>
<span
class="tl-dot"
data-track="3"
data-index="1"
style="left: 33.333%;"
></span>
<span
class="tl-dot"
data-track="3"
data-index="2"
style="left: 66.667%;"
></span>
</div>
<div class="tl-row">
<div class="tl-label">2</div>
<div class="tl-line"></div>
<span
class="tl-dot accent coral"
data-track="2"
data-index="0"
style="left: 0%;"
></span>
<span
class="tl-dot coral"
data-track="2"
data-index="1"
style="left: 50%;"
></span>
</div>
<div id="timelinePlayhead" class="tl-playhead"></div>
</div>
<div class="timeline-foot">
<span>0 s</span>
<span>shared cycle</span>
<span>4 s</span>
</div>
</div>
<div class="legend">
<span class="legend-item">
<span class="legend-swatch"></span>
THREE regular pulse
</span>
<span class="legend-item">
<span class="legend-swatch coral"></span>
TWO regular pulse
</span>
<span class="legend-item">
<span class="legend-swatch gold"></span>
Accent / shared anchor
</span>
</div>
</section>
<section>
<label class="check-row">
<input id="pauseAtAnchor" type="checkbox" />
<span>Pause automatically at every shared anchor</span>
</label>
<div class="anchor-row">
<span>Recurring shared anchors</span>
<div id="anchorPips" class="anchor-pips" aria-hidden="true"></div>
</div>
<div id="nextReadout" class="next-readout" aria-live="polite">
<strong>Next:</strong> THREE regular pulse
</div>
</section>
</aside>
<div class="view-hint">
<span class="view-dot"></span>
<span>Drag to orbit · scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</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 stage = document.getElementById("stage");
const playButton = document.getElementById("playButton");
const restartButton = document.getElementById("restartButton");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const tempoValue = document.getElementById("tempoValue");
const cycleValue = document.getElementById("cycleValue");
const clockValue = document.getElementById("clockValue");
const spacingValue = document.getElementById("spacingValue");
const nextReadout = document.getElementById("nextReadout");
const playState = document.getElementById("playState");
const pauseAtAnchor = document.getElementById("pauseAtAnchor");
const anchorPips = document.getElementById("anchorPips");
const timelinePlayhead = document.getElementById("timelinePlayhead");
const resetViewButton = document.getElementById("resetView");
const CYCLE_DURATION = 4;
const START_X = -12;
const END_X = 12;
const EPSILON = 0.000001;
const COLORS = {
background: 0xd9e3dd,
ground: 0xb8c6bd,
stage: 0xcdbfa7,
sand: 0xe0d5bf,
sandAlt: 0xd4c7ae,
wall: 0xc7b99f,
wallLight: 0xded1b8,
wallDark: 0xa99b83,
teal: 0x2a9d8f,
tealLight: 0x79c9bd,
tealDark: 0x315b56,
coral: 0xe76f51,
coralLight: 0xf3aa91,
coralDark: 0x70443a,
gold: 0xe9c46a,
goldDeep: 0xb98721,
leaf: 0x648f68,
leafLight: 0x87aa79,
trunk: 0x80694f,
ink: 0x243a35
};
let elapsed = 0;
let playbackSpeed = Number(speedInput.value);
let playing = true;
let lastAnchorNumber = 0;
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(COLORS.background, 34, 64);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const initialView = {
azimuth: 0.73,
elevation: 0.54,
radius: 34
};
let cameraAzimuth = initialView.azimuth;
let cameraElevation = initialView.elevation;
let cameraRadius = initialView.radius;
function updateCamera() {
const horizontalRadius = Math.cos(cameraElevation) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraAzimuth) * horizontalRadius,
cameraTarget.y + Math.sin(cameraElevation) * cameraRadius,
cameraTarget.z + Math.cos(cameraAzimuth) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7df, 0x62766f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.1);
sun.position.set(-13, 24, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 21;
sun.shadow.camera.bottom = -19;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xc8e9e4, 1.0);
rimLight.position.set(15, 9, -15);
scene.add(rimLight);
const courtyard = new THREE.Group();
scene.add(courtyard);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
function addBox(
width,
height,
depth,
x,
y,
z,
material,
parent = courtyard
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const groundMaterial = standardMaterial(COLORS.ground);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 55),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.43;
ground.receiveShadow = true;
scene.add(ground);
const stageMaterial = standardMaterial(COLORS.stage);
addBox(31.2, 0.5, 17.2, 0, -0.04, 0, stageMaterial);
// Instanced voxel paving.
const tileGeometry = new THREE.BoxGeometry(1.46, 0.09, 1.46);
const tileMaterial = standardMaterial(0xffffff, { vertexColors: true });
const tileCount = 20 * 10;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
const tileDummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < 10; row++) {
for (let column = 0; column < 20; column++) {
tileDummy.position.set(
-14.25 + column * 1.5,
0.255,
-6.75 + row * 1.5
);
tileDummy.updateMatrix();
tiles.setMatrixAt(tileIndex, tileDummy.matrix);
const variation = (row + column) % 3;
tileColor.setHex(
variation === 0
? COLORS.sand
: variation === 1
? COLORS.sandAlt
: 0xd9ceb9
);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
courtyard.add(tiles);
// Voxel courtyard walls.
const wallMaterial = standardMaterial(COLORS.wall);
const wallLightMaterial = standardMaterial(COLORS.wallLight);
const wallDarkMaterial = standardMaterial(COLORS.wallDark);
addBox(10.9, 3.7, 0.72, -9.55, 1.84, -9.65, wallMaterial);
addBox(10.9, 3.7, 0.72, 9.55, 1.84, -9.65, wallMaterial);
addBox(7.9, 0.72, 0.82, 0, 4.11, -9.65, wallLightMaterial);
addBox(0.78, 4.45, 0.92, -3.7, 2.2, -9.65, wallDarkMaterial);
addBox(0.78, 4.45, 0.92, 3.7, 2.2, -9.65, wallDarkMaterial);
addBox(0.68, 2.35, 9.6, -15.25, 1.16, -4.75, wallMaterial);
addBox(0.68, 2.35, 9.6, 15.25, 1.16, -4.75, wallMaterial);
for (let x = -14; x <= 14; x += 2) {
addBox(1.25, 0.48, 0.9, x, 3.94, -9.65, wallLightMaterial);
}
for (let z = -8; z <= 0; z += 2) {
addBox(0.88, 0.46, 1.25, -15.25, 2.55, z, wallLightMaterial);
addBox(0.88, 0.46, 1.25, 15.25, 2.55, z, wallLightMaterial);
}
addBox(2.1, 3.4, 2.1, -14.15, 1.68, -8.65, wallDarkMaterial);
addBox(2.1, 3.4, 2.1, 14.15, 1.68, -8.65, wallDarkMaterial);
addBox(2.45, 0.52, 2.45, -14.15, 3.57, -8.65, wallLightMaterial);
addBox(2.45, 0.52, 2.45, 14.15, 3.57, -8.65, wallLightMaterial);
// Voxel planters and trees.
function addTree(x, z, scale = 1) {
const planterMaterial = standardMaterial(COLORS.wallDark);
const trunkMaterial = standardMaterial(COLORS.trunk);
const leafMaterial = standardMaterial(COLORS.leaf);
const leafLightMaterial = standardMaterial(COLORS.leafLight);
addBox(2.25 * scale, 0.5 * scale, 2.25 * scale,
x, 0.48 * scale, z, planterMaterial);
addBox(0.48 * scale, 2.1 * scale, 0.48 * scale,
x, 1.55 * scale, z, trunkMaterial);
addBox(1.7 * scale, 1.45 * scale, 1.7 * scale,
x, 2.72 * scale, z, leafMaterial);
addBox(1.25 * scale, 1.05 * scale, 1.3 * scale,
x - 0.65 * scale, 3.35 * scale, z + 0.2 * scale, leafLightMaterial);
addBox(1.05 * scale, 0.9 * scale, 1.05 * scale,
x + 0.6 * scale, 3.7 * scale, z - 0.15 * scale, leafMaterial);
addBox(1.05 * scale, 0.85 * scale, 1.05 * scale,
x + 0.25 * scale, 2.85 * scale, z - 0.8 * scale, leafLightMaterial);
}
addTree(-11.7, -7.25, 0.93);
addTree(11.7, -7.25, 0.93);
// Gate lanterns.
const lanternMaterial = standardMaterial(COLORS.gold, {
emissive: COLORS.gold,
emissiveIntensity: 1.8,
roughness: 0.45
});
for (const x of [-3.15, 3.15]) {
addBox(0.58, 0.78, 0.58, x, 2.45, -9.05, lanternMaterial);
addBox(0.82, 0.16, 0.82, x, 2.9, -9.05, wallDarkMaterial);
const light = new THREE.PointLight(COLORS.gold, 24, 8, 2);
light.position.set(x, 2.4, -8.5);
scene.add(light);
}
function makeTextSprite(title, subtitle, colorHex) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
roundedRect(context, 12, 18, 1000, 220, 28);
context.fillStyle = "rgba(28, 48, 44, 0.90)";
context.fill();
context.lineWidth = 8;
context.strokeStyle = `#${new THREE.Color(colorHex).getHexString()}`;
context.stroke();
context.fillStyle = `#${new THREE.Color(colorHex).getHexString()}`;
context.font = "800 64px system-ui, sans-serif";
context.fillText(title, 50, 104);
context.fillStyle = "rgba(245, 242, 226, 0.86)";
context.font = "700 28px system-ui, sans-serif";
context.fillText(subtitle, 53, 167);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: true
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(7.7, 1.925, 1);
return sprite;
}
const threeLabel = makeTextSprite(
"THREE",
"3 EQUAL BEATS / CYCLE",
COLORS.tealLight
);
threeLabel.position.set(-4.4, 3.08, -4.85);
courtyard.add(threeLabel);
const twoLabel = makeTextSprite(
"TWO",
"2 EQUAL BEATS / CYCLE",
COLORS.coralLight
);
twoLabel.position.set(6.1, 3.08, 4.85);
courtyard.add(twoLabel);
const seamLabel = makeTextSprite(
"CYCLE SEAM",
"THE SAME SHARED ANCHOR",
COLORS.gold
);
seamLabel.scale.set(5.8, 1.45, 1);
seamLabel.position.set(11.25, 3.35, 0);
courtyard.add(seamLabel);
const beats = [];
const tracks = [];
function createTrack({
name,
count,
z,
color,
lightColor,
darkColor,
phases
}) {
const track = {
name,
count,
z,
color,
lightColor,
darkColor,
phases,
beats: []
};
const baseMaterial = standardMaterial(darkColor);
addBox(25.3, 0.17, 3.0, 0, 0.43, z, baseMaterial);
for (let segment = 0; segment < 12; segment++) {
const segmentMaterial = standardMaterial(
segment % 2 === 0 ? darkColor : color,
{ roughness: 0.9 }
);
addBox(
1.98,
0.065,
2.72,
-11 + segment * 2,
0.545,
z,
segmentMaterial
);
}
addBox(25.3, 0.08, 0.12, 0, 0.59, z - 1.42, lightColor);
addBox(25.3, 0.08, 0.12, 0, 0.59, z + 1.42, lightColor);
phases.forEach((phase, index) => {
const x = THREE.MathUtils.lerp(START_X, END_X, phase);
const isAccent = index === 0;
const beatGroup = new THREE.Group();
beatGroup.position.set(x, 0.6, z);
courtyard.add(beatGroup);
const baseMaterial = standardMaterial(
isAccent ? color : darkColor
);
addBox(2.55, 0.23, 2.55, 0, 0.11, 0, baseMaterial, beatGroup);
const pulseGroup = new THREE.Group();
pulseGroup.position.y = 0.22;
beatGroup.add(pulseGroup);
const stemMaterial = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.62
});
const stem = addBox(
0.82,
1.25,
0.82,
0,
0.625,
0,
stemMaterial,
pulseGroup
);
const capMaterial = standardMaterial(
isAccent ? COLORS.gold : lightColor,
{
emissive: isAccent ? COLORS.gold : lightColor,
emissiveIntensity: isAccent ? 0.55 : 0.12,
roughness: 0.45
}
);
const cap = addBox(
1.05,
0.23,
1.05,
0,
1.36,
0,
capMaterial,
pulseGroup
);
const haloMaterial = new THREE.MeshBasicMaterial({
color: isAccent ? COLORS.gold : lightColor,
transparent: true,
opacity: 0.07,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const halo = new THREE.Group();
beatGroup.add(halo);
addBox(3.1, 0.035, 0.12, 0, 0.015, -1.38, haloMaterial, halo);
addBox(3.1, 0.035, 0.12, 0, 0.015, 1.38, haloMaterial, halo);
addBox(0.12, 0.035, 2.64, -1.44, 0.015, 0, haloMaterial, halo);
addBox(0.12, 0.035, 2.64, 1.44, 0.015, 0, haloMaterial, halo);
let accentBeam = null;
if (isAccent) {
const beamMaterial = new THREE.MeshBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
accentBeam = addBox(
0.12,
3.25,
0.12,
0,
2.35,
0,
beamMaterial,
pulseGroup
);
}
const beat = {
index,
phase,
group: beatGroup,
pulseGroup,
stem,
stemMaterial,
cap,
capMaterial,
halo,
haloMaterial,
accentBeam,
isAccent
};
track.beats.push(beat);
beats.push(beat);
});
tracks.push(track);
return track;
}
createTrack({
name: "THREE",
count: 3,
z: -3.18,
color: COLORS.teal,
lightColor: COLORS.tealLight,
darkColor: COLORS.tealDark,
phases: [0, 1 / 3, 2 / 3]
});
createTrack({
name: "TWO",
count: 2,
z: 3.18,
color: COLORS.coral,
lightColor: COLORS.coralLight,
darkColor: COLORS.coralDark,
phases: [0, 1 / 2]
});
function makeAlignmentBridge(x) {
const material = new THREE.MeshBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.05,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const bridge = addBox(0.095, 0.095, 6.35, x, 2.63, 0, material);
addBox(0.11, 2.55, 0.11, x, 1.72, -3.18, material);
addBox(0.11, 2.55, 0.11, x, 1.72, 3.18, material);
const floorMaterial = new THREE.MeshBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.08,
depthWrite: false
});
addBox(0.2, 0.04, 3.0, x, 0.625, -3.18, floorMaterial);
addBox(0.2, 0.04, 3.0, x, 0.625, 3.18, floorMaterial);
return { bridge, material };
}
const startAlignment = makeAlignmentBridge(START_X);
const endAlignment = makeAlignmentBridge(END_X);
const playheadGroup = new THREE.Group();
courtyard.add(playheadGroup);
const playheadMaterial = new THREE.MeshBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.72,
depthWrite: false,
blending: THREE.AdditiveBlending
});
addBox(0.075, 4.25, 0.075, 0, 2.55, 0, playheadMaterial, playheadGroup);
addBox(0.42, 0.42, 0.42, 0, 4.78, 0, playheadMaterial, playheadGroup);
addBox(0.07, 0.07, 8.05, 0, 0.67, 0, playheadMaterial, playheadGroup);
// Custom orbit controls, implemented directly without addons.
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const points = [...pointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraAzimuth -= dx * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + dy * 0.0045,
0.25,
1.15
);
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
22,
48
);
}
previousPinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.025,
22,
48
);
},
{ passive: false }
);
resetViewButton.addEventListener("click", () => {
cameraAzimuth = initialView.azimuth;
cameraElevation = initialView.elevation;
cameraRadius = initialView.radius;
});
function updatePlayButton() {
playButton.textContent = playing ? "Pause" : "Play";
playState.textContent = playing ? "Playing" : "Paused";
}
playButton.addEventListener("click", () => {
playing = !playing;
updatePlayButton();
});
restartButton.addEventListener("click", () => {
elapsed = 0;
lastAnchorNumber = 0;
playing = true;
updatePlayButton();
updateAnchorPips(1);
});
function setSpeed(value) {
playbackSpeed = Number(value);
speedInput.value = String(playbackSpeed);
speedValue.textContent = `${playbackSpeed.toFixed(2)}×`;
const sliderMin = Number(speedInput.min);
const sliderMax = Number(speedInput.max);
const fill = ((playbackSpeed - sliderMin) / (sliderMax - sliderMin)) * 100;
speedInput.style.setProperty("--speed-fill", `${fill}%`);
document.querySelectorAll("[data-speed]").forEach((button) => {
button.classList.toggle(
"active",
Math.abs(Number(button.dataset.speed) - playbackSpeed) < 0.001
);
});
}
speedInput.addEventListener("input", () => setSpeed(speedInput.value));
document.querySelectorAll("[data-speed]").forEach((button) => {
button.addEventListener("click", () => setSpeed(button.dataset.speed));
});
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (event.code === "Space" && tag !== "INPUT" && tag !== "BUTTON") {
event.preventDefault();
playing = !playing;
updatePlayButton();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function updateAnchorPips(anchorNumber) {
anchorPips.replaceChildren();
const firstVisible = Math.max(1, anchorNumber - 11);
for (let number = firstVisible; number <= anchorNumber; number++) {
const pip = document.createElement("span");
pip.className = "anchor-pip";
pip.title = `Shared anchor ${number}`;
if (number === anchorNumber) {
pip.classList.add("newest");
}
anchorPips.appendChild(pip);
}
}
const timelineDots = [...document.querySelectorAll(".tl-dot")];
function updateTimeline() {
const phase = (elapsed % CYCLE_DURATION) / CYCLE_DURATION;
timelinePlayhead.style.left = `${phase * 100}%`;
for (const track of tracks) {
const interval = CYCLE_DURATION / track.count;
const eventIndex = Math.floor((elapsed + EPSILON) / interval);
const eventTime = eventIndex * interval;
const age = Math.max(0, elapsed - eventTime);
const pulse = Math.exp(-age * 5.2);
for (const dot of timelineDots) {
if (Number(dot.dataset.track) !== track.count) continue;
const dotIndex = Number(dot.dataset.index);
const active = eventIndex % track.count === dotIndex;
dot.style.setProperty("--pulse", active ? pulse.toFixed(4) : "0");
}
}
}
function updateNextEvent() {
const threeInterval = CYCLE_DURATION / 3;
const twoInterval = CYCLE_DURATION / 2;
const threeIndex = Math.floor((elapsed + EPSILON) / threeInterval) + 1;
const twoIndex = Math.floor((elapsed + EPSILON) / twoInterval) + 1;
const cycleIndex = Math.floor((elapsed + EPSILON) / CYCLE_DURATION) + 1;
const candidates = [
{
time: threeIndex * threeInterval,
label:
threeIndex % 3 === 0
? "THREE cycle accent"
: `THREE regular pulse ${threeIndex % 3}`
},
{
time: twoIndex * twoInterval,
label:
twoIndex % 2 === 0
? "TWO cycle accent"
: "TWO regular pulse"
},
{
time: cycleIndex * CYCLE_DURATION,
label: "Shared cycle anchor"
}
];
candidates.sort((a, b) => a.time - b.time);
const next = candidates[0];
const realSeconds = Math.max(0, (next.time - elapsed) / playbackSpeed);
nextReadout.innerHTML =
`<strong>Next:</strong> ${next.label} in ` +
`${realSeconds.toFixed(1)} real second${realSeconds === 1 ? "" : "s"}`;
}
function updateScene() {
const phase = (elapsed % CYCLE_DURATION) / CYCLE_DURATION;
playheadGroup.position.x = THREE.MathUtils.lerp(START_X, END_X, phase);
for (const track of tracks) {
const interval = CYCLE_DURATION / track.count;
const eventIndex = Math.floor((elapsed + EPSILON) / interval);
const eventTime = eventIndex * interval;
const age = Math.max(0, elapsed - eventTime);
for (const beat of track.beats) {
const matchingBeat = eventIndex % track.count === beat.index;
const rawPulse = matchingBeat ? Math.exp(-age * 5.2) : 0;
const pulse = beat.isAccent ? rawPulse * 1.18 : rawPulse;
beat.pulseGroup.scale.y = 1 + pulse * 0.25;
beat.stemMaterial.emissiveIntensity = 0.12 + pulse * 1.9;
beat.capMaterial.emissiveIntensity =
(beat.isAccent ? 0.55 : 0.12) + pulse * 2.5;
beat.haloMaterial.opacity = 0.055 + pulse * 0.68;
beat.halo.scale.setScalar(1 + pulse * 0.34);
if (beat.accentBeam) {
beat.accentBeam.material.opacity = pulse * 0.58;
beat.accentBeam.visible = pulse > 0.015;
}
}
}
const cycleIndex = Math.floor((elapsed + EPSILON) / CYCLE_DURATION);
const cycleEventTime = cycleIndex * CYCLE_DURATION;
const alignmentAge = Math.max(0, elapsed - cycleEventTime);
const alignmentPulse = Math.exp(-alignmentAge * 4.8);
const cyclePhase = elapsed % CYCLE_DURATION;
const timeToSeam = CYCLE_DURATION - cyclePhase;
const seamPulse = Math.exp(-timeToSeam * 3.15);
startAlignment.material.opacity = 0.045 + alignmentPulse * 0.8;
endAlignment.material.opacity = 0.035 + seamPulse * 0.72;
playheadMaterial.opacity = 0.62 + alignmentPulse * 0.2;
}
function updateReadouts() {
const anchorNumber = Math.floor((elapsed + EPSILON) / CYCLE_DURATION) + 1;
const cycleClock = elapsed % CYCLE_DURATION;
cycleValue.textContent = String(anchorNumber).padStart(2, "0");
clockValue.textContent = `${cycleClock.toFixed(2)} / 4.00 s`;
tempoValue.textContent = `${(15 * playbackSpeed).toFixed(1)} cycles/min`;
const threeSpacing = (CYCLE_DURATION / 3) / playbackSpeed;
const twoSpacing = (CYCLE_DURATION / 2) / playbackSpeed;
spacingValue.textContent =
`${threeSpacing.toFixed(2)} s · ${twoSpacing.toFixed(2)} s pulse spacing`;
if (anchorNumber !== lastAnchorNumber) {
lastAnchorNumber = anchorNumber;
updateAnchorPips(anchorNumber);
}
}
setSpeed(playbackSpeed);
updatePlayButton();
updateAnchorPips(1);
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
const previousElapsed = elapsed;
const previousCycle = Math.floor((previousElapsed + EPSILON) / CYCLE_DURATION);
elapsed += delta * playbackSpeed;
const currentCycle = Math.floor((elapsed + EPSILON) / CYCLE_DURATION);
if (currentCycle > previousCycle) {
if (pauseAtAnchor.checked) {
elapsed = currentCycle * CYCLE_DURATION;
playing = false;
updatePlayButton();
}
}
}
updateScene();
updateTimeline();
updateReadouts();
updateNextEvent();
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```