Prompt specification
Build or customize the Three.js 3D scene "Four Signal Pads on a Ring" 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: Four Signal Pads on a Ring
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/four-signal-pads-on-a-ring-x3465
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Place four pads with distinct shapes and positions around a ring. Light a short sequence while keeping shape cues available for viewers who cannot distinguish colors.
Working Three.js Starter (four-signal-pads-on-a-ring-x3465):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#07111f">
<title>Voxel Shape Signal</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 21, 38, 0.82);
--panel-border: rgba(170, 205, 235, 0.18);
--text: #eef6ff;
--muted: #9db0c7;
--blue: #56b4e9;
--orange: #e69f00;
--green: #009e73;
--purple: #cc79a7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
canvas:focus-visible {
outline: 2px solid #ffffff;
outline-offset: -4px;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: auto;
}
.title-panel {
position: absolute;
top: 20px;
left: 20px;
width: min(370px, calc(100vw - 40px));
padding: 18px 20px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #b8cbe0;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.pixel-mark {
width: 16px;
height: 16px;
background:
linear-gradient(var(--blue), var(--blue)) 0 0 / 6px 16px no-repeat,
linear-gradient(var(--blue), var(--blue)) 10px 0 / 6px 6px no-repeat,
linear-gradient(var(--orange), var(--orange)) 0 10px / 16px 6px no-repeat;
image-rendering: pixelated;
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2.25rem);
line-height: 1;
letter-spacing: -0.045em;
}
.intro {
margin: 10px 0 15px;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.5;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid rgba(190, 215, 235, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.06);
color: var(--text);
font: inherit;
font-size: 0.78rem;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(190, 215, 235, 0.34);
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 2px solid #ffffff;
outline-offset: 2px;
}
.primary {
border-color: rgba(86, 180, 233, 0.45);
background: rgba(86, 180, 233, 0.16);
}
.status-panel {
position: absolute;
top: 20px;
right: 20px;
width: 246px;
padding: 15px 16px;
border-radius: 16px;
}
.status-kicker {
color: var(--muted);
font-size: 0.67rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-main {
display: flex;
align-items: center;
gap: 12px;
margin-top: 8px;
}
.status-symbol {
display: grid;
width: 46px;
height: 46px;
flex: 0 0 46px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 12px;
background: rgba(255, 255, 255, 0.06);
font-size: 1.65rem;
line-height: 1;
}
.status-title {
font-size: 1rem;
font-weight: 850;
}
.status-detail {
margin-top: 3px;
color: var(--muted);
font-size: 0.74rem;
}
.steps {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 13px;
}
.step {
display: grid;
height: 26px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 7px;
color: #8297ae;
font-size: 0.78rem;
transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.step.active {
color: #07111f;
background: #ffffff;
border-color: #ffffff;
}
.legend-panel {
position: absolute;
bottom: 20px;
left: 20px;
width: min(530px, calc(100vw - 40px));
padding: 13px;
border-radius: 16px;
}
.legend-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 0 3px 10px;
color: var(--muted);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-heading span:last-child {
color: #d9e7f5;
letter-spacing: 0.02em;
text-transform: none;
font-weight: 600;
}
.legend {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.legend button {
display: flex;
min-width: 0;
align-items: center;
gap: 9px;
padding: 8px;
text-align: left;
}
.cue {
display: grid;
width: 31px;
height: 31px;
flex: 0 0 31px;
place-items: center;
border: 1px solid color-mix(in srgb, var(--cue) 70%, white 10%);
border-radius: 8px;
background: color-mix(in srgb, var(--cue) 18%, transparent);
color: var(--cue);
font-size: 1.12rem;
line-height: 1;
}
.cue-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 0.72rem;
}
.help {
position: absolute;
right: 20px;
bottom: 20px;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.55;
text-align: right;
}
.help strong {
color: #e6f1fb;
font-weight: 750;
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #07111f;
color: #bcd0e4;
font-size: 0.85rem;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.intro {
display: none;
}
.status-panel {
top: 143px;
right: 12px;
width: 218px;
}
.legend-panel {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
}
.legend {
grid-template-columns: repeat(2, 1fr);
}
.help {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">Building voxel ring…</div>
<div class="hud">
<section class="panel title-panel" aria-labelledby="scene-title">
<div class="eyebrow">
<span class="pixel-mark" aria-hidden="true"></span>
Voxel signal / four pads
</div>
<h1 id="scene-title">Shape Signal</h1>
<p class="intro">
A repeating light phrase around a voxel ring. Every pad keeps a unique
silhouette, label, and readable text cue.
</p>
<div class="controls">
<button id="toggleSequence" class="primary" type="button">Pause</button>
<button id="replaySequence" type="button">Replay</button>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
<section class="panel status-panel" aria-label="Current sequence step">
<div class="status-kicker" id="statusKicker">Sequence</div>
<div class="status-main">
<div class="status-symbol" id="statusSymbol" aria-hidden="true">+</div>
<div>
<div class="status-title" id="statusTitle">Cross</div>
<div class="status-detail" id="statusDetail">Plus-sign cue</div>
</div>
</div>
<div class="steps" id="stepDots" aria-hidden="true"></div>
</section>
<section class="panel legend-panel" aria-labelledby="legend-title">
<div class="legend-heading">
<span id="legend-title">Color-safe shape legend</span>
<span>Select a pad to preview it</span>
</div>
<div class="legend" id="legend">
<button type="button" data-pad="0" style="--cue: var(--blue)">
<span class="cue" aria-hidden="true">+</span>
<span class="cue-name">Cross</span>
</button>
<button type="button" data-pad="1" style="--cue: var(--orange)">
<span class="cue" aria-hidden="true">▲</span>
<span class="cue-name">Triangle</span>
</button>
<button type="button" data-pad="2" style="--cue: var(--green)">
<span class="cue" aria-hidden="true">■</span>
<span class="cue-name">Square</span>
</button>
<button type="button" data-pad="3" style="--cue: var(--purple)">
<span class="cue" aria-hidden="true">◆</span>
<span class="cue-name">Diamond</span>
</button>
</div>
</section>
<div class="panel help">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br>
<strong>Arrow keys</strong> rotate · <strong>+ / −</strong> zoom
</div>
</div>
<div id="announcer" class="sr-only" aria-live="polite" aria-atomic="true"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const canvas = document.createElement("canvas");
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"Interactive voxel ring with four shape-coded light pads. Drag to orbit and use the arrow keys to rotate."
);
document.body.prepend(canvas);
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 18, 34);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
70
);
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const hemi = new THREE.HemisphereLight(0xbcdcff, 0x182238, 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4e6, 3.1);
sun.position.set(7, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x7dbfff, 1.05);
rimLight.position.set(-10, 7, -9);
scene.add(rimLight);
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
// ---------------------------------------------------------------------
// Voxel terrain
// ---------------------------------------------------------------------
const floorGeometry = new THREE.BoxGeometry(0.96, 0.28, 0.96);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0.02,
vertexColors: true
});
const floorCells = [];
function hash(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
return value - Math.floor(value);
}
for (let x = -11; x <= 11; x++) {
for (let z = -11; z <= 11; z++) {
const radius = Math.hypot(x, z);
if (radius <= 11.35) floorCells.push({ x, z, radius });
}
}
const floor = new THREE.InstancedMesh(
floorGeometry,
floorMaterial,
floorCells.length
);
floor.receiveShadow = true;
floor.castShadow = false;
floorCells.forEach((cell, index) => {
const heightJitter = cell.radius > 8 ? -0.035 : 0;
dummy.position.set(cell.x, -0.14 + heightJitter, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floor.setMatrixAt(index, dummy.matrix);
const variation = hash(cell.x * 3.1, cell.z * 2.7);
tempColor.set(0x142238);
if ((cell.x + cell.z) % 2 === 0) {
tempColor.lerp(new THREE.Color(0x1b2d46), 0.42);
} else {
tempColor.lerp(new THREE.Color(0x102034), 0.32);
}
if (variation > 0.83) {
tempColor.lerp(new THREE.Color(0x2b455c), 0.42);
}
floor.setColorAt(index, tempColor);
});
floor.instanceMatrix.needsUpdate = true;
floor.instanceColor.needsUpdate = true;
scene.add(floor);
// Pixelated center platform.
const centerTileGeometry = new THREE.BoxGeometry(0.72, 0.15, 0.72);
const centerTileMaterial = new THREE.MeshStandardMaterial({
color: 0x263a50,
roughness: 0.78
});
const centerTiles = new THREE.InstancedMesh(
centerTileGeometry,
centerTileMaterial,
25
);
centerTiles.receiveShadow = true;
let centerIndex = 0;
for (let x = -2; x <= 2; x++) {
for (let z = -2; z <= 2; z++) {
dummy.position.set(x * 0.73, 0.075, z * 0.73);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
centerTiles.setMatrixAt(centerIndex++, dummy.matrix);
}
}
centerTiles.instanceMatrix.needsUpdate = true;
scene.add(centerTiles);
// Segmented voxel ring.
const ringGeometry = new THREE.BoxGeometry(0.62, 0.18, 0.62);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.62,
metalness: 0.08,
vertexColors: true
});
const ringCount = 48;
const ring = new THREE.InstancedMesh(ringGeometry, ringMaterial, ringCount);
ring.castShadow = true;
ring.receiveShadow = true;
for (let i = 0; i < ringCount; i++) {
const angle = (i / ringCount) * Math.PI * 2;
const radius = 5.25;
dummy.position.set(
Math.sin(angle) * radius,
0.105,
Math.cos(angle) * radius
);
dummy.rotation.set(0, angle, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
ring.setMatrixAt(i, dummy.matrix);
tempColor.set(i % 4 === 0 ? 0x3d6683 : 0x29465f);
if (i % 2 === 0) tempColor.lerp(new THREE.Color(0x496c83), 0.18);
ring.setColorAt(i, tempColor);
}
ring.instanceMatrix.needsUpdate = true;
ring.instanceColor.needsUpdate = true;
scene.add(ring);
// Central voxel beacon.
const core = new THREE.Group();
scene.add(core);
const coreDark = new THREE.MeshStandardMaterial({
color: 0x17283b,
roughness: 0.56,
metalness: 0.18
});
const coreEdge = new THREE.MeshStandardMaterial({
color: 0x35516b,
roughness: 0.48,
metalness: 0.15
});
const coreGlow = new THREE.MeshStandardMaterial({
color: 0xb9eaff,
emissive: 0x56b4e9,
emissiveIntensity: 0.8,
roughness: 0.3,
metalness: 0.1
});
for (const x of [-0.75, 0.75]) {
for (const z of [-0.75, 0.75]) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.68, 0.34, 0.68),
coreDark
);
block.position.set(x, 0.29, z);
block.castShadow = true;
block.receiveShadow = true;
core.add(block);
}
}
const coreColumn = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 1.0, 0.72),
coreEdge
);
coreColumn.position.y = 0.86;
coreColumn.castShadow = true;
core.add(coreColumn);
const coreTop = new THREE.Mesh(
new THREE.BoxGeometry(0.54, 0.54, 0.54),
coreGlow
);
coreTop.position.y = 1.59;
coreTop.castShadow = true;
core.add(coreTop);
const coreLight = new THREE.PointLight(0x8dd9ff, 7, 6, 2);
coreLight.position.set(0, 1.8, 0);
core.add(coreLight);
// ---------------------------------------------------------------------
// Four pads: plus, triangle, square outline, diamond
// ---------------------------------------------------------------------
const padDefinitions = [
{
name: "Cross",
symbol: "+",
cue: "Plus-sign cue",
color: 0x56b4e9,
position: [0, -5.25],
rotation: 0,
shape: [
[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]
]
},
{
name: "Triangle",
symbol: "▲",
cue: "Triangle cue",
color: 0xe69f00,
position: [5.25, 0],
rotation: -Math.PI / 2,
shape: [
[0, -1],
[-1, 0], [0, 0], [1, 0],
[-1, 1], [0, 1], [1, 1]
]
},
{
name: "Square",
symbol: "■",
cue: "Square-outline cue",
color: 0x009e73,
position: [0, 5.25],
rotation: Math.PI,
shape: [
[-1, -1], [0, -1], [1, -1],
[-1, 0], [1, 0],
[-1, 1], [0, 1], [1, 1]
]
},
{
name: "Diamond",
symbol: "◆",
cue: "Diamond cue",
color: 0xcc79a7,
position: [-5.25, 0],
rotation: Math.PI / 2,
shape: [
[0, 0],
[0.78, 0.78], [-0.78, 0.78],
[0.78, -0.78], [-0.78, -0.78]
]
}
];
const baseBlockGeometry = new THREE.BoxGeometry(0.88, 0.22, 0.88);
const baseBlockMaterial = new THREE.MeshStandardMaterial({
color: 0x1b2b3d,
roughness: 0.72,
metalness: 0.12
});
const tileGeometry = new THREE.BoxGeometry(0.58, 0.58, 0.58);
const haloGeometry = new THREE.BoxGeometry(0.68, 0.055, 0.68);
const sparkGeometry = new THREE.BoxGeometry(0.11, 0.11, 0.11);
const pads = [];
function roundedLabelTexture(definition) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 160;
const context = labelCanvas.getContext("2d");
const accent = `#${new THREE.Color(definition.color).getHexString()}`;
context.clearRect(0, 0, 512, 160);
context.fillStyle = "rgba(5, 13, 25, 0.93)";
context.fillRect(4, 4, 504, 152);
context.strokeStyle = accent;
context.lineWidth = 7;
context.strokeRect(7, 7, 498, 146);
context.fillStyle = accent;
context.font = "700 62px Arial, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(definition.symbol, 63, 82);
context.fillStyle = "#f1f7ff";
context.font = "800 43px Arial, sans-serif";
context.textAlign = "left";
context.fillText(definition.name.toUpperCase(), 128, 82);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
padDefinitions.forEach((definition, index) => {
const group = new THREE.Group();
group.position.set(definition.position[0], 0, definition.position[1]);
group.rotation.y = definition.rotation;
scene.add(group);
// A common nine-block plinth keeps the four pad positions visually equal.
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
const block = new THREE.Mesh(baseBlockGeometry, baseBlockMaterial);
block.position.set(x * 0.91, 0.11, z * 0.91);
block.castShadow = true;
block.receiveShadow = true;
group.add(block);
}
}
const material = new THREE.MeshStandardMaterial({
color: definition.color,
emissive: definition.color,
emissiveIntensity: 0.08,
roughness: 0.42,
metalness: 0.12
});
const haloMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0,
depthWrite: false
});
const tiles = [];
const halos = [];
definition.shape.forEach(([x, z], tileIndex) => {
const tile = new THREE.Mesh(tileGeometry, material);
tile.position.set(x * 0.66, 0.48, z * 0.66);
tile.castShadow = true;
tile.receiveShadow = true;
group.add(tile);
tiles.push({
mesh: tile,
baseY: tile.position.y,
phase: tileIndex * 0.73
});
// The luminous echo repeats the exact silhouette of the pad.
const halo = new THREE.Mesh(haloGeometry, haloMaterial);
halo.position.set(x * 0.84, 0.245, z * 0.84);
group.add(halo);
halos.push(halo);
});
const light = new THREE.PointLight(definition.color, 0, 5.8, 2);
light.position.set(0, 1.05, 0);
group.add(light);
const sparkMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0,
depthWrite: false
});
const sparks = [];
for (let i = 0; i < 12; i++) {
const spark = new THREE.Mesh(sparkGeometry, sparkMaterial);
spark.visible = false;
spark.userData.angle = (i / 12) * Math.PI * 2 + index * 0.31;
spark.userData.offset = (i % 4) * 0.055;
spark.userData.spin = 0.7 + (i % 5) * 0.12;
group.add(spark);
sparks.push(spark);
}
const labelMaterial = new THREE.SpriteMaterial({
map: roundedLabelTexture(definition),
transparent: true,
depthWrite: false,
fog: false
});
const label = new THREE.Sprite(labelMaterial);
label.position.set(0, 1.55, 0);
label.scale.set(2.35, 0.73, 1);
group.add(label);
pads.push({
group,
material,
haloMaterial,
tiles,
halos,
light,
sparkMaterial,
sparks,
sparkStart: -100,
definition
});
});
// ---------------------------------------------------------------------
// Sequence and accessibility state
// ---------------------------------------------------------------------
const sequence = [0, 1, 3, 2];
const beatDuration = 850;
const loopPause = 1100;
const toggleButton = document.getElementById("toggleSequence");
const replayButton = document.getElementById("replaySequence");
const resetButton = document.getElementById("resetView");
const legendButtons = [...document.querySelectorAll("[data-pad]")];
const statusKicker = document.getElementById("statusKicker");
const statusSymbol = document.getElementById("statusSymbol");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const stepDots = document.getElementById("stepDots");
const announcer = document.getElementById("announcer");
sequence.forEach((padIndex) => {
const dot = document.createElement("span");
dot.className = "step";
dot.textContent = padDefinitions[padIndex].symbol;
stepDots.appendChild(dot);
});
let running = true;
let sequenceTime = 0;
let lastStep = -1;
let activePad = -1;
let activeEnvelope = 0;
let preview = null;
let elapsed = 0;
let centerPulse = 0;
function smoothstep(edge0, edge1, value) {
const x = Math.max(0, Math.min(1, (value - edge0) / (edge1 - edge0)));
return x * x * (3 - 2 * x);
}
function triggerPad(index) {
pads[index].sparkStart = elapsed;
centerPulse = 1;
}
function announceStep(step) {
const definition = padDefinitions[sequence[step]];
announcer.textContent =
`Step ${step + 1} of ${sequence.length}: ${definition.name}. ${definition.cue}.`;
}
function setVisibleStatus(kicker, definition, detail, step = -1) {
statusKicker.textContent = kicker;
statusSymbol.textContent = definition.symbol;
statusSymbol.style.color = `#${new THREE.Color(definition.color).getHexString()}`;
statusTitle.textContent = definition.name;
statusDetail.textContent = detail;
[...stepDots.children].forEach((dot, index) => {
dot.classList.toggle("active", index === step);
});
}
function previewPad(index) {
preview = {
index,
start: elapsed,
duration: 950
};
triggerPad(index);
}
legendButtons.forEach((button) => {
button.addEventListener("click", () => {
previewPad(Number(button.dataset.pad));
});
});
toggleButton.addEventListener("click", () => {
running = !running;
toggleButton.textContent = running ? "Pause" : "Resume";
if (running) {
lastStep = -1;
} else {
activePad = -1;
statusKicker.textContent = "Paused";
}
});
replayButton.addEventListener("click", () => {
sequenceTime = 0;
lastStep = -1;
running = true;
preview = null;
toggleButton.textContent = "Pause";
});
function updateSequence(dt) {
let step = -1;
let phase = 0;
if (running) {
sequenceTime += dt * 1000;
const totalSequenceTime = sequence.length * beatDuration;
const loopTime = sequenceTime % (totalSequenceTime + loopPause);
if (loopTime < totalSequenceTime) {
step = Math.floor(loopTime / beatDuration);
phase = (loopTime % beatDuration) / beatDuration;
}
}
if (step !== lastStep) {
lastStep = step;
if (step >= 0) {
triggerPad(sequence[step]);
announceStep(step);
}
}
if (preview) {
const previewPhase = (elapsed - preview.start) / preview.duration;
if (previewPhase < 1) {
activePad = preview.index;
activeEnvelope = 1 - smoothstep(0.58, 1, previewPhase);
const definition = padDefinitions[preview.index];
setVisibleStatus(
"Preview",
definition,
definition.cue,
sequence.indexOf(preview.index)
);
} else {
preview = null;
}
}
if (!preview) {
if (running && step >= 0) {
activePad = sequence[step];
activeEnvelope = 1 - smoothstep(0.52, 1, phase);
const definition = padDefinitions[activePad];
setVisibleStatus(
`Step ${step + 1} / ${sequence.length}`,
definition,
definition.cue,
step
);
} else {
activePad = -1;
activeEnvelope = 0;
if (running) {
const neutral = padDefinitions[0];
setVisibleStatus("Cycle rest", neutral, "Next phrase begins shortly", -1);
} else {
const neutral = padDefinitions[0];
setVisibleStatus("Paused", neutral, "Press Resume to continue", -1);
}
}
}
}
// ---------------------------------------------------------------------
// Direct camera controls — no external controls addon
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const initialCamera = {
theta: 0.68,
polar: 1.02,
radius: 18.6
};
const cameraState = { ...initialCamera };
const desiredCamera = { ...initialCamera };
function applyCamera(dt) {
const smoothing = reducedMotion ? 1 : 1 - Math.exp(-dt * 13);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
desiredCamera.theta,
smoothing
);
cameraState.polar = THREE.MathUtils.lerp(
cameraState.polar,
desiredCamera.polar,
smoothing
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredCamera.radius,
smoothing
);
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x + sinPolar * Math.sin(cameraState.theta) * cameraState.radius,
cameraTarget.y + Math.cos(cameraState.polar) * cameraState.radius,
cameraTarget.z + sinPolar * Math.cos(cameraState.theta) * cameraState.radius
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let dragDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
desiredCamera.theta -= dx * 0.006;
desiredCamera.polar = THREE.MathUtils.clamp(
desiredCamera.polar + dy * 0.005,
0.36,
1.36
);
});
function endPointer(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
11.5,
29
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desiredCamera.theta += 0.12;
break;
case "ArrowRight":
desiredCamera.theta -= 0.12;
break;
case "ArrowUp":
desiredCamera.polar = Math.max(0.36, desiredCamera.polar - 0.09);
break;
case "ArrowDown":
desiredCamera.polar = Math.min(1.36, desiredCamera.polar + 0.09);
break;
case "+":
case "=":
desiredCamera.radius = Math.max(11.5, desiredCamera.radius - 1);
break;
case "-":
case "_":
desiredCamera.radius = Math.min(29, desiredCamera.radius + 1);
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
resetButton.addEventListener("click", () => {
Object.assign(desiredCamera, initialCamera);
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
function updatePads(dt) {
pads.forEach((pad, index) => {
const isActive = index === activePad;
const envelope = isActive ? activeEnvelope : 0;
pad.material.emissiveIntensity = 0.08 + envelope * 1.7;
pad.light.intensity = envelope * 42;
pad.haloMaterial.opacity = envelope * 0.7;
pad.tiles.forEach((tile) => {
const bounce = reducedMotion
? 0
: Math.sin(elapsed * 11 + tile.phase) * 0.035;
tile.mesh.position.y =
tile.baseY + envelope * (0.085 + bounce);
tile.mesh.scale.setScalar(1 + envelope * 0.045);
});
pad.halos.forEach((halo, haloIndex) => {
const pulse = reducedMotion
? 0
: Math.sin(elapsed * 9 + haloIndex * 0.45) * 0.025;
halo.scale.setScalar(1 + envelope * (0.035 + pulse));
});
const sparkAge = elapsed - pad.sparkStart;
pad.sparkMaterial.opacity = envelope * 0.82;
pad.sparks.forEach((spark) => {
const localAge = sparkAge - spark.userData.offset;
if (localAge >= 0 && localAge < 1.05) {
const radial = 0.16 + localAge * 0.42;
spark.visible = true;
spark.position.set(
Math.cos(spark.userData.angle) * radial,
0.72 + localAge * 1.38,
Math.sin(spark.userData.angle) * radial
);
spark.rotation.set(
localAge * spark.userData.spin,
localAge * 2.2,
localAge * spark.userData.spin
);
spark.scale.setScalar(1 - localAge * 0.45);
} else {
spark.visible = false;
}
});
});
centerPulse = Math.max(0, centerPulse - dt * 3.8);
coreGlow.emissiveIntensity = 0.65 + centerPulse * 2.6;
coreLight.intensity = 5 + centerPulse * 32;
if (!reducedMotion) {
coreTop.rotation.y += dt * 0.45;
}
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateSequence(dt);
updatePads(dt);
applyCamera(dt);
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
applyCamera(1);
updateSequence(0);
renderer.render(scene, camera);
loading.remove();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```