Prompt specification
Build or customize the Three.js 3D scene "Predict a Player After Several Rotations" 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: Predict a Player After Several Rotations
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/predict-a-player-after-several-rotations-x3668
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring volleyball rotation and player positions. Create a cyclic-permutation puzzle based on the same six-position ring. Accept modular arithmetic predictions and verify them through repeated visual steps. Voxel style.
Working Three.js Starter (predict-a-player-after-several-rotations-x3668):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Volley Rotation — Modular Six</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 39, 0.88);
--panel-strong: rgba(10, 24, 41, 0.96);
--line: rgba(165, 219, 255, 0.17);
--text: #eef8ff;
--muted: #91a9bd;
--cyan: #67e8f9;
--lime: #b7f36b;
--orange: #ffb35c;
--red: #ff7387;
}
* {
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 {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.025), transparent 45%),
var(--panel);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
top: 20px;
left: 20px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 14px 11px 10px;
border-radius: 15px;
pointer-events: none;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border-radius: 11px;
color: #07111f;
background: linear-gradient(145deg, var(--cyan), #82aaff);
box-shadow: 0 0 28px rgba(103, 232, 249, 0.22);
font: 900 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand-title {
font-size: 13px;
font-weight: 900;
letter-spacing: 0.13em;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.challenge {
top: 94px;
left: 20px;
width: 370px;
max-height: calc(100vh - 120px);
overflow: auto;
padding: 18px;
border-radius: 20px;
scrollbar-width: thin;
scrollbar-color: rgba(103, 232, 249, 0.3) transparent;
}
.eyebrow {
color: var(--cyan);
font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.intro strong {
color: var(--text);
}
.comparison {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin: 15px 0;
}
.matrix {
min-width: 0;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(2, 10, 20, 0.28);
}
.matrix-title {
padding: 9px 10px;
border-bottom: 1px solid var(--line);
color: var(--muted);
font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.matrix-title span {
float: right;
color: rgba(145, 169, 189, 0.62);
}
.seat-row {
display: grid;
grid-template-columns: 30px 1fr;
align-items: center;
gap: 6px;
min-height: 28px;
padding: 3px 7px;
}
.seat-row + .seat-row {
border-top: 1px solid rgba(165, 219, 255, 0.055);
}
.seat-code {
color: #7890a5;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.token {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 34px;
height: 21px;
padding: 0 7px;
border-radius: 6px;
color: #07111f;
font: 900 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.13);
}
.token.small {
min-width: 28px;
height: 25px;
font-size: 11px;
}
.equation {
margin: 12px 0 9px;
padding: 10px 12px;
border: 1px solid rgba(103, 232, 249, 0.14);
border-radius: 10px;
color: #b8d6e6;
background: rgba(103, 232, 249, 0.045);
text-align: center;
font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.equation b {
color: var(--cyan);
}
.input-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.prediction-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
#prediction {
width: 100%;
height: 43px;
padding: 0 12px;
border: 1px solid rgba(103, 232, 249, 0.25);
border-radius: 10px;
outline: none;
color: var(--text);
background: rgba(2, 10, 20, 0.64);
font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
transition: border-color 160ms, box-shadow 160ms;
}
#prediction:focus {
border-color: var(--cyan);
box-shadow: 0 0 0 3px rgba(103, 232, 249, 0.08);
}
#prediction::placeholder {
color: #587083;
}
.primary {
height: 43px;
padding: 0 14px;
border: 0;
border-radius: 10px;
color: #07111f;
background: linear-gradient(135deg, var(--cyan), #8cb4ff);
box-shadow: 0 7px 22px rgba(103, 232, 249, 0.16);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.primary:hover {
filter: brightness(1.08);
}
.primary:disabled {
cursor: wait;
opacity: 0.55;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 8px;
}
.secondary {
height: 35px;
border: 1px solid var(--line);
border-radius: 9px;
color: #c9dce8;
background: rgba(255, 255, 255, 0.025);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.secondary:hover {
border-color: rgba(103, 232, 249, 0.35);
color: white;
background: rgba(103, 232, 249, 0.06);
}
#status {
min-height: 48px;
margin-top: 12px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--muted);
background: rgba(0, 0, 0, 0.12);
font-size: 11px;
line-height: 1.45;
}
#status.good {
border-color: rgba(183, 243, 107, 0.35);
color: #d9ffc1;
background: rgba(183, 243, 107, 0.07);
}
#status.bad {
border-color: rgba(255, 115, 135, 0.35);
color: #ffd3da;
background: rgba(255, 115, 135, 0.07);
}
#status.running {
border-color: rgba(103, 232, 249, 0.35);
color: #c6f7ff;
background: rgba(103, 232, 249, 0.07);
}
.accepted {
margin-top: 11px;
color: #6f8799;
font-size: 10px;
line-height: 1.55;
}
.accepted code {
color: #b8d6e6;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend {
top: 20px;
right: 20px;
width: 242px;
padding: 14px;
border-radius: 15px;
pointer-events: none;
}
.legend-title {
margin-bottom: 8px;
color: var(--muted);
font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
}
.cycle {
padding: 9px 10px;
border-radius: 9px;
color: var(--cyan);
background: rgba(103, 232, 249, 0.055);
text-align: center;
font: 800 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.role-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px 10px;
margin-top: 11px;
color: #9fb6c7;
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.role-list b {
color: white;
}
.transport {
right: 20px;
bottom: 20px;
width: min(570px, calc(100vw - 430px));
min-width: 430px;
padding: 13px 14px;
border-radius: 16px;
}
.transport-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.transport-title {
font-size: 11px;
font-weight: 900;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.step-readout {
color: var(--cyan);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.live-lineup {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 6px;
margin-bottom: 10px;
}
.live-seat {
min-width: 0;
padding: 6px 2px;
border: 1px solid var(--line);
border-radius: 8px;
text-align: center;
background: rgba(2, 10, 20, 0.22);
}
.live-seat small {
display: block;
margin-bottom: 3px;
color: #7890a5;
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.transport-actions {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
}
.view-tools {
position: fixed;
z-index: 4;
right: 20px;
top: 222px;
display: flex;
gap: 6px;
}
.view-tools button {
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 8px;
color: #b8cedd;
background: rgba(8, 20, 35, 0.76);
backdrop-filter: blur(10px);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.view-tools button:hover {
color: var(--cyan);
border-color: rgba(103, 232, 249, 0.35);
}
.camera-hint {
position: fixed;
z-index: 4;
left: 20px;
bottom: 20px;
color: rgba(160, 186, 203, 0.63);
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
@media (max-width: 900px) {
.legend {
display: none;
}
.transport {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
min-width: 0;
}
.camera-hint {
display: none;
}
.view-tools {
right: 12px;
top: 86px;
}
}
@media (max-width: 620px) {
.brand {
top: 10px;
left: 10px;
padding: 8px 10px 8px 8px;
}
.brand-mark {
width: 35px;
height: 35px;
}
.brand-title {
font-size: 11px;
}
.brand-subtitle {
display: none;
}
.challenge {
top: 66px;
left: 10px;
width: calc(100vw - 20px);
max-height: 47vh;
padding: 14px;
border-radius: 16px;
}
h1 {
font-size: 21px;
}
.comparison {
margin: 11px 0;
}
.transport {
padding: 10px;
}
.live-seat {
padding: 5px 1px;
}
.view-tools {
top: auto;
right: 10px;
bottom: 160px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel volleyball rotation scene"></canvas>
<header class="brand panel">
<div class="brand-mark">6</div>
<div>
<div class="brand-title">VOLLEY ROTATION</div>
<div class="brand-subtitle">MODULAR SIX / FIELD LAB</div>
</div>
</header>
<aside class="challenge panel">
<div class="eyebrow">Cyclic permutation puzzle</div>
<h1>Find the modular shift.</h1>
<p class="intro">
Each rotation advances every player by one seat. Determine the shift
<strong>k ∈ ℤ₆</strong> that transforms the puzzle-start lineup into the
target lineup.
</p>
<div class="comparison">
<section class="matrix">
<div class="matrix-title">PUZZLE START <span>seat</span></div>
<div id="startGrid"></div>
</section>
<section class="matrix">
<div class="matrix-title">TARGET <span>seat</span></div>
<div id="targetGrid"></div>
</section>
</div>
<div class="equation">
destination = <b>(origin + k) mod 6</b>
</div>
<label class="input-label" for="prediction">Your prediction</label>
<div class="prediction-row">
<input
id="prediction"
type="text"
inputmode="text"
autocomplete="off"
spellcheck="false"
placeholder="4"
aria-describedby="accepted"
/>
<button id="checkButton" class="primary">Check & rotate</button>
</div>
<div class="actions">
<button id="newButton" class="secondary">New puzzle</button>
<button id="hintButton" class="secondary">Show hint</button>
</div>
<div id="status" role="status" aria-live="polite">
Enter a shift, or use a modular expression.
</div>
<div class="accepted" id="accepted">
Accepted:
<code>4</code>,
<code>k = 4</code>,
<code>x → (x + 4) mod 6</code>, or a destination mapping such as
<code>3,4,5,0,1,2</code>.
</div>
</aside>
<section class="legend panel">
<div class="legend-title">SIX-POSITION RING</div>
<div class="cycle">S0 → S1 → S2 → S3 → S4 → S5 → S0</div>
<div class="role-list">
<div><b>S0</b> Front left</div>
<div><b>S1</b> Front middle</div>
<div><b>S2</b> Front right</div>
<div><b>S3</b> Back right</div>
<div><b>S4</b> Back middle</div>
<div><b>S5</b> Back left</div>
</div>
</section>
<nav class="view-tools" aria-label="Camera views">
<button id="isoView">ISOMETRIC</button>
<button id="topView">TOP</button>
<button id="ringView">RING</button>
</nav>
<section class="transport panel">
<div class="transport-head">
<div class="transport-title">Live rotation</div>
<div class="step-readout" id="stepReadout">0 VISUAL STEPS</div>
</div>
<div class="live-lineup" id="liveLineup"></div>
<div class="transport-actions">
<button id="stepButton" class="secondary">Rotate +1</button>
<button id="autoButton" class="secondary">Auto cycle</button>
<button id="resetButton" class="secondary">Reset lineup</button>
</div>
</section>
<div class="camera-hint">
DRAG TO ORBIT · SHIFT + DRAG TO PAN · SCROLL TO ZOOM
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, lights
// -------------------------------------------------------------------------
const canvas = document.querySelector("#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(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 25, 57);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(1.1, 0.55, 0),
radius: 18.5,
azimuth: -0.62,
polar: 1.02
};
function updateCamera() {
const { target, radius, azimuth, polar } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbfeaff, 0x172237, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.2);
sun.position.set(-7, 14, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x59dfff, 1.3);
rimLight.position.set(9, 7, -10);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0.02) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function box(
width,
height,
depth,
colorOrMaterial,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
colorOrMaterial?.isMaterial
? colorOrMaterial
: material(colorOrMaterial)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, options = {}) {
const {
foreground = "#ffffff",
background = "rgba(5,15,26,0.86)",
border = "rgba(103,232,249,0.35)",
fontSize = 54,
width = 512,
height = 128
} = options;
const textCanvas = document.createElement("canvas");
textCanvas.width = width;
textCanvas.height = height;
const context = textCanvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = background;
context.fillRect(5, 5, width - 10, height - 10);
context.strokeStyle = border;
context.lineWidth = 5;
context.strokeRect(5, 5, width - 10, height - 10);
context.fillStyle = foreground;
context.font = `900 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2 + 2);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(width / 500, height / 500, 1);
return sprite;
}
function shuffle(items) {
const result = [...items];
for (let i = result.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
const delay = milliseconds =>
new Promise(resolve => setTimeout(resolve, milliseconds));
// -------------------------------------------------------------------------
// Voxel volleyball court
// -------------------------------------------------------------------------
const courtGroup = new THREE.Group();
scene.add(courtGroup);
box(19, 0.42, 12.2, 0x14233a, 0, -0.42, 0, courtGroup);
box(18.4, 0.12, 11.5, 0x263b52, 0, -0.18, 0, courtGroup);
const tileColors = [0x225b70, 0x28677a, 0x2d7180, 0x245f73];
for (let ix = 0; ix < 10; ix++) {
for (let iz = 0; iz < 8; iz++) {
const x = -7.2 + ix * 1.6;
const z = -4.2 + iz * 1.2;
const color = tileColors[(ix + iz * 2) % tileColors.length];
box(
1.56,
0.09,
1.16,
color,
x,
-0.065,
z,
courtGroup
);
}
}
const lineMaterial = new THREE.MeshStandardMaterial({
color: 0xf4f1d0,
roughness: 0.75,
emissive: 0x39371f,
emissiveIntensity: 0.12
});
// Outer boundary.
box(16, 0.035, 0.085, lineMaterial, 0, 0.025, -4.8, courtGroup);
box(16, 0.035, 0.085, lineMaterial, 0, 0.025, 4.8, courtGroup);
box(0.085, 0.035, 9.6, lineMaterial, -8, 0.025, 0, courtGroup);
box(0.085, 0.035, 9.6, lineMaterial, 8, 0.025, 0, courtGroup);
// Center and attack lines.
box(0.075, 0.035, 9.6, lineMaterial, 0, 0.03, 0, courtGroup);
box(0.065, 0.035, 9.6, lineMaterial, -1.9, 0.03, 0, courtGroup);
// Voxel center emblem.
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const emblem = box(
0.27,
0.075,
0.27,
i % 2 === 0 ? 0x67e8f9 : 0xb7f36b,
3.25 + Math.cos(angle) * 0.65,
0.045,
Math.sin(angle) * 0.65,
courtGroup
);
emblem.rotation.y = angle;
}
// Net posts and net.
const poleMaterial = material(0xd8e7ed, 0.38, 0.38);
box(0.2, 3.15, 0.2, poleMaterial, 0, 1.5, -5.25, courtGroup);
box(0.2, 3.15, 0.2, poleMaterial, 0, 1.5, 5.25, courtGroup);
box(0.24, 0.22, 10.8, 0xf2f7f8, 0, 2.72, 0, courtGroup);
const netMaterial = material(0xe3f0ee, 0.55, 0.05);
for (let z = -5; z <= 5; z += 0.5) {
box(0.025, 1.65, 0.025, netMaterial, 0, 1.75, z, courtGroup);
}
for (let y = 1.0; y <= 2.45; y += 0.36) {
box(0.025, 0.025, 10, netMaterial, 0, y, 0, courtGroup);
}
// Low voxel bleachers and audience blocks.
box(18.5, 0.42, 1.6, 0x172a43, 0, -0.03, 6.2, courtGroup);
box(18.5, 0.42, 1.6, 0x172a43, 0, -0.03, -6.2, courtGroup);
const audienceColors = [
0xff7387,
0xffb35c,
0xb7f36b,
0x67e8f9,
0x8ea7ff,
0xc493ff
];
for (const side of [-1, 1]) {
for (let row = 0; row < 3; row++) {
box(
18.2,
0.25,
0.46,
0x203652,
0,
0.16 + row * 0.28,
side * (5.65 + row * 0.46),
courtGroup
);
for (let col = 0; col < 15; col++) {
if ((row * 3 + col) % 7 === 0) continue;
const color =
audienceColors[(row * 5 + col * 2) % audienceColors.length];
box(
0.28,
0.3,
0.28,
color,
-8.2 + col * 1.17,
0.43 + row * 0.28,
side * (5.65 + row * 0.46),
courtGroup
);
}
}
}
// Benches on the empty side.
for (const z of [-2.4, 0, 2.4]) {
box(2.3, 0.22, 0.48, 0x7f9daf, -6.2, 0.48, z, courtGroup);
box(0.18, 0.5, 0.35, 0x4d677b, -7.15, 0.23, z, courtGroup);
box(0.18, 0.5, 0.35, 0x4d677b, -5.25, 0.23, z, courtGroup);
}
// -------------------------------------------------------------------------
// Six-position ring and voxel players
// -------------------------------------------------------------------------
const seatPositions = [
new THREE.Vector3(1.35, 0, -2.7), // S0 front-left
new THREE.Vector3(1.35, 0, 0), // S1 front-middle
new THREE.Vector3(1.35, 0, 2.7), // S2 front-right
new THREE.Vector3(5.1, 0, 2.7), // S3 back-right
new THREE.Vector3(5.1, 0, 0), // S4 back-middle
new THREE.Vector3(5.1, 0, -2.7) // S5 back-left
];
const seatNames = [
"FRONT LEFT",
"FRONT MIDDLE",
"FRONT RIGHT",
"BACK RIGHT",
"BACK MIDDLE",
"BACK LEFT"
];
const ringPoints = seatPositions.map(point => point.clone());
ringPoints.push(seatPositions[0].clone());
const ringGeometry = new THREE.BufferGeometry().setFromPoints(ringPoints);
const ringMaterial = new THREE.LineDashedMaterial({
color: 0x67e8f9,
transparent: true,
opacity: 0.48,
dashSize: 0.18,
gapSize: 0.12
});
const ringLine = new THREE.Line(ringGeometry, ringMaterial);
ringLine.position.y = 0.09;
ringLine.computeLineDistances();
scene.add(ringLine);
seatPositions.forEach((position, index) => {
box(
1.03,
0.075,
1.03,
index % 2 === 0 ? 0x123449 : 0x153d4b,
position.x,
0.015,
position.z
);
box(
0.16,
0.035,
0.86,
0x67e8f9,
position.x,
0.065,
position.z
);
const label = makeTextSprite(`S${index}`, {
foreground: "#dffaff",
background: "rgba(5,17,29,0.78)",
border: "rgba(103,232,249,0.28)",
fontSize: 58
});
label.scale.set(0.58, 0.145, 1);
label.position.set(position.x, 0.2, position.z);
scene.add(label);
});
// Central rotating direction marker.
const rotationMarker = new THREE.Group();
rotationMarker.position.set(3.25, 0.13, 0);
scene.add(rotationMarker);
for (let index = 0; index < 4; index++) {
const arrow = new THREE.Group();
const angle = (index / 4) * Math.PI * 2;
arrow.position.set(Math.cos(angle) * 0.95, 0, Math.sin(angle) * 0.95);
arrow.rotation.y = -angle;
box(
0.32,
0.07,
0.09,
0xb7f36b,
0.12,
0,
0,
arrow
);
box(
0.14,
0.07,
0.09,
0xb7f36b,
-0.06,
0,
0.09,
arrow
).rotation.y = -Math.PI / 4;
box(
0.14,
0.07,
0.09,
0xb7f36b,
-0.06,
0,
-0.09,
arrow
).rotation.y = Math.PI / 4;
rotationMarker.add(arrow);
}
const playerColors = [
0xff7387,
0xffb35c,
0xb7f36b,
0x67e8f9,
0x8ea7ff,
0xc493ff
];
const players = new Map();
function createPlayer(id) {
const group = new THREE.Group();
const color = playerColors[(id - 1) % playerColors.length];
const jerseyMaterial = material(color, 0.76);
const darkMaterial = material(0x17253a);
const skinMaterial = material(id % 2 ? 0xc88e68 : 0xa86f4e);
const shoeMaterial = material(0xf4f1e8);
const hairMaterial = material(id % 3 === 0 ? 0x442b25 : 0x20212a);
// Shoes and legs.
box(0.25, 0.15, 0.38, shoeMaterial, -0.16, 0.08, -0.035, group);
box(0.25, 0.15, 0.38, shoeMaterial, 0.16, 0.08, -0.035, group);
box(0.23, 0.48, 0.25, darkMaterial, -0.16, 0.39, 0, group);
box(0.23, 0.48, 0.25, darkMaterial, 0.16, 0.39, 0, group);
// Torso and jersey band.
box(0.64, 0.65, 0.4, jerseyMaterial, 0, 0.93, 0, group);
box(0.66, 0.1, 0.42, 0xf7fbff, 0, 0.76, 0, group);
// Arms.
box(0.19, 0.55, 0.22, jerseyMaterial, -0.43, 0.94, 0, group);
box(0.19, 0.55, 0.22, jerseyMaterial, 0.43, 0.94, 0, group);
box(0.2, 0.17, 0.21, skinMaterial, -0.43, 0.62, 0, group);
box(0.2, 0.17, 0.21, skinMaterial, 0.43, 0.62, 0, group);
// Head, hair, and simple face.
box(0.47, 0.44, 0.43, skinMaterial, 0, 1.47, 0, group);
box(0.5, 0.13, 0.45, hairMaterial, 0, 1.72, 0.015, group);
box(0.055, 0.055, 0.03, 0x101722, -0.11, 1.49, -0.225, group);
box(0.055, 0.055, 0.03, 0x101722, 0.11, 1.49, -0.225, group);
const label = makeTextSprite(`P${id}`, {
foreground: "#07111f",
background: `#${color.toString(16).padStart(6, "0")}`,
border: "rgba(255,255,255,0.7)",
fontSize: 64,
width: 256,
height: 128
});
label.scale.set(0.52, 0.26, 1);
label.position.set(0, 1.02, -0.29);
group.add(label);
group.userData.slot = 0;
scene.add(group);
players.set(id, group);
return group;
}
for (let id = 1; id <= 6; id++) {
createPlayer(id);
}
// Floating voxel volleyball.
const volleyball = new THREE.Group();
box(0.45, 0.45, 0.45, 0xf7f2df, 0, 0, 0, volleyball);
const stripeA = material(0x67e8f9);
const stripeB = material(0xffb35c);
box(0.46, 0.09, 0.09, stripeA, 0, 0.08, -0.225, volleyball);
box(0.09, 0.46, 0.09, stripeB, 0.08, 0, -0.225, volleyball);
box(0.09, 0.09, 0.46, stripeA, 0.225, 0.08, 0, volleyball);
volleyball.position.set(-1.4, 3.5, 1.2);
scene.add(volleyball);
// In-world court label.
const courtLabel = makeTextSprite("ROTATION / MOD 6", {
foreground: "#c9f7ff",
background: "rgba(7,17,31,0.82)",
border: "rgba(103,232,249,0.3)",
fontSize: 42
});
courtLabel.scale.set(2.6, 0.65, 1);
courtLabel.position.set(-5.9, 2.25, -5.7);
scene.add(courtLabel);
// -------------------------------------------------------------------------
// Puzzle state
// -------------------------------------------------------------------------
let baselineOrder = [];
let targetOrder = [];
let liveOrder = [];
let actualShift = 0;
let visualSteps = 0;
let verifying = false;
let activeTween = null;
let autoTimer = null;
const startGrid = document.querySelector("#startGrid");
const targetGrid = document.querySelector("#targetGrid");
const liveLineup = document.querySelector("#liveLineup");
const predictionInput = document.querySelector("#prediction");
const statusBox = document.querySelector("#status");
const stepReadout = document.querySelector("#stepReadout");
const checkButton = document.querySelector("#checkButton");
const newButton = document.querySelector("#newButton");
const autoButton = document.querySelector("#autoButton");
function playerColorCss(id) {
return `#${playerColors[(id - 1) % playerColors.length].toString(16).padStart(6, "0")}`;
}
function seatToken(id, small = false) {
return `
<span class="token${small ? " small" : ""}" style="background:${playerColorCss(id)}">
P${id}
</span>
`;
}
function renderLineupGrid(container, order) {
container.innerHTML = order
.map(
(id, index) => `
<div class="seat-row">
<span class="seat-code">S${index}</span>
${seatToken(id)}
</div>
`
)
.join("");
}
function renderLiveLineup() {
liveLineup.innerHTML = liveOrder
.map(
(id, index) => `
<div class="live-seat">
<small>S${index}</small>
${seatToken(id, true)}
</div>
`
)
.join("");
stepReadout.textContent = `${visualSteps} VISUAL STEP${visualSteps === 1 ? "" : "S"}`;
}
function resetLineup() {
liveOrder = [...baselineOrder];
liveOrder.forEach((id, slot) => {
const player = players.get(id);
player.position.copy(seatPositions[slot]);
player.userData.slot = slot;
});
visualSteps = 0;
renderLiveLineup();
}
function newPuzzle() {
stopAuto();
baselineOrder = shuffle([1, 2, 3, 4, 5, 6]);
actualShift = 1 + Math.floor(Math.random() * 5);
targetOrder = Array(6);
baselineOrder.forEach((id, origin) => {
targetOrder[(origin + actualShift) % 6] = id;
});
renderLineupGrid(startGrid, baselineOrder);
renderLineupGrid(targetGrid, targetOrder);
resetLineup();
predictionInput.value = "";
statusBox.className = "";
statusBox.textContent =
"Compare the two seat-by-seat lineups. Enter the modular shift k.";
checkButton.disabled = false;
newButton.disabled = false;
}
// -------------------------------------------------------------------------
// Modular expression parser
// -------------------------------------------------------------------------
function parsePrediction(rawValue) {
const raw = rawValue.trim().toLowerCase();
if (!raw) {
throw new Error("Enter a prediction first.");
}
const normalized = raw
.replace(/→/g, "->")
.replace(/≡/g, "=")
.replace(/−/g, "-")
.replace(/\s+/g, " ");
// Destination mapping: origin-seat -> destination-seat.
if (normalized.includes(",")) {
const parts = normalized.split(",").map(part => part.trim());
if (parts.length === 6 && parts.every(part => /^-?\d+$/.test(part))) {
const mapping = parts.map(part => Number(part));
if (mapping.every(value => value >= 0 && value < 6)) {
return { type: "mapping", mapping };
}
throw new Error("Every destination in a mapping must be in 0…5.");
}
if (parts.length === 1 && /^-?\d+$/.test(parts[0])) {
return { type: "shift", shift: normalizeShift(Number(parts[0])) };
}
throw new Error("Use six comma-separated destinations or one shift value.");
}
// k = 4
const kMatch = normalized.match(/^k\s*=\s*(-?\d+)$/);
if (kMatch) {
return { type: "shift", shift: normalizeShift(Number(kMatch[1])) };
}
// (x + 4) mod 6 or (x - 2) % 6
const formulaMatch = normalized.match(
/x\s*(?:->|=>|=)?\s*\(\s*x\s*([+-])\s*(\d+)\s*\)\s*(?:mod|%)\s*6/
);
if (formulaMatch) {
const amount = Number(formulaMatch[2]);
const sign = formulaMatch[1] === "-" ? -1 : 1;
return { type: "shift", shift: normalizeShift(sign * amount) };
}
// x + 4 mod 6, x - 2, and similar forms.
const compactFormulaMatch = normalized.match(
/x\s*(?:->|=>|=)?\s*x?\s*([+-])\s*(\d+)\s*(?:mod\s*6|%6)?/
);
if (compactFormulaMatch) {
const amount = Number(compactFormulaMatch[2]);
const sign = compactFormulaMatch[1] === "-" ? -1 : 1;
return { type: "shift", shift: normalizeShift(sign * amount) };
}
// A single integer is interpreted as k.
if (/^-?\d+$/.test(normalized)) {
return { type: "shift", shift: normalizeShift(Number(normalized)) };
}
throw new Error(
"Use a value such as 4, k = 4, or x → (x + 4) mod 6."
);
}
function normalizeShift(value) {
return ((value % 6) + 6) % 6;
}
function expectedMapping(shift) {
return Array.from({ length: 6 }, (_, origin) => (origin + shift) % 6);
}
function mappingsMatch(a, b) {
return a.length === b.length && a.every((value, index) => value === b[index]);
}
// -------------------------------------------------------------------------
// Step animation
// -------------------------------------------------------------------------
function animateStep(duration = 760) {
if (activeTween) {
return Promise.resolve(false);
}
const fromOrder = [...liveOrder];
const moves = fromOrder.map((id, origin) => {
const player = players.get(id);
const target = seatPositions[(origin + 1) % 6].clone();
return {
id,
player,
from: player.position.clone(),
to: target,
dx: target.x - player.position.x,
dz: target.z - player.position.z
};
});
return new Promise(resolve => {
activeTween = {
elapsed: 0,
duration,
moves,
resolve
};
});
}
async function performStep(duration = 760) {
const completed = await animateStep(duration);
if (completed) {
const previous = [...liveOrder];
liveOrder = Array(6);
previous.forEach((id, origin) => {
const destination = (origin + 1) % 6;
liveOrder[destination] = id;
players.get(id).userData.slot = destination;
});
visualSteps += 1;
renderLiveLineup();
}
return completed;
}
function updateTween(deltaTime) {
if (!activeTween) return;
const tween = activeTween;
tween.elapsed += deltaTime * 1000;
const rawProgress = Math.min(tween.elapsed / tween.duration, 1);
const eased =
rawProgress < 0.5
? 4 * rawProgress * rawProgress * rawProgress
: 1 - Math.pow(-2 * rawProgress + 2, 3) / 2;
tween.moves.forEach(move => {
move.player.position.lerpVectors(move.from, move.to, eased);
move.player.position.y = Math.sin(rawProgress * Math.PI) * 0.22;
if (Math.abs(move.dx) + Math.abs(move.dz) > 0.001) {
move.player.rotation.y = Math.atan2(move.dx, move.dz);
}
});
rotationMarker.rotation.y = rawProgress * Math.PI * 0.66;
ringMaterial.opacity = 0.46 + Math.sin(rawProgress * Math.PI) * 0.42;
if (rawProgress >= 1) {
tween.moves.forEach(move => {
move.player.position.copy(move.to);
move.player.position.y = 0;
});
activeTween = null;
tween.resolve(true);
}
}
// -------------------------------------------------------------------------
// Verification
// -------------------------------------------------------------------------
async function verifyPrediction() {
if (verifying) return;
let parsed;
try {
parsed = parsePrediction(predictionInput.value);
} catch (error) {
statusBox.className = "bad";
statusBox.textContent = error.message;
return;
}
const expected = expectedMapping(actualShift);
const predictionCorrect =
parsed.type === "shift"
? parsed.shift === actualShift
: mappingsMatch(parsed.mapping, expected);
verifying = true;
stopAuto();
checkButton.disabled = true;
newButton.disabled = true;
// Verification always starts from the defined puzzle-start lineup.
resetLineup();
statusBox.className = "running";
statusBox.textContent = predictionCorrect
? `Prediction accepted. Verifying with ${actualShift} visual rotation step${actualShift === 1 ? "" : "s"}…`
: "Prediction differs from the target. Running the target route to verify…";
for (let step = 1; step <= actualShift; step++) {
statusBox.textContent = predictionCorrect
? `Prediction accepted · visual step ${step} / ${actualShift}`
: `Route verification · visual step ${step} / ${actualShift}`;
await performStep(760);
await delay(150);
}
const routeCorrect = liveOrder.every(
(id, index) => id === targetOrder[index]
);
if (predictionCorrect && routeCorrect) {
statusBox.className = "good";
statusBox.textContent =
`Correct. The modular shift is k = ${actualShift}; destination = (origin + ${actualShift}) mod 6. The animated route matches the target.`;
} else {
statusBox.className = "bad";
statusBox.textContent =
`The visual route reached the target using k = ${actualShift}. Your prediction was not equivalent to that shift.`;
}
verifying = false;
checkButton.disabled = false;
newButton.disabled = false;
}
// -------------------------------------------------------------------------
// Auto rotation and UI events
// -------------------------------------------------------------------------
function stopAuto() {
if (autoTimer !== null) {
clearInterval(autoTimer);
autoTimer = null;
}
autoButton.textContent = "Auto cycle";
autoButton.style.borderColor = "";
autoButton.style.color = "";
}
function toggleAuto() {
if (autoTimer !== null) {
stopAuto();
return;
}
if (verifying) return;
autoTimer = setInterval(() => {
if (!activeTween && !verifying) {
performStep(680);
}
}, 1050);
autoButton.textContent = "Stop cycle";
autoButton.style.borderColor = "rgba(103,232,249,0.45)";
autoButton.style.color = "#67e8f9";
statusBox.className = "";
statusBox.textContent =
"Exploration mode: the live lineup is rotating. Check & rotate will reset it to the puzzle start.";
}
predictionInput.addEventListener("keydown", event => {
if (event.key === "Enter") {
verifyPrediction();
}
});
checkButton.addEventListener("click", verifyPrediction);
newButton.addEventListener("click", () => {
if (!verifying) newPuzzle();
});
document.querySelector("#hintButton").addEventListener("click", () => {
if (verifying) return;
const targetByPlayer = new Map();
targetOrder.forEach((id, seat) => targetByPlayer.set(id, seat));
const shiftForPlayer1 =
(targetByPlayer.get(baselineOrder[0]) - 0 + 6) % 6;
statusBox.className = "";
statusBox.textContent =
`Hint: follow the player that began in S0. In the target lineup, P${baselineOrder[0]} occupies S${targetByPlayer.get(baselineOrder[0])}, so k = ${shiftForPlayer1}.`;
});
document.querySelector("#stepButton").addEventListener("click", async () => {
if (verifying || activeTween) return;
await performStep();
statusBox.className = "";
statusBox.textContent =
"Exploration mode: the live lineup moved one seat. Check & rotate resets to the puzzle start.";
});
autoButton.addEventListener("click", toggleAuto);
document.querySelector("#resetButton").addEventListener("click", () => {
if (verifying) return;
stopAuto();
resetLineup();
statusBox.className = "";
statusBox.textContent =
"Live lineup reset to the puzzle-start permutation.";
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let shiftedPointer = false;
canvas.addEventListener("pointerdown", event => {
dragging = true;
shiftedPointer = event.shiftKey;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (event.shiftKey || shiftedPointer) {
cameraState.target.x -= deltaX * 0.012;
cameraState.target.z += deltaY * 0.012;
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-8,
8
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-7,
7
);
} else {
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + deltaY * 0.005,
0.12,
1.38
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
shiftedPointer = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8,
31
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#isoView").addEventListener("click", () => {
cameraState.target.set(1.1, 0.55, 0);
cameraState.radius = 18.5;
cameraState.azimuth = -0.62;
cameraState.polar = 1.02;
updateCamera();
});
document.querySelector("#topView").addEventListener("click", () => {
cameraState.target.set(1.1, 0, 0);
cameraState.radius = 19;
cameraState.azimuth = 0;
cameraState.polar = 0.09;
updateCamera();
});
document.querySelector("#ringView").addEventListener("click", () => {
cameraState.target.set(3.2, 0.45, 0);
cameraState.radius = 11.5;
cameraState.azimuth = -0.48;
cameraState.polar = 1.08;
updateCamera();
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const deltaTime = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateTween(deltaTime);
if (!activeTween) {
rotationMarker.rotation.y += deltaTime * 0.16;
ringMaterial.opacity = 0.42 + Math.sin(elapsed * 1.6) * 0.07;
}
volleyball.position.y = 3.5 + Math.sin(elapsed * 1.45) * 0.22;
volleyball.rotation.x = elapsed * 0.55;
volleyball.rotation.y = elapsed * 0.8;
renderer.render(scene, camera);
}
newPuzzle();
animate();
</script>
</body>
</html>
```