Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Percussion Rehearsal" 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: Neighborhood Percussion Rehearsal
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-percussion-rehearsal-x3343
Scene Description Prompt:
Build a small rehearsal circle with three procedural percussion instruments and visible beat markers. Each player's motion must match its displayed pattern without requiring prerecorded audio. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (neighborhood-percussion-rehearsal-x3343):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Loop — Procedural Rehearsal Circle</title>
<style>
:root {
--bg: #080c17;
--panel: rgba(12, 18, 34, 0.88);
--panel-solid: #0d1426;
--line: rgba(255, 255, 255, 0.12);
--text: #f4f7ff;
--muted: #8994ad;
--thud: #ff6b5f;
--tick: #ffd166;
--rattle: #55d6be;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.brand {
top: 22px;
left: 24px;
display: flex;
align-items: center;
gap: 14px;
user-select: none;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 8px);
grid-template-rows: repeat(3, 8px);
gap: 3px;
transform: rotate(-6deg);
}
.brand-mark i {
display: block;
background: var(--thud);
border-radius: 1px;
box-shadow: 0 0 18px rgba(255, 107, 95, 0.25);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
background: var(--tick);
}
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(7),
.brand-mark i:nth-child(9) {
background: var(--rattle);
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.camera-hint {
top: 24px;
right: 24px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(8, 12, 23, 0.58);
color: #aeb8ca;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.panel {
position: fixed;
z-index: 10;
left: 50%;
bottom: 18px;
width: min(1060px, calc(100% - 36px));
transform: translateX(-50%);
padding: 14px 16px 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(18px) saturate(130%);
}
.transport {
display: flex;
align-items: center;
gap: 10px;
min-height: 42px;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
}
.transport button {
height: 36px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.05);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 150ms ease;
}
.transport button:hover {
border-color: rgba(255, 255, 255, 0.35);
background: rgba(255, 255, 255, 0.1);
transform: translateY(-1px);
}
.transport button:active {
transform: translateY(0);
}
.transport button:focus-visible,
.step-cell:focus-visible,
input:focus-visible {
outline: 2px solid var(--tick);
outline-offset: 2px;
}
.transport .primary {
min-width: 94px;
border-color: transparent;
background: var(--text);
color: #101625;
}
.transport .primary:hover {
background: #fff;
}
.tempo {
display: flex;
align-items: center;
gap: 9px;
margin-left: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.tempo input {
width: 105px;
accent-color: var(--tick);
cursor: pointer;
}
.tempo output {
min-width: 58px;
color: var(--text);
font-variant-numeric: tabular-nums;
}
.status {
margin-left: auto;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
letter-spacing: 0.06em;
text-align: right;
text-transform: uppercase;
}
.status::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 8px;
border-radius: 50%;
background: var(--rattle);
box-shadow: 0 0 10px var(--rattle);
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 20px;
padding: 12px 1px 9px;
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-heading span {
color: var(--muted);
font-size: 10px;
}
.timeline-scroll {
overflow-x: auto;
padding-bottom: 3px;
scrollbar-color: #33405d transparent;
scrollbar-width: thin;
}
.timeline {
display: grid;
grid-template-columns: 92px repeat(16, minmax(27px, 1fr));
gap: 5px;
min-width: 680px;
align-items: center;
}
.lane-title {
display: grid;
grid-template-columns: 8px 1fr;
grid-template-rows: auto auto;
column-gap: 8px;
align-items: center;
min-height: 34px;
padding-right: 7px;
}
.lane-title.corner {
display: block;
color: #5f6a80;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.lane-dot {
grid-row: 1 / 3;
width: 7px;
height: 24px;
border-radius: 2px;
background: var(--lane);
box-shadow: 0 0 12px color-mix(in srgb, var(--lane) 45%, transparent);
}
.lane-title strong {
font-size: 10px;
letter-spacing: 0.08em;
}
.lane-title small {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.step-head {
height: 19px;
color: #63708a;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
text-align: center;
}
.step-head.quarter {
color: var(--tick);
font-weight: 800;
}
.step-cell {
position: relative;
height: 28px;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 5px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition: background 100ms ease, border-color 100ms ease, transform 100ms ease;
}
.step-cell::before {
content: "";
display: block;
width: 10px;
height: 10px;
margin: auto;
border-radius: 2px;
background: #303a50;
transition: 100ms ease;
}
.step-cell:hover {
border-color: rgba(255, 255, 255, 0.32);
transform: translateY(-1px);
}
.step-cell.active {
background: rgba(255, 255, 255, 0.075);
}
.step-cell.active::before {
background: var(--lane);
box-shadow: 0 0 9px var(--lane);
}
.step-cell.current {
border-color: rgba(255, 255, 255, 0.85);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.step-cell.current::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 3px;
height: 3px;
border-radius: 50%;
background: #fff;
transform: translateX(-50%);
}
.footnote {
display: flex;
justify-content: space-between;
gap: 16px;
padding-top: 8px;
color: #65708a;
font-size: 9px;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #080c17;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.brand {
top: 16px;
left: 16px;
}
.brand h1 {
font-size: 14px;
}
.brand p {
font-size: 9px;
}
.camera-hint {
display: none;
}
.panel {
bottom: 0;
width: 100%;
padding: 11px 10px 9px;
border-radius: 13px 13px 0 0;
}
.transport {
flex-wrap: wrap;
gap: 7px;
}
.transport button {
height: 33px;
padding: 0 10px;
font-size: 9px;
}
.transport .primary {
min-width: 78px;
}
.tempo {
order: 4;
width: 100%;
margin-left: 0;
}
.tempo input {
flex: 1;
}
.status {
font-size: 8px;
}
.panel-heading span {
display: none;
}
.footnote span:last-child {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="hud brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<h1>Voxel Loop</h1>
<p>Three players · sixteen steps · one circle</p>
</div>
</header>
<aside class="hud camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</aside>
<section class="panel" aria-label="Rehearsal controls and pattern">
<div class="transport">
<button id="play" class="primary" type="button" aria-pressed="false">▶ Play</button>
<button id="restart" type="button" title="Restart from step one">↺ Restart</button>
<label class="tempo" for="tempo">
Tempo
<input id="tempo" type="range" min="72" max="144" value="96" step="1" />
<output id="tempo-value" for="tempo">96 BPM</output>
</label>
<button id="mute" type="button" aria-pressed="false">Sound On</button>
<div id="status" class="status">Pattern ready</div>
</div>
<div class="panel-heading">
<strong>Displayed pattern · click a tile to edit</strong>
<span>One bar / 16 sixteenth-note steps</span>
</div>
<div class="timeline-scroll">
<div id="timeline" class="timeline"></div>
</div>
<div class="footnote">
<span>Pattern edits restart the bar so sound and motion always match.</span>
<span>Audio is synthesized live · Space toggles playback</span>
</div>
</section>
<div id="loading">Waking the pixels…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and pattern data
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const timeline = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const muteButton = document.querySelector("#mute");
const tempoInput = document.querySelector("#tempo");
const tempoValue = document.querySelector("#tempo-value");
const statusElement = document.querySelector("#status");
const loading = document.querySelector("#loading");
const STEP_COUNT = 16;
const players = [
{
name: "THUD",
role: "Low drum",
color: 0xff6b5f,
css: "#ff6b5f",
position: new THREE.Vector3(-2.65, 0.16, 1.05),
pan: -0.48,
pattern: [
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 0,
1, 0, 0, 0
]
},
{
name: "TICK",
role: "Wood block",
color: 0xffd166,
css: "#ffd166",
position: new THREE.Vector3(2.65, 0.16, 1.05),
pan: 0.48,
pattern: [
0, 0, 1, 0,
0, 1, 0, 0,
1, 0, 0, 1,
0, 0, 1, 0
]
},
{
name: "RATTLE",
role: "Pixel shaker",
color: 0x55d6be,
css: "#55d6be",
position: new THREE.Vector3(0, 0.16, -2.75),
pan: 0,
pattern: [
0, 1, 0, 1,
0, 1, 0, 1,
1, 0, 1, 0,
0, 1, 0, 1
]
}
];
timeline.innerHTML = `
<div class="lane-title corner">PLAYER</div>
${Array.from({ length: STEP_COUNT }, (_, i) => `
<div class="step-head ${i % 4 === 0 ? "quarter" : ""}" data-step="${i}">
${i + 1}
</div>
`).join("")}
${players.map((player, playerIndex) => `
<div class="lane-title" style="--lane:${player.css}">
<span class="lane-dot"></span>
<strong>${player.name}</strong>
<small>${player.role}</small>
</div>
${Array.from({ length: STEP_COUNT }, (_, step) => `
<button
type="button"
class="step-cell"
style="--lane:${player.css}"
data-player="${playerIndex}"
data-step="${step}"
aria-label="${player.name}, step ${step + 1}"
aria-pressed="false"
></button>
`).join("")}
`).join("")}
`;
const cells = [...timeline.querySelectorAll(".step-cell")];
const stepElements = [...timeline.querySelectorAll("[data-step]")];
function renderPattern() {
cells.forEach((cell) => {
const playerIndex = Number(cell.dataset.player);
const step = Number(cell.dataset.step);
const active = players[playerIndex].pattern[step] === 1;
cell.classList.toggle("active", active);
cell.setAttribute("aria-pressed", String(active));
});
}
renderPattern();
timeline.addEventListener("click", (event) => {
const cell = event.target.closest(".step-cell");
if (!cell) return;
const playerIndex = Number(cell.dataset.player);
const step = Number(cell.dataset.step);
const pattern = players[playerIndex].pattern;
pattern[step] = pattern[step] ? 0 : 1;
renderPattern();
// Restarting avoids a previously scheduled step disagreeing with the UI.
if (isPlaying) {
restartSequence();
}
});
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080c17);
scene.fog = new THREE.FogExp2(0x080c17, 0.034);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0.46,
pitch: 0.59,
radius: 13.4,
target: new THREE.Vector3(0, 0.35, 0)
};
function updateCamera() {
const horizontal = Math.sin(cameraState.pitch) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.cos(cameraState.pitch) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb9dfff, 0x171326, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe7c4, 3.2);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x668dff, 1.7);
rimLight.position.set(-7, 5, -7);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.035
})
);
}
return materialCache.get(key);
}
function voxel(parent, size, position, color, customMaterial = null) {
const mesh = new THREE.Mesh(unitBox, customMaterial || getMaterial(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.arcTo(x + width, y, x + width, y + height, radius);
context.arcTo(x + width, y + height, x, y + height, radius);
context.arcTo(x, y + height, x, y, radius);
context.arcTo(x, y, x + width, y, radius);
context.closePath();
}
function makeLabel(text, cssColor) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 8, 10, 496, 76, 18);
context.fillStyle = "rgba(7, 11, 23, 0.88)";
context.fill();
context.lineWidth = 4;
context.strokeStyle = cssColor;
context.stroke();
context.fillStyle = cssColor;
context.font = "800 37px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 50);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.65, 0.31, 1);
sprite.renderOrder = 20;
return sprite;
}
// Ground and tiled rehearsal platform.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x080d1a,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.14;
ground.receiveShadow = true;
scene.add(ground);
const stageBase = new THREE.Mesh(
new THREE.CylinderGeometry(4.82, 4.92, 0.18, 48),
new THREE.MeshStandardMaterial({
color: 0x121a2d,
roughness: 0.85
})
);
stageBase.position.y = -0.07;
stageBase.receiveShadow = true;
scene.add(stageBase);
for (let gx = -8; gx <= 8; gx++) {
for (let gz = -8; gz <= 8; gz++) {
if (gx * gx + gz * gz > 23.4) continue;
const tileColor = (gx + gz) % 2 === 0 ? 0x18233a : 0x141d31;
voxel(
scene,
[0.52, 0.13, 0.52],
[gx * 0.56, 0.075, gz * 0.56],
tileColor
);
}
}
// Dashed outer rehearsal circle.
for (let i = 0; i < 40; i++) {
const angle = (i / 40) * Math.PI * 2;
const marker = voxel(
scene,
[0.4, 0.15, 0.18],
[
Math.sin(angle) * 4.66,
0.11,
Math.cos(angle) * 4.66
],
i % 5 === 0 ? 0x334761 : 0x253149
);
marker.rotation.y = angle;
}
// Center pixel motif.
const centerMotif = new THREE.Group();
scene.add(centerMotif);
voxel(centerMotif, [1.25, 0.08, 0.16], [0, 0.17, 0], 0x3b4a65);
voxel(centerMotif, [0.16, 0.08, 1.25], [0, 0.17, 0], 0x3b4a65);
voxel(centerMotif, [0.25, 0.09, 0.25], [0, 0.18, 0], 0x697996);
// -------------------------------------------------------------------------
// Procedural voxel instruments and characters
// -------------------------------------------------------------------------
function createLowDrum(parent) {
const group = new THREE.Group();
parent.add(group);
// Feet.
voxel(group, [0.18, 0.35, 0.18], [-0.46, 0.24, 0], 0x242c42);
voxel(group, [0.18, 0.35, 0.18], [0.46, 0.24, 0], 0x242c42);
voxel(group, [1.3, 0.12, 0.8], [0, 0.39, 0], 0xff6b5f);
// Shell.
voxel(group, [1.2, 0.66, 0.74], [0, 0.78, 0], 0x25324d);
voxel(group, [1.04, 0.52, 0.06], [0, 0.8, 0.4], 0xf0eadc);
voxel(group, [0.31, 0.31, 0.08], [0, 0.8, 0.45], 0xff6b5f);
// Pixel highlights.
voxel(group, [0.11, 0.53, 0.79], [-0.48, 0.8, 0], 0xff8b75);
voxel(group, [0.11, 0.53, 0.79], [0.48, 0.8, 0], 0xff8b75);
voxel(group, [0.88, 0.09, 0.79], [0, 1.06, 0], 0xff8b75);
return {
group,
hitPoint: new THREE.Vector3(0, 0.82, 0.48)
};
}
function createWoodBlock(parent) {
const group = new THREE.Group();
parent.add(group);
voxel(group, [0.95, 0.13, 0.72], [0, 0.23, 0], 0x55482f);
voxel(group, [0.76, 0.55, 0.57], [0, 0.57, 0], 0xc99339);
voxel(group, [0.82, 0.12, 0.63], [0, 0.88, 0], 0xffd166);
voxel(group, [0.82, 0.08, 0.64], [0, 0.57, 0], 0x76562d);
voxel(group, [0.25, 0.13, 0.68], [-0.2, 0.31, 0], 0xffdf83);
voxel(group, [0.25, 0.13, 0.68], [0.2, 0.31, 0], 0xffdf83);
return {
group,
hitPoint: new THREE.Vector3(0, 0.94, 0)
};
}
function createShaker(parent) {
const group = new THREE.Group();
parent.add(group);
// Small stand.
voxel(group, [0.48, 0.12, 0.48], [0, 0.2, 0], 0x243248);
voxel(group, [0.15, 0.48, 0.15], [0, 0.48, 0], 0x33435d);
// Rattle head.
voxel(group, [0.54, 0.46, 0.54], [0, 0.91, 0], 0x55d6be);
voxel(group, [0.58, 0.12, 0.58], [0, 1.12, 0], 0x8cebd9);
voxel(group, [0.58, 0.12, 0.58], [0, 0.72, 0], 0x318f80);
// Dark pixel openings.
voxel(group, [0.12, 0.12, 0.59], [-0.17, 0.93, 0], 0x20364a);
voxel(group, [0.12, 0.12, 0.59], [0.17, 0.93, 0], 0x20364a);
voxel(group, [0.59, 0.12, 0.12], [0, 0.93, 0.17], 0x20364a);
return {
group,
hitPoint: new THREE.Vector3(0, 1.0, 0)
};
}
function createFigure(parent, bodyColor, accentColor, skinColor) {
const root = new THREE.Group();
parent.add(root);
// Legs and shoes.
voxel(root, [0.23, 0.61, 0.26], [-0.18, 0.46, 0], 0x26324b);
voxel(root, [0.23, 0.61, 0.26], [0.18, 0.46, 0], 0x26324b);
voxel(root, [0.29, 0.16, 0.42], [-0.18, 0.13, 0.08], 0x111827);
voxel(root, [0.29, 0.16, 0.42], [0.18, 0.13, 0.08], 0x111827);
// Torso.
voxel(root, [0.68, 0.64, 0.39], [0, 1.03, 0], bodyColor);
voxel(root, [0.71, 0.11, 0.41], [0, 0.75, 0], 0x1b2439);
voxel(root, [0.19, 0.18, 0.035], [0, 1.05, 0.21], accentColor);
// Neck and head.
voxel(root, [0.2, 0.13, 0.2], [0, 1.4, 0], skinColor);
voxel(root, [0.49, 0.48, 0.46], [0, 1.66, 0], skinColor);
voxel(root, [0.52, 0.13, 0.49], [0, 1.91, -0.015], 0x182034);
voxel(root, [0.09, 0.24, 0.48], [-0.22, 1.78, 0], 0x182034);
voxel(root, [0.09, 0.24, 0.48], [0.22, 1.78, 0], 0x182034);
// Eyes face local +Z, toward the center of the circle.
voxel(root, [0.07, 0.08, 0.025], [-0.1, 1.69, 0.238], 0x111827);
voxel(root, [0.07, 0.08, 0.025], [0.1, 1.69, 0.238], 0x111827);
function makeArm(side) {
const shoulder = new THREE.Group();
shoulder.position.set(side * 0.43, 1.31, 0);
root.add(shoulder);
voxel(shoulder, [0.18, 0.47, 0.19], [0, -0.22, 0], bodyColor);
const elbow = new THREE.Group();
elbow.position.y = -0.44;
shoulder.add(elbow);
voxel(elbow, [0.16, 0.38, 0.17], [0, -0.18, 0], skinColor);
voxel(elbow, [0.2, 0.2, 0.21], [0, -0.42, 0], skinColor);
return { shoulder, elbow };
}
const leftArm = makeArm(-1);
const rightArm = makeArm(1);
return { root, leftArm, rightArm };
}
const beatMarkers = [];
function createBeatMarkers() {
for (let step = 0; step < STEP_COUNT; step++) {
const angle = (step / STEP_COUNT) * Math.PI * 2;
const radius = 4.36;
const x = Math.sin(angle) * radius;
const z = Math.cos(angle) * radius;
const markerGroup = new THREE.Group();
markerGroup.position.set(x, 0.16, z);
markerGroup.rotation.y = angle;
scene.add(markerGroup);
voxel(
markerGroup,
[0.37, 0.11, 0.37],
[0, 0, 0],
0x33415a
);
const lampMaterial = new THREE.MeshStandardMaterial({
color: step % 4 === 0 ? 0xffd166 : 0x526985,
emissive: step % 4 === 0 ? 0xffd166 : 0x526985,
emissiveIntensity: 0.08,
roughness: 0.55
});
const lamp = voxel(
markerGroup,
[0.19, 0.2, 0.19],
[0, 0.15, 0],
0xffffff,
lampMaterial
);
beatMarkers.push({ lamp, lampMaterial });
}
}
createBeatMarkers();
function createBurst(parent, hitPoint, color) {
const group = new THREE.Group();
group.position.copy(hitPoint);
parent.add(group);
const particles = [];
for (let i = 0; i < 8; i++) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false
});
const particle = voxel(
group,
[0.11, 0.11, 0.11],
[0, 0, 0],
0xffffff,
material
);
particle.visible = false;
particle.castShadow = false;
particle.receiveShadow = false;
particle.userData.angle = (i / 8) * Math.PI * 2;
particles.push(particle);
}
return { group, particles };
}
const visualPlayers = [];
players.forEach((config, index) => {
const root = new THREE.Group();
root.position.copy(config.position);
root.lookAt(0, config.position.y, 0);
scene.add(root);
let instrument;
if (index === 0) instrument = createLowDrum(root);
else if (index === 1) instrument = createWoodBlock(root);
else instrument = createShaker(root);
const figure = createFigure(
root,
config.color,
0xf4f7ff,
[0xe7b18f, 0xb97855, 0xf0c7a5][index]
);
figure.root.position.z = -0.82;
const burst = createBurst(root, instrument.hitPoint, config.color);
const hitLight = new THREE.PointLight(config.color, 0, 2.4, 2);
hitLight.position.copy(instrument.hitPoint);
root.add(hitLight);
const label = makeLabel(`${config.name} / ${config.role.toUpperCase()}`, config.css);
label.position.set(0, 2.45, -0.85);
root.add(label);
visualPlayers.push({
config,
root,
figure,
instrument: instrument.group,
hitPoint: instrument.hitPoint,
burst,
hitLight,
hitStarted: -100,
hitCount: 0
});
});
// Decorative background pixel fragments.
const decorationColors = [0x23304b, 0x2c3b58, 0x27324b, 0x364663];
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2 + 0.2;
const radius = 7 + (i % 4) * 0.55;
const size = 0.12 + (i % 3) * 0.045;
const fragment = voxel(
scene,
[size, size, size],
[
Math.sin(angle) * radius,
1.1 + (i % 5) * 0.55,
Math.cos(angle) * radius
],
decorationColors[i % decorationColors.length]
);
fragment.rotation.set(i * 0.2, i * 0.37, i * 0.13);
fragment.castShadow = false;
}
// -------------------------------------------------------------------------
// Procedural Web Audio percussion
// -------------------------------------------------------------------------
let audioContext = null;
let masterGain = null;
let noiseBuffer = null;
let muted = false;
const audioSources = new Set();
async function initAudio() {
try {
if (!audioContext) {
const AudioContextClass = window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return;
audioContext = new AudioContextClass({ latencyHint: "interactive" });
masterGain = audioContext.createGain();
masterGain.gain.value = muted ? 0 : 0.52;
masterGain.connect(audioContext.destination);
noiseBuffer = audioContext.createBuffer(
1,
audioContext.sampleRate,
audioContext.sampleRate
);
const data = noiseBuffer.getChannelData(0);
for (let i = 0; i < data.length; i++) {
data[i] = Math.random() * 2 - 1;
}
}
if (audioContext.state === "suspended") {
await audioContext.resume();
}
} catch (error) {
console.warn("Audio could not be initialized; visual playback will continue.", error);
}
}
function clockNow() {
return audioContext
? audioContext.currentTime
: performance.now() / 1000;
}
function trackSource(source) {
audioSources.add(source);
source.addEventListener("ended", () => audioSources.delete(source), { once: true });
}
function stopSources() {
for (const source of audioSources) {
try {
source.stop();
} catch (_) {
// A source may already have ended.
}
}
audioSources.clear();
}
function makePanner(pan) {
const panner = audioContext.createStereoPanner();
panner.pan.value = pan;
panner.connect(masterGain);
return panner;
}
function scheduleNoise(time, duration, pan, type, frequency, volume) {
const source = audioContext.createBufferSource();
source.buffer = noiseBuffer;
const filter = audioContext.createBiquadFilter();
filter.type = type;
filter.frequency.value = frequency;
filter.Q.value = 0.8;
const gain = audioContext.createGain();
gain.gain.setValueAtTime(0.0001, time);
gain.gain.exponentialRampToValueAtTime(volume, time + 0.003);
gain.gain.exponentialRampToValueAtTime(0.0001, time + duration);
source.connect(filter);
filter.connect(gain);
gain.connect(makePanner(pan));
source.start(time);
source.stop(time + duration + 0.02);
trackSource(source);
}
function scheduleLowDrum(time, pan) {
const oscillator = audioContext.createOscillator();
oscillator.type = "sine";
oscillator.frequency.setValueAtTime(145, time);
oscillator.frequency.exponentialRampToValueAtTime(46, time + 0.17);
const gain = audioContext.createGain();
gain.gain.setValueAtTime(0.0001, time);
gain.gain.exponentialRampToValueAtTime(0.78, time + 0.005);
gain.gain.exponentialRampToValueAtTime(0.0001, time + 0.34);
oscillator.connect(gain);
gain.connect(makePanner(pan));
oscillator.start(time);
oscillator.stop(time + 0.36);
trackSource(oscillator);
scheduleNoise(time, 0.055, pan, "lowpass", 850, 0.13);
}
function scheduleWoodBlock(time, pan) {
const oscillator = audioContext.createOscillator();
oscillator.type = "triangle";
oscillator.frequency.setValueAtTime(760, time);
oscillator.frequency.exponentialRampToValueAtTime(430, time + 0.08);
const gain = audioContext.createGain();
gain.gain.setValueAtTime(0.0001, time);
gain.gain.exponentialRampToValueAtTime(0.25, time + 0.003);
gain.gain.exponentialRampToValueAtTime(0.0001, time + 0.16);
oscillator.connect(gain);
gain.connect(makePanner(pan));
oscillator.start(time);
oscillator.stop(time + 0.18);
trackSource(oscillator);
scheduleNoise(time, 0.04, pan, "bandpass", 1900, 0.11);
}
function scheduleShaker(time, pan) {
scheduleNoise(time, 0.13, pan, "highpass", 3900, 0.18);
scheduleNoise(time, 0.065, pan, "bandpass", 6700, 0.07);
}
function scheduleSound(playerIndex, time) {
if (!audioContext || !masterGain || muted) return;
const player = players[playerIndex];
if (playerIndex === 0) scheduleLowDrum(time, player.pan);
else if (playerIndex === 1) scheduleWoodBlock(time, player.pan);
else scheduleShaker(time, player.pan);
}
// -------------------------------------------------------------------------
// Transport and look-ahead scheduler
// -------------------------------------------------------------------------
let bpm = 96;
let isPlaying = false;
let currentStep = -1;
let nextStep = 0;
let nextNoteTime = 0;
let schedulerTimer = null;
const scheduledEvents = [];
function updateDisplayedStep(step) {
if (currentStep === step) return;
currentStep = step;
stepElements.forEach((element) => {
const isCurrent = Number(element.dataset.step) === step;
element.classList.toggle("current", isCurrent);
if (isCurrent) {
element.setAttribute("aria-current", "step");
} else {
element.removeAttribute("aria-current");
}
});
if (step >= 0) {
statusElement.textContent =
`Step ${String(step + 1).padStart(2, "0")} / 16 · Beat ${Math.floor(step / 4) + 1}`;
}
}
function scheduleStep(step, time) {
const hits = [];
players.forEach((player, playerIndex) => {
if (!player.pattern[step]) return;
hits.push(playerIndex);
scheduleSound(playerIndex, time);
});
scheduledEvents.push({ time, step, hits });
}
function scheduler() {
if (!isPlaying) return;
const sixteenthDuration = 60 / bpm / 4;
const horizon = clockNow() + 0.12;
while (nextNoteTime < horizon) {
scheduleStep(nextStep, nextNoteTime);
nextStep = (nextStep + 1) % STEP_COUNT;
nextNoteTime += sixteenthDuration;
}
}
function processScheduledEvents() {
if (!isPlaying) return;
const now = clockNow();
while (
scheduledEvents.length &&
scheduledEvents[0].time <= now + 0.004
) {
const event = scheduledEvents.shift();
updateDisplayedStep(event.step);
event.hits.forEach((playerIndex) => {
triggerPlayerHit(playerIndex);
});
}
}
function triggerPlayerHit(playerIndex) {
const player = visualPlayers[playerIndex];
player.hitStarted = performance.now() / 1000;
player.hitCount++;
player.burst.group.visible = true;
}
function updateTransportButton() {
playButton.innerHTML = isPlaying ? "❚❚ Pause" : "▶ Play";
playButton.setAttribute("aria-pressed", String(isPlaying));
}
async function startPlayback() {
await initAudio();
isPlaying = true;
nextStep = currentStep >= 0 ? (currentStep + 1) % STEP_COUNT : 0;
nextNoteTime = clockNow() + 0.07;
scheduledEvents.length = 0;
clearInterval(schedulerTimer);
schedulerTimer = setInterval(scheduler, 25);
scheduler();
updateTransportButton();
statusElement.textContent = "Rolling · sixteen-step loop";
}
function pausePlayback() {
isPlaying = false;
clearInterval(schedulerTimer);
schedulerTimer = null;
stopSources();
scheduledEvents.length = 0;
updateTransportButton();
statusElement.textContent = currentStep >= 0
? `Paused · step ${currentStep + 1}`
: "Paused";
}
function restartSequence() {
stopSources();
scheduledEvents.length = 0;
currentStep = -1;
nextStep = 0;
nextNoteTime = clockNow() + 0.07;
updateDisplayedStep(-1);
if (isPlaying) {
scheduler();
statusElement.textContent = "Bar restarted · pattern locked";
} else {
statusElement.textContent = "Ready at step one";
}
}
playButton.addEventListener("click", () => {
if (isPlaying) {
pausePlayback();
} else {
startPlayback();
}
});
restartButton.addEventListener("click", restartSequence);
muteButton.addEventListener("click", () => {
muted = !muted;
muteButton.textContent = muted ? "Sound Off" : "Sound On";
muteButton.setAttribute("aria-pressed", String(muted));
if (masterGain && audioContext) {
const now = audioContext.currentTime;
masterGain.gain.cancelScheduledValues(now);
masterGain.gain.setTargetAtTime(muted ? 0 : 0.52, now, 0.02);
}
});
tempoInput.addEventListener("input", () => {
bpm = Number(tempoInput.value);
tempoValue.textContent = `${bpm} BPM`;
});
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (event.code === "Space" && tag !== "INPUT" && tag !== "BUTTON") {
event.preventDefault();
playButton.click();
}
});
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js examples or addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.0045,
0.34,
1.05
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.009,
9.2,
18
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.46;
cameraState.pitch = 0.59;
cameraState.radius = 13.4;
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function updatePlayers(now) {
visualPlayers.forEach((player, index) => {
const elapsed = now - player.hitStarted;
let energy = 0;
if (elapsed >= 0 && elapsed < 0.42) {
energy = elapsed < 0.085
? elapsed / 0.085
: Math.max(0, 1 - (elapsed - 0.085) / 0.335);
}
const rightShoulder = player.figure.rightArm.shoulder;
const rightElbow = player.figure.rightArm.elbow;
const leftShoulder = player.figure.leftArm.shoulder;
const leftElbow = player.figure.leftArm.elbow;
if (index === 2) {
const shake = Math.sin(elapsed * 48);
leftShoulder.rotation.x = -0.42 * energy;
rightShoulder.rotation.x = -0.42 * energy;
leftShoulder.rotation.z = (0.48 + shake * 0.18) * energy;
rightShoulder.rotation.z = (-0.48 - shake * 0.18) * energy;
leftElbow.rotation.x = 0.25 * energy;
rightElbow.rotation.x = 0.25 * energy;
player.instrument.rotation.z = shake * 0.24 * energy;
} else {
rightShoulder.rotation.x = -1.43 * energy;
rightShoulder.rotation.z = -0.13 * energy;
rightElbow.rotation.x = 0.44 * energy;
leftShoulder.rotation.x = -0.12 * energy;
player.instrument.rotation.z = 0;
}
player.figure.root.position.y = energy * 0.045;
player.instrument.scale.set(
1,
1 - energy * (index === 2 ? 0.025 : 0.085),
1
);
player.hitLight.intensity = energy * 5.5;
const burstElapsed = now - player.hitStarted;
const burstProgress = burstElapsed / 0.48;
if (burstProgress >= 0 && burstProgress < 1) {
player.burst.group.visible = true;
player.burst.particles.forEach((particle) => {
const angle = particle.userData.angle;
const distance = 0.16 + burstProgress * 0.72;
particle.visible = true;
particle.position.set(
Math.cos(angle) * distance,
Math.sin(burstProgress * Math.PI) * 0.18,
Math.sin(angle) * distance
);
particle.scale.setScalar(1 - burstProgress * 0.55);
particle.material.opacity = (1 - burstProgress) * 0.9;
});
} else {
player.burst.group.visible = false;
player.burst.particles.forEach((particle) => {
particle.visible = false;
});
}
});
}
function updateBeatMarkers(now) {
beatMarkers.forEach((marker, step) => {
const current = step === currentStep;
const quarter = step % 4 === 0;
const pulse = current
? 1.12 + Math.sin(now * 12) * 0.1
: 1;
marker.lamp.scale.setScalar(pulse);
marker.lampMaterial.color.set(
current
? (quarter ? 0xfff1a8 : 0xffffff)
: (quarter ? 0x6a5931 : 0x34435d)
);
marker.lampMaterial.emissive.set(
current
? (quarter ? 0xffd166 : 0xa8cfff)
: (quarter ? 0xffd166 : 0x526985)
);
marker.lampMaterial.emissiveIntensity = current
? (quarter ? 4.5 : 3)
: (quarter ? 0.25 : 0.07);
});
}
function animate() {
requestAnimationFrame(animate);
const now = performance.now() / 1000;
processScheduledEvents();
updateCamera();
updatePlayers(now);
updateBeatMarkers(now);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
});
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```