Prompt specification
Build or customize the Three.js 3D scene "Find the Invalid Score Transition" 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: Find the Invalid Score Transition
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/find-the-invalid-score-transition-x3652
Scene Description Prompt:
Find the invalid score transition. Create a puzzle comparing a legal scoring sequence with one impossible transition under a stated ruleset. Explain the violated state rule rather than relying on memorized labels. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (find-the-invalid-score-transition-x3652):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Broken Score Transition</title>
<style>
:root {
color-scheme: dark;
--bg: #07151c;
--panel: rgba(10, 29, 38, 0.92);
--panel-border: rgba(173, 218, 226, 0.16);
--text: #e7f1f2;
--muted: #9bb2b8;
--blue: #45c4ef;
--orange: #ff805b;
--gold: #ffd166;
--green: #62dfa7;
--red: #ff6072;
}
* {
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 {
font: inherit;
}
[hidden] {
display: none !important;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.brand {
position: absolute;
z-index: 5;
top: 20px;
left: 50%;
width: min(560px, calc(100vw - 760px));
transform: translateX(-50%);
text-align: center;
pointer-events: none;
}
.brand .eyebrow {
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 5px 0 4px;
font-size: clamp(22px, 2.4vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 13px;
}
.panel {
position: absolute;
z-index: 4;
border: 1px solid var(--panel-border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
}
#rules {
top: 20px;
left: 20px;
width: 315px;
max-height: calc(100vh - 40px);
padding: 20px;
overflow: auto;
}
#ledger {
top: 20px;
right: 20px;
bottom: 20px;
width: 355px;
padding: 18px;
overflow: auto;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h2 {
margin: 5px 0 12px;
font-size: 20px;
letter-spacing: -0.025em;
}
.rules-list {
margin: 0;
padding-left: 20px;
color: #c8d9dc;
font-size: 13px;
line-height: 1.55;
}
.rules-list li + li {
margin-top: 7px;
}
.state-rule {
margin-top: 14px;
padding: 12px;
border: 1px solid rgba(69, 196, 239, 0.24);
border-radius: 11px;
background: rgba(69, 196, 239, 0.07);
color: #d9edf1;
font-size: 12px;
line-height: 1.55;
}
.state-rule strong {
display: block;
margin-bottom: 4px;
color: var(--blue);
letter-spacing: 0.04em;
}
.state-rule code {
color: #fff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.tiny-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.question {
margin: 0 0 12px;
color: #c8d9dc;
font-size: 13px;
line-height: 1.45;
}
.choices {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.choice {
min-height: 64px;
padding: 9px;
border: 1px solid rgba(173, 218, 226, 0.15);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.choice:hover {
border-color: rgba(255, 209, 102, 0.52);
background: rgba(255, 209, 102, 0.06);
transform: translateY(-1px);
}
.choice.selected {
border-color: var(--gold);
background: rgba(255, 209, 102, 0.1);
box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.2);
}
.choice.valid {
border-color: rgba(98, 223, 167, 0.6);
background: rgba(98, 223, 167, 0.08);
}
.choice.invalid {
border-color: rgba(255, 96, 114, 0.75);
background: rgba(255, 96, 114, 0.11);
}
.choice-no {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.state-pair {
display: flex;
align-items: center;
gap: 5px;
white-space: nowrap;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.state-pair .arrow {
color: var(--muted);
}
.harbor {
color: var(--blue);
}
.ember {
color: var(--orange);
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 12px;
}
.primary,
.secondary,
.view-button {
border: 0;
border-radius: 10px;
cursor: pointer;
font-weight: 800;
}
.primary {
padding: 11px 14px;
background: var(--gold);
color: #172026;
transition: filter 150ms ease, opacity 150ms ease;
}
.primary:hover:not(:disabled) {
filter: brightness(1.08);
}
.primary:disabled {
cursor: not-allowed;
opacity: 0.35;
}
.secondary {
padding: 9px 11px;
border: 1px solid rgba(173, 218, 226, 0.18);
background: rgba(255, 255, 255, 0.04);
color: var(--text);
font-size: 11px;
}
.feedback {
min-height: 50px;
margin-top: 12px;
padding: 11px 12px;
border: 1px solid rgba(173, 218, 226, 0.14);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: #c8d9dc;
font-size: 12px;
line-height: 1.5;
}
.feedback.success {
border-color: rgba(98, 223, 167, 0.52);
background: rgba(98, 223, 167, 0.08);
}
.feedback.warn {
border-color: rgba(255, 209, 102, 0.45);
background: rgba(255, 209, 102, 0.07);
}
.feedback strong {
color: var(--text);
}
.comparison {
margin-top: 12px;
padding: 12px;
border: 1px solid rgba(98, 223, 167, 0.3);
border-radius: 12px;
background: rgba(98, 223, 167, 0.045);
font-size: 11px;
line-height: 1.6;
}
.comparison h3 {
margin: 0 0 8px;
font-size: 12px;
}
.comparison .chain {
margin-bottom: 11px;
color: #d8eeee;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.8;
}
.comparison .broken {
color: #ffb0ba;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.view-controls {
position: absolute;
z-index: 5;
bottom: 18px;
left: 50%;
display: flex;
gap: 6px;
padding: 6px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 12px;
background: rgba(8, 24, 31, 0.82);
backdrop-filter: blur(10px);
}
.view-button {
padding: 8px 11px;
background: transparent;
color: #c9dadd;
font-size: 11px;
}
.view-button:hover {
background: rgba(255, 255, 255, 0.07);
color: #fff;
}
.legend {
position: absolute;
z-index: 4;
bottom: 21px;
left: 20px;
display: flex;
gap: 13px;
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 10px currentColor;
}
.dot.blue {
color: var(--blue);
background: var(--blue);
}
.dot.orange {
color: var(--orange);
background: var(--orange);
}
@media (max-width: 920px) {
body {
overflow: auto;
}
#app {
min-height: 100vh;
height: auto;
}
#scene {
position: fixed;
}
.brand {
position: fixed;
top: 12px;
left: 12px;
width: calc(100vw - 24px);
transform: none;
text-align: left;
}
.brand p {
display: none;
}
.panel {
position: relative;
inset: auto;
width: auto;
max-height: none;
margin: 12px;
}
#rules {
margin-top: 78px;
}
#ledger {
margin-bottom: 70px;
}
.choices {
grid-template-columns: repeat(3, 1fr);
}
.legend {
display: none;
}
.view-controls {
position: fixed;
}
}
@media (max-width: 560px) {
.choices {
grid-template-columns: 1fr 1fr;
}
.brand h1 {
font-size: 22px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive three-dimensional score ledger"></div>
<header class="brand">
<div class="eyebrow">State Logic Puzzle</div>
<h1>Find the Broken Transition</h1>
<p>Six links connect seven score states. Exactly one link is impossible.</p>
</header>
<section id="rules" class="panel" aria-labelledby="rules-title">
<div class="eyebrow">Stated Ruleset</div>
<h2 id="rules-title">Harbor–Ember scoring</h2>
<ol class="rules-list">
<li>The match starts at <strong>(0, 0)</strong>.</li>
<li>Each scoring event adds exactly <strong>2 or 3 points</strong>.</li>
<li>An event changes exactly <strong>one team</strong>; the other score stays fixed.</li>
<li>Scores never decrease.</li>
</ol>
<div class="state-rule">
<strong>Formal state rule</strong>
A transition from <code>s = (H, E)</code> to <code>s′ = (H′, E′)</code>
is legal only when
<code>s′ − s</code> is one of
<code>(2,0), (3,0), (0,2), (0,3)</code>.
</div>
<p class="tiny-note">
No named plays or memorized labels are needed. Inspect how the ordered
pair of scores changes from one state to the next.
</p>
</section>
<section id="ledger" class="panel" aria-labelledby="ledger-title">
<div class="eyebrow">Transition Ledger</div>
<h2 id="ledger-title">Choose one link</h2>
<p class="question">
Select a transition and test it against the state rule. You can also
click a numbered diamond on the 3D board.
</p>
<div id="choices" class="choices"></div>
<div class="actions">
<button id="check" class="primary" type="button" disabled>
Check transition
</button>
<button id="reset" class="secondary" type="button">
Reset
</button>
</div>
<div
id="feedback"
class="feedback"
role="status"
aria-live="polite"
>
Choose a link to begin.
</div>
<div id="comparison" class="comparison" hidden>
<h3>Legal sequence compared with the impossible transition</h3>
<div class="chain">
<strong>Five legal events:</strong><br>
(0,0) → (2,0) → (2,3) → (5,3) → (5,5) → (8,5)
</div>
<div class="chain">
<strong>Legal changes:</strong><br>
(2,0), (0,3), (3,0), (0,2), (3,0)
</div>
<div class="broken">
<strong>Impossible link:</strong><br>
(8,5) → (8,9)<br>
Δ = (0,4), which is not an allowed event.
</div>
</div>
</section>
<div class="legend" aria-hidden="true">
<span><i class="dot blue"></i> Harbor score</span>
<span><i class="dot orange"></i> Ember score</span>
</div>
<nav class="view-controls" aria-label="Camera controls">
<button id="reset-view" class="view-button" type="button">
Reset view
</button>
<button id="top-view" class="view-button" type="button">
Top view
</button>
</nav>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Puzzle data
// -------------------------------------------------------------------------
const states = [
{ h: 0, e: 0 },
{ h: 2, e: 0 },
{ h: 2, e: 3 },
{ h: 5, e: 3 },
{ h: 5, e: 5 },
{ h: 8, e: 5 },
{ h: 8, e: 9 }
];
const transitions = states.slice(0, -1).map((from, index) => ({
index,
from,
to: states[index + 1]
}));
const invalidIndex = 5;
const colors = {
background: 0x07151c,
platform: 0x102a33,
platformEdge: 0x1a3b45,
blue: 0x45c4ef,
blueDark: 0x167b9d,
orange: 0xff805b,
orangeDark: 0xb8402e,
neutral: 0x80979e,
neutralBright: 0xc6dadd,
gold: 0xffd166,
green: 0x62dfa7,
red: 0xff6072
};
const selectedTransitions = new Set([5]);
const legalDeltas = new Set(["2,0", "3,0", "0,2", "0,3"]);
function deltaKey(transition) {
return [
transition.to.h - transition.from.h,
transition.to.e - transition.from.e
].join(",");
}
function isLegal(transition) {
return legalDeltas.has(deltaKey(transition));
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(sceneHost.clientWidth, sceneHost.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional score transition puzzle. Drag to orbit and scroll to zoom."
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(colors.background);
scene.fog = new THREE.Fog(colors.background, 18, 33);
const camera = new THREE.PerspectiveCamera(
44,
sceneHost.clientWidth / sceneHost.clientHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
const orbit = {
theta: 0,
phi: 0.88,
radius: 16.5
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const hemisphere = new THREE.HemisphereLight(
0xbfefff,
0x132027,
1.55
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.3);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x45c4ef, 22, 20, 2);
rimLight.position.set(-8, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff805b, 18, 18, 2);
warmLight.position.set(8, 4, -3);
scene.add(warmLight);
const standardMaterial = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.08,
flatShading: true,
...extra
});
const platformMaterial = standardMaterial(colors.platform);
const platformEdgeMaterial = standardMaterial(colors.platformEdge);
const blueMaterial = standardMaterial(colors.blue, {
emissive: 0x073847,
emissiveIntensity: 0.35
});
const blueDarkMaterial = standardMaterial(colors.blueDark);
const orangeMaterial = standardMaterial(colors.orange, {
emissive: 0x46170d,
emissiveIntensity: 0.35
});
const orangeDarkMaterial = standardMaterial(colors.orangeDark);
function addMesh(geometry, material, position, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Main low-poly board.
addMesh(
new THREE.BoxGeometry(20, 0.34, 4.25),
platformMaterial,
new THREE.Vector3(0, -0.2, 0)
);
addMesh(
new THREE.BoxGeometry(20.4, 0.12, 4.55),
platformEdgeMaterial,
new THREE.Vector3(0, -0.39, 0)
);
for (const z of [-2.05, 2.05]) {
addMesh(
new THREE.BoxGeometry(20, 0.12, 0.12),
platformEdgeMaterial,
new THREE.Vector3(0, 0.02, z)
);
}
// Triangular supports emphasize the low-poly construction.
for (const x of [-8.6, -3, 3, 8.6]) {
const support = addMesh(
new THREE.ConeGeometry(0.72, 1.15, 3),
platformEdgeMaterial,
new THREE.Vector3(x, -0.9, 0)
);
support.rotation.y = Math.PI / 6;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeStateTexture(h, e) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 4, 4, 504, 120, 24);
ctx.fillStyle = "rgba(5, 18, 24, 0.93)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = "rgba(198, 218, 221, 0.32)";
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 48px system-ui, sans-serif";
ctx.fillStyle = "#45c4ef";
ctx.fillText(`H ${h}`, 150, 65);
ctx.fillStyle = "#69848b";
ctx.fillText("•", 256, 63);
ctx.fillStyle = "#ff805b";
ctx.fillText(`E ${e}`, 362, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeTextSprite(text, foreground = "#d8e8ea", background = "#102a33") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
ctx.beginPath();
ctx.arc(128, 128, 105, 0, Math.PI * 2);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = foreground;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "900 105px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 135);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.48, 0.48, 1);
sprite.renderOrder = 5;
return sprite;
}
function makeTeamLabel(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 4, 4, 504, 104, 22);
ctx.fillStyle = "rgba(6, 20, 26, 0.9)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "900 52px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 58);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.2, 0.48, 1);
sprite.renderOrder = 5;
return sprite;
}
function createScoreStack(score, x, z, primary, secondary, team) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const plate = addMesh(
new THREE.BoxGeometry(0.72, 0.07, 0.72),
team === "harbor" ? blueDarkMaterial : orangeDarkMaterial,
new THREE.Vector3(0, 0.035, 0),
group
);
plate.castShadow = false;
const blockHeight = 0.145;
const blockPitch = 0.175;
for (let point = 0; point < score; point++) {
const material = point % 2 === 0 ? primary : secondary;
const block = addMesh(
new THREE.BoxGeometry(0.46, blockHeight, 0.46),
material,
new THREE.Vector3(0, 0.1 + point * blockPitch, 0),
group
);
block.rotation.y = point % 2 === 0 ? 0.025 : -0.025;
}
}
function createTotem(x, team, color, label) {
const group = new THREE.Group();
group.position.set(x, 0, -0.15);
scene.add(group);
const isHarbor = team === "harbor";
const primary = isHarbor ? blueMaterial : orangeMaterial;
const secondary = isHarbor ? blueDarkMaterial : orangeDarkMaterial;
addMesh(
new THREE.CylinderGeometry(0.73, 0.84, 0.34, 6),
secondary,
new THREE.Vector3(0, 0.17, 0),
group
);
const crystal = addMesh(
new THREE.IcosahedronGeometry(0.68, 0),
primary,
new THREE.Vector3(0, 1.05, 0),
group
);
crystal.rotation.set(0.2, 0.35, 0.08);
addMesh(
new THREE.ConeGeometry(0.34, 0.6, 5),
secondary,
new THREE.Vector3(0, 1.78, 0),
group
);
const sprite = makeTeamLabel(label, isHarbor ? "#45c4ef" : "#ff805b");
sprite.position.set(0, 2.28, 0);
group.add(sprite);
}
createTotem(-9.35, "harbor", colors.blue, "HARBOR");
createTotem(9.35, "ember", colors.orange, "EMBER");
const stationX = (index) => -7.5 + index * 2.5;
states.forEach((state, index) => {
const x = stationX(index);
createScoreStack(
state.h,
x,
-0.62,
blueMaterial,
blueDarkMaterial,
"harbor"
);
createScoreStack(
state.e,
x,
0.62,
orangeMaterial,
orangeDarkMaterial,
"ember"
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(1.78, 0.45),
new THREE.MeshBasicMaterial({
map: makeStateTexture(state.h, state.e),
transparent: true,
side: THREE.DoubleSide
})
);
plaque.rotation.x = -Math.PI / 2;
plaque.position.set(x, 0.035, 1.48);
scene.add(plaque);
});
function cylinderBetween(start, end, radius, material) {
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const markerEntries = [];
const hitTargets = [];
transitions.forEach((transition, index) => {
const startX = stationX(index) + 0.5;
const endX = stationX(index + 1) - 0.5;
const rodMaterial = standardMaterial(colors.neutral, {
emissive: 0x102028,
emissiveIntensity: 0.25
});
const rod = cylinderBetween(
new THREE.Vector3(startX, 0.18, 0),
new THREE.Vector3(endX, 0.18, 0),
0.045,
rodMaterial
);
const group = new THREE.Group();
group.position.set((startX + endX) / 2, 0.43, 0);
scene.add(group);
const markerMaterial = standardMaterial(colors.neutralBright, {
emissive: 0x14262d,
emissiveIntensity: 0.3
});
const marker = addMesh(
new THREE.DodecahedronGeometry(0.24, 0),
markerMaterial,
new THREE.Vector3(0, 0, 0),
group
);
marker.userData.transitionIndex = index;
const number = makeTextSprite(String(index + 1), "#f1f7f8", "#142a33");
number.position.set(0, 0.43, 0.03);
group.add(number);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.022, 6, 28),
new THREE.MeshBasicMaterial({
color: colors.gold,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
ring.visible = false;
ring.renderOrder = 4;
group.add(ring);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitArea = new THREE.Mesh(
new THREE.SphereGeometry(0.43, 8, 6),
hitMaterial
);
hitArea.userData.transitionIndex = index;
group.add(hitArea);
hitTargets.push(hitArea);
markerEntries.push({
group,
marker,
markerMaterial,
ring,
rod,
rodMaterial
});
});
// -------------------------------------------------------------------------
// UI and selection
// -------------------------------------------------------------------------
const choicesHost = document.querySelector("#choices");
const checkButton = document.querySelector("#check");
const resetButton = document.querySelector("#reset");
const feedback = document.querySelector("#feedback");
const comparison = document.querySelector("#comparison");
let selectedIndex = null;
let solved = false;
const choiceButtons = [];
transitions.forEach((transition, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "choice";
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="choice-no">Link ${index + 1}</span>
<span class="state-pair">
<span class="harbor">H ${transition.from.h}</span>
<span class="arrow">·</span>
<span class="ember">E ${transition.from.e}</span>
<span class="arrow">→</span>
<span class="harbor">H ${transition.to.h}</span>
<span class="arrow">·</span>
<span class="ember">E ${transition.to.e}</span>
</span>
`;
button.addEventListener("click", () => selectTransition(index));
choicesHost.appendChild(button);
choiceButtons.push(button);
});
function selectTransition(index) {
if (solved) return;
selectedIndex = index;
choiceButtons.forEach((button, i) => {
const selected = i === index;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
markerEntries.forEach((entry, i) => {
const selected = i === index;
entry.markerMaterial.color.set(
selected ? colors.gold : colors.neutralBright
);
entry.markerMaterial.emissive.set(
selected ? 0x6b4a00 : 0x14262d
);
entry.markerMaterial.emissiveIntensity = selected ? 0.72 : 0.3;
entry.marker.scale.setScalar(selected ? 1.22 : 1);
entry.ring.visible = selected;
});
checkButton.disabled = false;
const transition = transitions[index];
const dh = transition.to.h - transition.from.h;
const de = transition.to.e - transition.from.e;
feedback.className = "feedback";
feedback.innerHTML = `
Link ${index + 1} selected. Its score change is
<strong>Δ = (${dh}, ${de})</strong>. Test whether that vector is one
allowed event.
`;
}
checkButton.addEventListener("click", () => {
if (selectedIndex === null || solved) return;
const transition = transitions[selectedIndex];
const dh = transition.to.h - transition.from.h;
const de = transition.to.e - transition.from.e;
const legal = isLegal(transition);
if (selectedIndex === invalidIndex) {
solved = true;
feedback.className = "feedback success";
feedback.innerHTML = `
<strong>Link ${selectedIndex + 1} is impossible.</strong><br>
The state changes from <strong>(8, 5)</strong> to
<strong>(8, 9)</strong>, so
<strong>Δ = (0, 4)</strong>: Ember rises by four while Harbor
remains fixed. One legal event can change only one team by exactly
two or three, so <strong>(0, 4)</strong> is not an allowed state
transition.
`;
comparison.hidden = false;
checkButton.disabled = true;
choiceButtons.forEach((button, i) => {
button.classList.remove("selected");
button.classList.toggle("valid", i !== invalidIndex);
button.classList.toggle("invalid", i === invalidIndex);
});
markerEntries.forEach((entry, i) => {
const invalid = i === invalidIndex;
const color = invalid ? colors.red : colors.green;
entry.markerMaterial.color.set(color);
entry.markerMaterial.emissive.set(color);
entry.markerMaterial.emissiveIntensity = 0.65;
entry.rodMaterial.color.set(color);
entry.ring.visible = false;
});
} else {
feedback.className = "feedback warn";
feedback.innerHTML = `
Link ${selectedIndex + 1} is legal because
<strong>Δ = (${dh}, ${de})</strong> changes exactly one team by
exactly ${Math.abs(dh + de)} points. That vector belongs to the
stated legal set. Keep looking for the link whose change is not
two or three.
`;
}
});
resetButton.addEventListener("click", () => {
selectedIndex = null;
solved = false;
checkButton.disabled = true;
comparison.hidden = true;
feedback.className = "feedback";
feedback.textContent = "Choose a link to begin.";
choiceButtons.forEach((button) => {
button.classList.remove("selected", "valid", "invalid");
button.setAttribute("aria-pressed", "false");
});
markerEntries.forEach((entry) => {
entry.markerMaterial.color.set(colors.neutralBright);
entry.markerMaterial.emissive.set(0x14262d);
entry.markerMaterial.emissiveIntensity = 0.3;
entry.marker.scale.setScalar(1);
entry.ring.visible = false;
entry.rodMaterial.color.set(colors.neutral);
});
});
// -------------------------------------------------------------------------
// Camera controls implemented without an external controls addon
// -------------------------------------------------------------------------
let dragging = false;
let dragMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let orbitStartTheta = 0;
let orbitStartPhi = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
orbitStartTheta = desiredOrbit.theta;
orbitStartPhi = desiredOrbit.phi;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerStartX;
const dy = event.clientY - pointerStartY;
if (Math.abs(dx) + Math.abs(dy) > 5) dragMoved = true;
desiredOrbit.theta = orbitStartTheta - dx * 0.006;
desiredOrbit.phi = THREE.MathUtils.clamp(
orbitStartPhi + dy * 0.005,
0.08,
1.35
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragMoved) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitTargets, false);
if (intersections.length) {
selectTransition(intersections[0].object.userData.transitionIndex);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius + event.deltaY * 0.008,
9,
24
);
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", () => {
desiredOrbit.theta = 0;
desiredOrbit.phi = 0.88;
desiredOrbit.radius = 16.5;
});
document.querySelector("#top-view").addEventListener("click", () => {
desiredOrbit.theta = 0;
desiredOrbit.phi = 0.08;
desiredOrbit.radius = 16.5;
});
const resizeObserver = new ResizeObserver(() => {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
if (!width || !height) return;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resizeObserver.observe(sceneHost);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
desiredOrbit.theta,
0.12
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
desiredOrbit.phi,
0.12
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
desiredOrbit.radius,
0.12
);
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
markerEntries.forEach((entry, index) => {
entry.marker.rotation.x += 0.004;
entry.marker.rotation.y += 0.007;
entry.group.position.y =
0.43 + Math.sin(elapsed * 2.1 + index * 0.8) * 0.035;
if (entry.ring.visible) {
entry.ring.rotation.z += 0.015;
}
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```