Prompt specification
Build or customize the Three.js 3D scene "Build a Rondo With Stage Islands" 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: Build a Rondo With Stage Islands
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/build-a-rondo-with-stage-islands-x3316
Scene Description Prompt:
Make a low-poly rondo builder in one HTML file using Three.js from cdnjs: arrange stage islands into recurring and contrasting sections with animated transitions.
Working Three.js Starter (build-a-rondo-with-stage-islands-x3316):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rondo — Low-Poly Stage Builder</title>
<style>
:root {
--paper: #eee9de;
--panel: rgba(250, 248, 242, 0.91);
--ink: #20262d;
--muted: #71757a;
--line: rgba(32, 38, 45, 0.13);
--coral: #eb6a4a;
--blue: #4563cf;
--gold: #d59a2d;
--violet: #8461b3;
--shadow: 0 18px 60px rgba(37, 42, 48, 0.14);
}
* {
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;
}
button {
font: inherit;
}
button:focus-visible,
[tabindex]:focus-visible {
outline: 2px solid var(--coral);
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.grain {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
opacity: 0.17;
background:
repeating-radial-gradient(
circle at 12% 18%,
rgba(26, 31, 38, 0.08) 0 0.6px,
transparent 0.8px 4px
);
mix-blend-mode: multiply;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 72px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--line);
background: rgba(238, 233, 222, 0.72);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-symbol {
width: 35px;
height: 35px;
position: relative;
transform: rotate(45deg);
border: 1px solid var(--ink);
}
.brand-symbol::before,
.brand-symbol::after {
content: "";
position: absolute;
background: var(--ink);
}
.brand-symbol::before {
width: 1px;
height: 46px;
left: 16px;
top: -6px;
}
.brand-symbol::after {
width: 46px;
height: 1px;
top: 16px;
left: -6px;
}
.brand-copy {
display: flex;
align-items: baseline;
gap: 9px;
}
.brand-copy strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 500;
letter-spacing: -0.04em;
}
.brand-copy span {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
}
.action-button {
height: 38px;
padding: 0 15px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.34);
border: 1px solid var(--line);
border-radius: 999px;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.action-button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.72);
border-color: rgba(32, 38, 45, 0.28);
}
.action-button.primary {
min-width: 102px;
color: #fffaf1;
background: var(--ink);
border-color: var(--ink);
}
.action-button.primary:hover {
background: #343b43;
}
.action-button.primary .play-icon {
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid currentColor;
}
body.playing .action-button.primary .play-icon {
width: 8px;
height: 10px;
border: 0;
border-left: 3px solid currentColor;
border-right: 3px solid currentColor;
}
.builder {
position: fixed;
z-index: 8;
top: 92px;
left: 24px;
bottom: 24px;
width: 326px;
padding: 22px;
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
scrollbar-width: thin;
scrollbar-color: rgba(32, 38, 45, 0.18) transparent;
}
.eyebrow {
margin: 0 0 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.builder h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 34px;
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro {
margin: 13px 0 22px;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.section-heading {
margin: 20px 0 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.section-heading h2 {
margin: 0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-heading span {
color: var(--muted);
font-size: 10px;
}
.palette {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.motif-card {
min-height: 76px;
padding: 11px;
display: grid;
grid-template-columns: 26px 1fr;
grid-template-rows: 1fr auto;
gap: 4px 8px;
text-align: left;
color: var(--ink);
background: rgba(255, 255, 255, 0.46);
border: 1px solid var(--line);
border-radius: 12px;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.motif-card:hover {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 8px 20px rgba(32, 38, 45, 0.08);
}
.motif-swatch {
width: 24px;
height: 24px;
display: grid;
place-items: center;
grid-row: 1 / span 2;
color: white;
background: var(--motif);
border-radius: 7px;
font-family: Georgia, serif;
font-size: 14px;
}
.motif-card strong {
align-self: end;
font-size: 11px;
font-weight: 750;
}
.motif-card small {
color: var(--muted);
font-size: 9px;
}
.sequence {
min-height: 73px;
padding: 9px;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
gap: 6px;
border: 1px dashed rgba(32, 38, 45, 0.19);
border-radius: 13px;
background: rgba(255, 255, 255, 0.25);
}
.sequence-chip {
position: relative;
height: 32px;
padding: 0 8px 0 6px;
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--ink);
background: white;
border: 1px solid var(--line);
border-radius: 9px;
cursor: grab;
user-select: none;
transition:
transform 150ms ease,
border-color 150ms ease,
box-shadow 150ms ease;
}
.sequence-chip:hover {
transform: translateY(-1px);
border-color: rgba(32, 38, 45, 0.3);
}
.sequence-chip.active {
border-color: var(--chip-color);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--chip-color) 22%, transparent);
}
.sequence-chip.dragging {
opacity: 0.4;
cursor: grabbing;
}
.chip-letter {
width: 21px;
height: 21px;
display: grid;
place-items: center;
color: white;
background: var(--chip-color);
border-radius: 6px;
font-family: Georgia, serif;
font-size: 12px;
}
.chip-name {
max-width: 61px;
overflow: hidden;
font-size: 9px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.remove-chip {
width: 15px;
height: 18px;
padding: 0;
color: #9a9da0;
background: transparent;
border: 0;
cursor: pointer;
font-size: 15px;
line-height: 1;
}
.remove-chip:hover {
color: var(--coral);
}
.sequence-help {
margin: 8px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.preset-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.preset {
min-height: 32px;
padding: 6px;
color: var(--muted);
background: transparent;
border: 1px solid var(--line);
border-radius: 9px;
cursor: pointer;
font-size: 9px;
font-weight: 700;
transition: background 150ms ease, color 150ms ease;
}
.preset:hover {
color: var(--ink);
background: rgba(255, 255, 255, 0.65);
}
.builder-actions {
margin-top: 9px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.builder-actions button {
min-height: 34px;
color: var(--ink);
background: rgba(255, 255, 255, 0.38);
border: 1px solid var(--line);
border-radius: 9px;
cursor: pointer;
font-size: 9px;
font-weight: 750;
}
.builder-actions button:hover {
background: white;
}
.legend {
margin-top: 21px;
padding-top: 17px;
display: flex;
justify-content: space-between;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 8px;
line-height: 1.5;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 7px;
height: 7px;
background: var(--coral);
border-radius: 50%;
}
.legend-dot.contrast {
background: var(--blue);
border-radius: 1px;
transform: rotate(45deg);
}
.now-card {
position: fixed;
z-index: 6;
top: 92px;
right: 24px;
width: 235px;
padding: 19px;
color: #f5f1e7;
background: rgba(31, 37, 44, 0.94);
border-radius: 18px;
box-shadow: var(--shadow);
overflow: hidden;
}
.now-card::after {
content: "";
position: absolute;
width: 110px;
height: 110px;
right: -49px;
top: -49px;
background: var(--now-color, var(--coral));
border-radius: 50%;
opacity: 0.2;
}
.now-card .eyebrow {
color: rgba(255, 255, 255, 0.47);
}
.now-content {
display: grid;
grid-template-columns: 42px 1fr;
gap: 12px;
align-items: center;
}
.section-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
color: white;
background: var(--now-color, var(--coral));
border-radius: 12px;
font-family: Georgia, serif;
font-size: 22px;
}
.now-card h2 {
margin: 0;
font-family: Georgia, serif;
font-size: 24px;
font-weight: 400;
letter-spacing: -0.03em;
}
.now-card p {
margin: 14px 0 0;
color: rgba(255, 255, 255, 0.6);
font-size: 10px;
line-height: 1.6;
}
.now-meta {
margin-top: 16px;
padding-top: 13px;
display: flex;
justify-content: space-between;
border-top: 1px solid rgba(255, 255, 255, 0.12);
color: rgba(255, 255, 255, 0.45);
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.timeline-wrap {
position: fixed;
z-index: 6;
left: 375px;
right: 280px;
bottom: 25px;
padding: 13px 17px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 16px;
background: rgba(250, 248, 242, 0.78);
box-shadow: 0 12px 36px rgba(37, 42, 48, 0.08);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.timeline-top {
margin-bottom: 9px;
display: flex;
align-items: center;
justify-content: space-between;
}
.timeline-title {
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.form-marks {
display: flex;
gap: 4px;
}
.form-mark {
width: 18px;
height: 18px;
display: grid;
place-items: center;
color: var(--muted);
background: rgba(32, 38, 45, 0.06);
border-radius: 5px;
font-family: Georgia, serif;
font-size: 9px;
transition: background 200ms ease, color 200ms ease;
}
.form-mark.active {
color: white;
background: var(--ink);
}
.progress-track {
height: 3px;
overflow: hidden;
background: rgba(32, 38, 45, 0.1);
border-radius: 999px;
}
.progress-fill {
width: 100%;
height: 100%;
background: var(--coral);
border-radius: inherit;
transform: scaleX(0);
transform-origin: left;
}
.view-tools {
position: fixed;
z-index: 7;
right: 24px;
bottom: 25px;
display: flex;
gap: 5px;
}
.view-tools button {
width: 36px;
height: 36px;
display: grid;
place-items: center;
color: var(--ink);
background: rgba(250, 248, 242, 0.8);
border: 1px solid rgba(32, 38, 45, 0.13);
border-radius: 11px;
box-shadow: 0 8px 24px rgba(37, 42, 48, 0.08);
cursor: pointer;
font-size: 16px;
}
.view-tools button:hover {
background: white;
}
.hover-label {
position: fixed;
z-index: 9;
padding: 7px 10px;
color: white;
background: rgba(31, 37, 44, 0.9);
border-radius: 8px;
pointer-events: none;
opacity: 0;
transform: translate(12px, 12px);
transition: opacity 120ms ease;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.hover-label.visible {
opacity: 1;
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
top: 87px;
padding: 10px 15px;
color: white;
background: rgba(31, 37, 44, 0.92);
border-radius: 999px;
box-shadow: var(--shadow);
pointer-events: none;
opacity: 0;
transform: translate(-50%, -8px);
transition: opacity 180ms ease, transform 180ms ease;
font-size: 10px;
font-weight: 700;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-inner {
text-align: center;
}
.loading-shape {
width: 46px;
height: 46px;
margin: 0 auto 16px;
background: var(--coral);
clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
animation: turn 1.5s ease-in-out infinite;
}
.loading strong {
display: block;
font-family: Georgia, serif;
font-size: 22px;
font-weight: 400;
}
.loading small {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@keyframes turn {
50% {
transform: rotate(90deg) scale(0.7);
}
100% {
transform: rotate(180deg);
}
}
@media (max-width: 1100px) {
.now-card {
display: none;
}
.timeline-wrap {
right: 80px;
}
}
@media (max-width: 760px) {
.topbar {
height: 62px;
padding: 0 13px;
}
.brand-copy span,
#soundButton {
display: none;
}
.brand-copy strong {
font-size: 22px;
}
.action-button {
height: 35px;
padding: 0 12px;
}
.builder {
top: auto;
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
max-height: 45vh;
padding: 18px;
border-radius: 18px;
}
.builder h1 {
font-size: 28px;
}
.intro {
margin-bottom: 14px;
}
.palette {
grid-template-columns: repeat(4, 1fr);
}
.motif-card {
min-height: 58px;
padding: 8px;
grid-template-columns: 22px 1fr;
}
.motif-card strong {
font-size: 9px;
}
.motif-card small {
display: none;
}
.motif-swatch {
width: 21px;
height: 21px;
}
.timeline-wrap {
left: 12px;
right: 12px;
bottom: calc(45vh + 22px);
padding: 10px 13px;
}
.view-tools {
right: 12px;
bottom: calc(45vh + 22px);
}
.view-tools button {
width: 32px;
height: 32px;
}
.toast {
top: 72px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly rondo stage"></canvas>
<div class="grain"></div>
<header class="topbar">
<div class="brand">
<div class="brand-symbol" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Rondo</strong>
<span>Stage form builder</span>
</div>
</div>
<div class="top-actions">
<button class="action-button" id="soundButton" aria-pressed="false">
<span aria-hidden="true">♪</span>
<span id="soundLabel">Sound off</span>
</button>
<button class="action-button" id="playButton">
<span class="play-icon" aria-hidden="true"></span>
<span id="playLabel">Play form</span>
</button>
</div>
</header>
<aside class="builder" aria-label="Rondo sequence builder">
<p class="eyebrow">Sequence composer</p>
<h1>Shape the refrain.</h1>
<p class="intro">
Build a recurring musical form. Return sections keep the same stage;
contrasting sections rearrange the islands.
</p>
<div class="section-heading">
<h2>Add a section</h2>
<span>Choose a motif</span>
</div>
<div class="palette">
<button class="motif-card" data-motif="A" style="--motif: var(--coral)">
<span class="motif-swatch">A</span>
<strong>Return</strong>
<small>Recurring motif</small>
</button>
<button class="motif-card" data-motif="B" style="--motif: var(--blue)">
<span class="motif-swatch">B</span>
<strong>Tide</strong>
<small>Contrasting motif</small>
</button>
<button class="motif-card" data-motif="C" style="--motif: var(--gold)">
<span class="motif-swatch">C</span>
<strong>Afterglow</strong>
<small>Contrasting motif</small>
</button>
<button class="motif-card" data-motif="D" style="--motif: var(--violet)">
<span class="motif-swatch">D</span>
<strong>Mirage</strong>
<small>Contrasting motif</small>
</button>
</div>
<div class="section-heading">
<h2>Your form</h2>
<span id="sectionCount">5 sections</span>
</div>
<div id="sequence" class="sequence" aria-label="Current rondo sequence"></div>
<p class="sequence-help">Drag chips to reorder. Select one to visit its stage.</p>
<div class="section-heading">
<h2>Form presets</h2>
<span>One-click structures</span>
</div>
<div class="preset-row">
<button class="preset" data-preset="classic">Classic</button>
<button class="preset" data-preset="expanded">Expanded</button>
<button class="preset" data-preset="minimal">Minimal</button>
</div>
<div class="builder-actions">
<button id="balanceButton">Balance A returns</button>
<button id="clearButton">Clear form</button>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-dot"></span>
<span>Recurring<br />unchanged stage</span>
</div>
<div class="legend-item">
<span class="legend-dot contrast"></span>
<span>Contrasting<br />new arrangement</span>
</div>
</div>
</aside>
<section id="nowCard" class="now-card" aria-live="polite">
<p id="nowEyebrow" class="eyebrow">Section 01 / 05</p>
<div class="now-content">
<div id="nowLetter" class="section-mark">A</div>
<div>
<h2 id="nowName">Return</h2>
<span id="nowKind" class="eyebrow" style="margin: 0">Recurring motif</span>
</div>
</div>
<p id="nowDescription"></p>
<div class="now-meta">
<span id="nowPosition">Beginning</span>
<span id="nowShape">Triangle stage</span>
</div>
</section>
<section class="timeline-wrap" aria-label="Playback timeline">
<div class="timeline-top">
<span class="timeline-title">Rondo timeline</span>
<div id="formMarks" class="form-marks"></div>
</div>
<div class="progress-track">
<div id="progressFill" class="progress-fill"></div>
</div>
</section>
<div class="view-tools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetCamera" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div id="hoverLabel" class="hover-label"></div>
<div id="toast" class="toast"></div>
<div id="loading" class="loading">
<div class="loading-inner">
<div class="loading-shape"></div>
<strong>Rondo</strong>
<small>Assembling the stage</small>
</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 $ = (selector) => document.querySelector(selector);
const motifs = {
A: {
key: "A",
name: "Return",
kind: "recurring",
color: 0xeb6a4a,
accent: 0xffc857,
css: "#eb6a4a",
shape: "Triangle stage",
description:
"A compact three-island chorus. Every return reproduces the same warm, familiar silhouette.",
notes: [261.63, 329.63, 392.0]
},
B: {
key: "B",
name: "Tide",
kind: "contrasting",
color: 0x4563cf,
accent: 0xa9d5ef,
css: "#4563cf",
shape: "Split stage",
description:
"Two distant islands stretch the form apart, joined by a cool architectural gate.",
notes: [220.0, 277.18, 329.63]
},
C: {
key: "C",
name: "Afterglow",
kind: "contrasting",
color: 0xd59a2d,
accent: 0xffdf82,
css: "#d59a2d",
shape: "Five-island ring",
description:
"Five smaller platforms orbit a golden center, creating a brighter, more expansive contrast.",
notes: [293.66, 369.99, 440.0]
},
D: {
key: "D",
name: "Mirage",
kind: "contrasting",
color: 0x8461b3,
accent: 0xe5b4db,
css: "#8461b3",
shape: "Crescent stage",
description:
"A crescent of slender towers introduces a suspended, dreamlike counter-motif.",
notes: [196.0, 246.94, 293.66]
}
};
let sequence = ["A", "B", "A", "C", "A"];
let currentIndex = 0;
let currentSection = "A";
let currentGroup = null;
let transition = null;
let playing = false;
let playElapsed = 0;
let soundEnabled = false;
let audioContext = null;
let masterGain = null;
let dragIndex = null;
let toastTimer = null;
const SECTION_DURATION = 4.2;
// ── Three.js scene ────────────────────────────────────────────────
const canvas = $("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9de);
scene.fog = new THREE.Fog(0xeee9de, 23, 58);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xfff7e5, 0x718096, 2.35);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff3d8, 3.15);
sunlight.position.set(-7, 14, 10);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -16;
sunlight.shadow.camera.right = 16;
sunlight.shadow.camera.top = 16;
sunlight.shadow.camera.bottom = -16;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 45;
sunlight.shadow.bias = -0.0006;
scene.add(sunlight);
const rimLight = new THREE.DirectionalLight(0xaac9ff, 1.2);
rimLight.position.set(10, 7, -12);
scene.add(rimLight);
const stageRoot = new THREE.Group();
scene.add(stageRoot);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0xe8e1d5,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -4.2;
ground.receiveShadow = true;
scene.add(ground);
[
{ radius: 7.2, color: 0xc2b8a8, opacity: 0.24 },
{ radius: 10.8, color: 0xb4aa9b, opacity: 0.17 },
{ radius: 15.0, color: 0xa69d91, opacity: 0.12 }
].forEach(({ radius, color, opacity }) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.018, 3, 128),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -4.13;
scene.add(ring);
});
const particleGeometry = new THREE.BufferGeometry();
const particlePositions = new Float32Array(420 * 3);
for (let i = 0; i < 420; i++) {
const radius = 8 + Math.random() * 20;
const angle = Math.random() * Math.PI * 2;
particlePositions[i * 3] = Math.cos(angle) * radius;
particlePositions[i * 3 + 1] = -1 + Math.random() * 13;
particlePositions[i * 3 + 2] = Math.sin(angle) * radius;
}
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x5f6671,
size: 0.045,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
scene.add(particles);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xeb6a4a,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const pulse = new THREE.Mesh(
new THREE.RingGeometry(1, 1.035, 72),
pulseMaterial
);
pulse.rotation.x = -Math.PI / 2;
pulse.position.y = -4.08;
pulse.visible = false;
scene.add(pulse);
// ── Direct camera controls ────────────────────────────────────────
const desiredCamera = {
azimuth: 0.62,
polar: 1.02,
distance: 18.5,
target: new THREE.Vector3(0, -0.25, 0)
};
const actualCamera = {
azimuth: desiredCamera.azimuth,
polar: desiredCamera.polar,
distance: desiredCamera.distance,
target: desiredCamera.target.clone()
};
function resetCamera() {
desiredCamera.azimuth = 0.62;
desiredCamera.polar = 1.02;
desiredCamera.distance = 18.5;
desiredCamera.target.set(0, -0.25, 0);
}
function updateCamera() {
actualCamera.azimuth = THREE.MathUtils.lerp(
actualCamera.azimuth,
desiredCamera.azimuth,
0.1
);
actualCamera.polar = THREE.MathUtils.lerp(
actualCamera.polar,
desiredCamera.polar,
0.1
);
actualCamera.distance = THREE.MathUtils.lerp(
actualCamera.distance,
desiredCamera.distance,
0.1
);
actualCamera.target.lerp(desiredCamera.target, 0.1);
const spherical = new THREE.Spherical(
actualCamera.distance,
actualCamera.polar,
actualCamera.azimuth
);
camera.position.setFromSpherical(spherical).add(actualCamera.target);
camera.lookAt(actualCamera.target);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let pointerMode = "orbit";
let primaryPointer = null;
let downPosition = { x: 0, y: 0 };
let lastPosition = { x: 0, y: 0 };
let dragged = false;
let pinchDistance = 0;
let pinchMidpoint = { x: 0, y: 0 };
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pointerDistance() {
const values = [...activePointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function pointerMidpoint() {
const values = [...activePointers.values()];
if (values.length < 2) return { x: 0, y: 0 };
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
function panCamera(dx, dy) {
const forward = new THREE.Vector3()
.subVectors(actualCamera.target, camera.position)
.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = actualCamera.distance * 0.00135;
desiredCamera.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
desiredCamera.target.x = THREE.MathUtils.clamp(
desiredCamera.target.x,
-7,
7
);
desiredCamera.target.z = THREE.MathUtils.clamp(
desiredCamera.target.z,
-7,
7
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
primaryPointer = event.pointerId;
pointerMode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
downPosition = { x: event.clientX, y: event.clientY };
lastPosition = { ...downPosition };
dragged = false;
} else if (activePointers.size === 2) {
pointerMode = "pinch";
pinchDistance = pointerDistance();
pinchMidpoint = pointerMidpoint();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) {
updateHover(event);
return;
}
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointerMode === "pinch" && activePointers.size >= 2) {
const distance = pointerDistance();
const midpoint = pointerMidpoint();
if (pinchDistance > 0 && distance > 0) {
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * (pinchDistance / distance),
9,
30
);
}
panCamera(
midpoint.x - pinchMidpoint.x,
midpoint.y - pinchMidpoint.y
);
pinchDistance = distance;
pinchMidpoint = midpoint;
dragged = true;
return;
}
if (event.pointerId !== primaryPointer) return;
const dx = event.clientX - lastPosition.x;
const dy = event.clientY - lastPosition.y;
lastPosition = { x: event.clientX, y: event.clientY };
if (
Math.hypot(
event.clientX - downPosition.x,
event.clientY - downPosition.y
) > 4
) {
dragged = true;
}
if (pointerMode === "pan") {
panCamera(dx, dy);
} else {
desiredCamera.azimuth -= dx * 0.006;
desiredCamera.polar = THREE.MathUtils.clamp(
desiredCamera.polar + dy * 0.004,
0.38,
1.36
);
}
hideHover();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 1) {
const [id, position] = activePointers.entries().next().value;
primaryPointer = id;
pointerMode = "orbit";
lastPosition = { ...position };
} else if (activePointers.size === 0) {
primaryPointer = null;
pointerMode = "orbit";
}
}
canvas.addEventListener("pointerup", (event) => {
if (!dragged) {
pickIsland(event);
}
releasePointer(event);
});
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("pointerleave", hideHover);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * Math.exp(event.deltaY * 0.001),
9,
30
);
},
{ passive: false }
);
$("#zoomIn").addEventListener("click", () => {
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance - 1.4,
9,
30
);
});
$("#zoomOut").addEventListener("click", () => {
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance + 1.4,
9,
30
);
});
$("#resetCamera").addEventListener("click", resetCamera);
// ── Procedural low-poly stage islands ─────────────────────────────
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
function markIsland(object, island) {
object.userData.island = island;
object.castShadow = true;
object.receiveShadow = true;
}
function makeIsland(key, index) {
const motif = motifs[key];
const island = new THREE.Group();
const darkColor = new THREE.Color(motif.color).multiplyScalar(0.68);
const baseMaterial = standardMaterial(darkColor);
const platformMaterial = standardMaterial(motif.color);
const floorMaterial = standardMaterial(0xf4ead8);
const propMaterial = standardMaterial(motif.accent);
const detailMaterial = standardMaterial(0x343941);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.18, 0.72, 1.25, 7, 1),
baseMaterial
);
base.position.y = -0.58;
markIsland(base, island);
island.add(base);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(1.14, 1.19, 0.22, 7),
platformMaterial
);
platform.position.y = 0.12;
markIsland(platform, island);
island.add(platform);
const floor = new THREE.Mesh(
new THREE.CylinderGeometry(0.86, 0.9, 0.07, 7),
floorMaterial
);
floor.position.y = 0.265;
markIsland(floor, island);
island.add(floor);
const stageRing = new THREE.Mesh(
new THREE.TorusGeometry(0.7, 0.024, 4, 36),
new THREE.MeshBasicMaterial({ color: motif.accent })
);
stageRing.rotation.x = Math.PI / 2;
stageRing.position.y = 0.307;
markIsland(stageRing, island);
island.add(stageRing);
if (key === "A") {
// Three little parasols: the recurring visual signature.
[-0.4, 0, 0.4].forEach((x, i) => {
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 0.43, 6),
detailMaterial
);
pole.position.set(x, 0.52, -0.31 + (i - 1) * 0.06);
markIsland(pole, island);
island.add(pole);
const canopy = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.28, 6),
propMaterial
);
canopy.position.set(x, 0.84, -0.31 + (i - 1) * 0.06);
markIsland(canopy, island);
island.add(canopy);
});
} else if (key === "B") {
// A split cobalt gate.
[-0.38, 0.38].forEach((x) => {
const pillar = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.92, 0.32),
propMaterial
);
pillar.position.set(x, 0.72, -0.22);
markIsland(pillar, island);
island.add(pillar);
});
const lintel = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.2, 0.34),
propMaterial
);
lintel.position.set(0, 1.18, -0.22);
markIsland(lintel, island);
island.add(lintel);
} else if (key === "C") {
// A cluster of faceted golden crystals.
const crystalLayout = [
[-0.3, 0.5, -0.18, 0.27],
[0.05, 0.58, -0.34, 0.34],
[0.35, 0.48, -0.1, 0.23]
];
crystalLayout.forEach(([x, y, z, size]) => {
const crystal = new THREE.Mesh(
new THREE.OctahedronGeometry(size, 0),
propMaterial
);
crystal.position.set(x, y, z);
crystal.rotation.y = x * 2;
markIsland(crystal, island);
island.add(crystal);
});
} else {
// Four slender mirage pillars.
[-0.45, -0.15, 0.16, 0.46].forEach((x, i) => {
const height = 0.48 + (i % 2) * 0.28;
const pillar = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.11, height, 5),
propMaterial
);
pillar.position.set(x, 0.31 + height / 2, -0.2);
pillar.rotation.z = (i - 1.5) * 0.05;
markIsland(pillar, island);
island.add(pillar);
});
}
for (let i = 0; i < 3; i++) {
const angle = 0.6 + i * 2.1 + index * 0.4;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.09 + (i % 2) * 0.025, 0),
baseMaterial
);
rock.position.set(
Math.cos(angle) * 0.96,
-0.04,
Math.sin(angle) * 0.96
);
rock.scale.y = 0.72;
markIsland(rock, island);
island.add(rock);
}
const haloMaterial = new THREE.MeshBasicMaterial({
color: motif.accent,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const halo = new THREE.Mesh(
new THREE.TorusGeometry(1.42, 0.035, 4, 48),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.y = -0.06;
halo.visible = false;
markIsland(halo, island);
island.add(halo);
island.userData.island = true;
island.userData.sectionKey = key;
island.userData.halo = halo;
island.userData.baseY = 0;
return island;
}
function layoutFor(key) {
if (key === "A") {
return [
{ x: 0, y: 0.15, z: -3.65, scale: 1.28 },
{ x: 3.35, y: -0.22, z: 2.1, scale: 1.02 },
{ x: -3.35, y: -0.42, z: 2.1, scale: 1.02 }
];
}
if (key === "B") {
return [
{ x: -5.65, y: 0.55, z: 0.15, scale: 1.38 },
{ x: 5.65, y: -0.12, z: -0.15, scale: 1.38 }
];
}
if (key === "C") {
return Array.from({ length: 5 }, (_, i) => {
const angle = -0.65 + (i / 5) * Math.PI * 2;
return {
x: Math.sin(angle) * 5.15,
y: 0.16 + Math.sin(i * 1.7) * 0.22,
z: Math.cos(angle) * 5.15,
scale: 0.88
};
});
}
return [
{ x: -4.4, y: 0.6, z: 0.7, scale: 1.02 },
{ x: -1.55, y: -0.05, z: -0.7, scale: 1.08 },
{ x: 1.55, y: 0.18, z: 0.75, scale: 1.08 },
{ x: 4.45, y: -0.35, z: -0.65, scale: 1.02 }
];
}
function buildStage(key) {
const group = new THREE.Group();
group.userData.sectionKey = key;
layoutFor(key).forEach((placement, index) => {
const island = makeIsland(key, index);
island.position.set(placement.x, placement.y, placement.z);
island.scale.setScalar(placement.scale);
island.rotation.y = index % 2 === 0 ? -0.11 : 0.13;
island.userData.baseY = placement.y;
group.add(island);
});
return group;
}
function disposeGroup(group) {
const geometries = new Set();
const materials = new Set();
group.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => materials.add(material));
} else {
materials.add(object.material);
}
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
}
// ── Section transitions ───────────────────────────────────────────
function transitionTo(key, index, withSound = true) {
if (transition) {
const stale = transition.from;
stageRoot.remove(stale);
disposeGroup(stale);
transition = null;
}
const from = currentGroup;
const to = buildStage(key);
stageRoot.add(to);
currentGroup = to;
currentSection = key;
currentIndex = index;
if (from) {
from.scale.setScalar(1);
from.position.y = 0;
to.scale.setScalar(0.015);
to.position.y = -5.5;
transition = {
from,
to,
started: performance.now(),
duration: 1180,
direction: index % 2 === 0 ? 1 : -1
};
pulseMaterial.color.setHex(motifs[key].accent);
pulse.visible = true;
pulse.scale.setScalar(1);
pulseMaterial.opacity = 0.55;
} else {
to.scale.setScalar(1);
to.position.y = 0;
}
updateNow();
if (withSound) playChord(key);
}
function visitIndex(index, withSound = true) {
if (!sequence.length) return;
const bounded = (index + sequence.length) % sequence.length;
currentIndex = bounded;
transitionTo(sequence[bounded], bounded, withSound);
playElapsed = 0;
}
// ── Sequence UI ───────────────────────────────────────────────────
function renderSequence() {
const container = $("#sequence");
container.innerHTML = "";
$("#sectionCount").textContent = `${sequence.length} section${
sequence.length === 1 ? "" : "s"
}`;
sequence.forEach((key, index) => {
const motif = motifs[key];
const chip = document.createElement("div");
chip.className = "sequence-chip";
chip.draggable = true;
chip.dataset.index = index;
chip.style.setProperty("--chip-color", motif.css);
chip.innerHTML = `
<span class="chip-letter">${key}</span>
<span class="chip-name">${motif.name}</span>
<button class="remove-chip" aria-label="Remove ${motif.name}">×</button>
`;
chip.addEventListener("click", (event) => {
if (event.target.closest(".remove-chip")) {
removeSection(index);
} else {
visitIndex(index);
}
});
chip.addEventListener("dragstart", (event) => {
dragIndex = index;
chip.classList.add("dragging");
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", String(index));
});
chip.addEventListener("dragend", () => {
dragIndex = null;
chip.classList.remove("dragging");
});
container.appendChild(chip);
});
const marks = $("#formMarks");
marks.innerHTML = "";
sequence.forEach((key, index) => {
const mark = document.createElement("span");
mark.className = "form-mark";
mark.textContent = key;
mark.dataset.index = index;
marks.appendChild(mark);
});
updateNow();
}
function updateNow() {
const motif = motifs[currentSection];
$("#nowEyebrow").textContent =
`Section ${String(currentIndex + 1).padStart(2, "0")} / ` +
String(sequence.length).padStart(2, "0");
$("#nowLetter").textContent = motif.key;
$("#nowName").textContent = motif.name;
$("#nowKind").textContent =
motif.kind === "recurring" ? "Recurring motif" : "Contrasting motif";
$("#nowDescription").textContent = motif.description;
$("#nowPosition").textContent =
currentIndex === 0
? "Beginning"
: currentIndex === sequence.length - 1
? "Final return"
: "Middle section";
$("#nowShape").textContent = motif.shape;
$("#nowCard").style.setProperty("--now-color", motif.css);
document.querySelectorAll(".sequence-chip").forEach((chip) => {
chip.classList.toggle(
"active",
Number(chip.dataset.index) === currentIndex
);
});
document.querySelectorAll(".form-mark").forEach((mark) => {
mark.classList.toggle(
"active",
Number(mark.dataset.index) === currentIndex
);
});
}
function removeSection(index) {
if (sequence.length === 1) {
showToast("A rondo needs at least one section");
return;
}
const removedKey = sequence[index];
sequence.splice(index, 1);
const found = sequence.indexOf(currentSection);
if (found >= 0) {
currentIndex = found;
} else {
currentIndex = Math.min(currentIndex, sequence.length - 1);
const nextKey = sequence[currentIndex];
transitionTo(nextKey, currentIndex);
}
renderSequence();
showToast(`${motifs[removedKey].name} removed`);
}
function addSection(key) {
sequence.push(key);
renderSequence();
showToast(`${motifs[key].name} added to the form`);
}
function applySequence(nextSequence, message) {
sequence = [...nextSequence];
currentIndex = 0;
renderSequence();
transitionTo(sequence[0], 0);
if (message) showToast(message);
}
document.querySelectorAll(".motif-card").forEach((button) => {
button.addEventListener("click", () => {
addSection(button.dataset.motif);
});
});
$("#sequence").addEventListener("dragover", (event) => {
event.preventDefault();
});
$("#sequence").addEventListener("drop", (event) => {
event.preventDefault();
const target = event.target.closest(".sequence-chip");
if (!target || dragIndex === null) return;
const targetIndex = Number(target.dataset.index);
if (targetIndex === dragIndex) return;
const [moved] = sequence.splice(dragIndex, 1);
sequence.splice(targetIndex, 0, moved);
const found = sequence.indexOf(currentSection);
currentIndex = found >= 0 ? found : 0;
renderSequence();
showToast("Form reordered");
});
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
const presets = {
classic: ["A", "B", "A", "C", "A"],
expanded: ["A", "B", "A", "C", "A", "D", "A"],
minimal: ["A", "B", "A"]
};
applySequence(
presets[button.dataset.preset],
`${button.textContent} form applied`
);
});
});
$("#balanceButton").addEventListener("click", () => {
const balanced = [];
sequence.forEach((key) => {
if (
motifs[key].kind === "contrasting" &&
(!balanced.length || balanced[balanced.length - 1] !== "A")
) {
balanced.push("A");
}
balanced.push(key);
});
if (balanced[balanced.length - 1] !== "A") balanced.push("A");
applySequence(balanced, "Recurring returns balanced");
});
$("#clearButton").addEventListener("click", () => {
applySequence(["A"], "Form cleared");
});
// ── Hovering and selecting stage islands ──────────────────────────
let hoveredIsland = null;
function findIsland(object) {
let current = object;
while (current) {
if (current.userData?.island) return current;
current = current.parent;
}
return null;
}
function setHoveredIsland(island) {
if (hoveredIsland === island) return;
if (hoveredIsland?.userData.halo) {
hoveredIsland.userData.halo.visible = false;
}
hoveredIsland = island;
if (hoveredIsland?.userData.halo) {
hoveredIsland.userData.halo.visible = true;
canvas.style.cursor = "pointer";
} else {
canvas.style.cursor = "grab";
}
}
function updateHover(event) {
if (event.pointerType === "touch") return;
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
stageRoot.children,
true
);
const hit = intersections.find(
(intersection) => findIsland(intersection.object)
);
setHoveredIsland(hit ? findIsland(hit.object) : null);
if (hoveredIsland) {
const label = $("#hoverLabel");
label.textContent = `${motifs[currentSection].key} · ${motifs[currentSection].name}`;
label.style.left = `${event.clientX}px`;
label.style.top = `${event.clientY}px`;
label.classList.add("visible");
} else {
hideHover();
}
}
function hideHover() {
setHoveredIsland(null);
$("#hoverLabel").classList.remove("visible");
}
function pickIsland(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
stageRoot.children,
true
);
const hit = intersections.find(
(intersection) => findIsland(intersection.object)
);
if (!hit) return;
const island = findIsland(hit.object);
const key = island.userData.sectionKey;
const index = sequence.indexOf(key);
if (index >= 0) {
visitIndex(index);
} else {
addSection(key);
visitIndex(sequence.length - 1);
}
}
// ── Playback and optional synthesized chords ─────────────────────
$("#playButton").addEventListener("click", () => {
playing = !playing;
playElapsed = 0;
document.body.classList.toggle("playing", playing);
$("#playLabel").textContent = playing ? "Pause form" : "Play form";
if (playing) {
showToast("Rondo performance started");
}
});
function ensureAudio() {
if (!soundEnabled) return null;
const AudioContextClass =
window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return null;
if (!audioContext) {
audioContext = new AudioContextClass();
masterGain = audioContext.createGain();
masterGain.gain.value = 0.2;
masterGain.connect(audioContext.destination);
}
if (audioContext.state === "suspended") {
audioContext.resume();
}
return audioContext;
}
$("#soundButton").addEventListener("click", () => {
soundEnabled = !soundEnabled;
$("#soundButton").setAttribute("aria-pressed", String(soundEnabled));
$("#soundLabel").textContent = soundEnabled ? "Sound on" : "Sound off";
if (soundEnabled) {
ensureAudio();
playChord(currentSection);
showToast("Synthesized chords enabled");
}
});
function playChord(key) {
const context = ensureAudio();
if (!context) return;
const notes = motifs[key].notes;
const now = context.currentTime;
notes.forEach((frequency, index) => {
const oscillator = context.createOscillator();
const gain = context.createGain();
const start = now + index * 0.085;
oscillator.type = index === 1 ? "triangle" : "sine";
oscillator.frequency.setValueAtTime(frequency, start);
gain.gain.setValueAtTime(0.0001, start);
gain.gain.exponentialRampToValueAtTime(0.17, start + 0.045);
gain.gain.exponentialRampToValueAtTime(0.0001, start + 1.55);
oscillator.connect(gain);
gain.connect(masterGain);
oscillator.start(start);
oscillator.stop(start + 1.65);
});
}
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 1800);
}
// ── Keyboard and resize ───────────────────────────────────────────
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
!["INPUT", "TEXTAREA", "BUTTON"].includes(document.activeElement.tagName)
) {
event.preventDefault();
$("#playButton").click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
stageRoot.position.x = window.innerWidth > 760 ? 1.25 : 0;
}
window.addEventListener("resize", resize);
resize();
// ── Animation loop ────────────────────────────────────────────────
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
if (transition) {
const progress = THREE.MathUtils.clamp(
(performance.now() - transition.started) / transition.duration,
0,
1
);
const eased =
progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
transition.from.scale.setScalar(1 - eased * 0.92);
transition.from.position.y = -eased * 5.2;
transition.from.rotation.y =
eased * transition.direction * 0.48;
transition.to.scale.setScalar(0.015 + eased * 0.985);
transition.to.position.y = -5.5 * (1 - eased);
transition.to.rotation.y =
-transition.direction * 0.25 * (1 - eased);
if (progress >= 1) {
const finished = transition.from;
stageRoot.remove(finished);
disposeGroup(finished);
transition.to.scale.setScalar(1);
transition.to.position.y = 0;
transition.to.rotation.y = 0;
transition = null;
}
}
if (currentGroup) {
currentGroup.children.forEach((island, index) => {
if (!island.userData.island) return;
island.position.y =
island.userData.baseY +
Math.sin(elapsed * 1.05 + index * 1.7) * 0.065;
});
}
if (pulse.visible) {
pulse.scale.setScalar(1 + elapsed * 0.01);
pulseMaterial.opacity = Math.max(0, pulseMaterial.opacity - delta * 0.42);
if (pulseMaterial.opacity <= 0.01) pulse.visible = false;
}
particles.rotation.y = elapsed * 0.008;
particles.position.y = Math.sin(elapsed * 0.18) * 0.16;
if (playing) {
playElapsed += delta;
if (playElapsed >= SECTION_DURATION) {
playElapsed -= SECTION_DURATION;
visitIndex(currentIndex + 1);
}
}
$("#progressFill").style.transform = `scaleX(${
playing ? Math.min(playElapsed / SECTION_DURATION, 1) : 0
})`;
renderer.render(scene, camera);
}
renderSequence();
transitionTo(sequence[0], 0, false);
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
setTimeout(() => $("#loading").remove(), 450);
});
</script>
</body>
</html>
```