Prompt specification
Build or customize the Three.js 3D scene "Knight Move Footprint on a Board" 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: Knight Move Footprint on a Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/knight-move-footprint-on-a-board-x3605
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Place one knight token on a small chessboard and mark its verified movement offsets. Distinguish its jump rule from a continuous path through intervening squares.
Working Three.js Starter (knight-move-footprint-on-a-board-x3605):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>Knight — Verified Offset Lab</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(8, 20, 34, 0.82);
--line: rgba(148, 190, 211, 0.18);
--text: #eaf7ff;
--muted: #8faabd;
--cyan: #4ff5d9;
--amber: #ffb45b;
--red: #ff6b72;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#titlePanel {
position: fixed;
top: 22px;
left: 22px;
width: min(410px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -0.055em;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.formula {
display: inline-block;
margin-top: 13px;
padding: 7px 9px;
border: 1px solid rgba(79, 245, 217, 0.24);
border-radius: 7px;
color: var(--cyan);
background: rgba(79, 245, 217, 0.055);
font-size: 11px;
}
#infoPanel {
position: fixed;
top: 22px;
right: 22px;
width: 330px;
padding: 17px;
border-radius: 16px;
pointer-events: none;
}
.panel-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.proof-head {
display: flex;
align-items: end;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
}
#proofCoord {
font-size: 38px;
line-height: 1;
font-weight: 900;
letter-spacing: -0.06em;
}
#proofBadge {
padding: 5px 7px;
border: 1px solid rgba(79, 245, 217, 0.3);
border-radius: 5px;
color: var(--cyan);
background: rgba(79, 245, 217, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
}
#proofOffset,
#proofRule {
margin-top: 10px;
font-size: 12px;
line-height: 1.45;
}
#proofRule { color: var(--cyan); }
.proof-divider {
height: 1px;
margin: 14px 0 12px;
background: var(--line);
}
.route-row {
display: grid;
grid-template-columns: 54px 1fr;
gap: 10px;
margin-top: 9px;
font-size: 11px;
line-height: 1.5;
}
.route-row .label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
padding-top: 2px;
}
#proofJump { color: var(--cyan); }
#proofPath { color: var(--amber); }
#proofBlocker { color: #ffc27d; }
.verdict {
margin-top: 13px;
padding: 10px;
border-left: 3px solid var(--cyan);
background: rgba(79, 245, 217, 0.055);
color: #c7fff3;
font-size: 10px;
line-height: 1.5;
}
#controls {
position: fixed;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
padding: 10px;
border-radius: 15px;
white-space: nowrap;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 8px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
cursor: pointer;
transition: 140ms ease;
}
button:hover {
color: var(--text);
border-color: rgba(180, 215, 230, 0.38);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.active {
color: #031713;
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 22px rgba(79, 245, 217, 0.18);
}
#pathBtn.active {
color: #211205;
border-color: var(--amber);
background: var(--amber);
box-shadow: 0 0 22px rgba(255, 180, 91, 0.16);
}
#blockerBtn.active {
color: #241206;
border-color: var(--amber);
background: var(--amber);
}
.separator {
width: 1px;
height: 29px;
margin: 0 2px;
background: var(--line);
}
#help {
position: fixed;
left: 22px;
bottom: 25px;
color: rgba(180, 205, 220, 0.6);
font-size: 10px;
line-height: 1.55;
pointer-events: none;
}
#help b { color: rgba(220, 242, 250, 0.82); }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.14em;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#infoPanel {
top: auto;
right: 12px;
bottom: 100px;
width: 280px;
transform: scale(0.88);
transform-origin: bottom right;
}
#help { display: none; }
}
@media (max-width: 620px) {
#titlePanel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle { display: none; }
.formula { margin-top: 10px; }
#infoPanel {
right: 10px;
bottom: 91px;
width: 245px;
transform: scale(0.76);
}
#controls {
bottom: 10px;
width: calc(100vw - 20px);
overflow-x: auto;
justify-content: flex-start;
padding: 8px;
}
button {
padding: 9px 10px;
flex: 0 0 auto;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel knight movement demonstration"></canvas>
<section id="titlePanel" class="glass">
<div class="eyebrow"><span class="live-dot"></span> Verified offset lab / 5 × 5</div>
<h1>Knight, not a walker.</h1>
<p class="subtitle">
All eight legal destinations are marked from C3. Select a cyan square to inspect its
verified displacement and compare a direct jump with a continuous grid path.
</p>
<div class="formula">(±2, ±1) ∪ (±1, ±2) → 8 destinations</div>
</section>
<aside id="infoPanel" class="glass">
<div class="panel-label">Selected destination proof</div>
<div class="proof-head">
<div id="proofCoord">E4</div>
<div id="proofBadge">LEGAL</div>
</div>
<div id="proofOffset">Δfile +2 · Δrank +1</div>
<div id="proofRule">|Δfile| = 2, |Δrank| = 1 → legal</div>
<div class="proof-divider"></div>
<div class="route-row">
<div class="label">JUMP</div>
<div id="proofJump">C3 → E4 · direct airborne move</div>
</div>
<div class="route-row">
<div class="label">PATH</div>
<div id="proofPath">C3 → C4 → D4 → E4 · comparison only</div>
</div>
<div class="route-row">
<div class="label">WALL</div>
<div id="proofBlocker">D4 · ignored by a knight jump</div>
</div>
<div class="verdict">
A knight tests only its destination. It does not need clear intervening squares.
The amber route is shown only to contrast jump movement with continuous travel.
</div>
</aside>
<nav id="controls" class="glass" aria-label="Scene controls">
<button id="jumpBtn" data-mode="jump">JUMP</button>
<button id="pathBtn" data-mode="path">PATH</button>
<button id="compareBtn" data-mode="compare" class="active">COMPARE</button>
<span class="separator"></span>
<button id="blockerBtn" class="active">WALL TEST</button>
<button id="animateBtn">ANIMATE LEAP</button>
<button id="resetBtn">RESET VIEW</button>
</nav>
<div id="help">
<b>DRAG</b> orbit · <b>SCROLL</b> zoom<br>
<b>CLICK</b> a cyan destination · <b>1 / 2 / 3</b> modes
</div>
<div id="loading">BUILDING VOXEL BOARD…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM / renderer
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.028);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.58, 0);
let cameraYaw = 0.72;
let cameraPitch = 0.72;
let cameraRadius = 13.4;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc6efff, 0x081321, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff3d7, 3.25);
keyLight.position.set(-6, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38f5dd, 18, 15, 2);
cyanLight.position.set(-4, 4, -3);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9c43, 10, 12, 2);
amberLight.position.set(5, 3, 2);
scene.add(amberLight);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
const FILES = ["A", "B", "C", "D", "E"];
const STEP = 1.04;
const TILE_TOP = 0.16;
const CENTER_COL = 2;
const CENTER_ROW = 2;
const COLORS = {
cyan: 0x4ff5d9,
cyanDark: 0x238f86,
amber: 0xffb45b,
amberDark: 0xb75d28,
gold: 0xe4ad43,
goldLight: 0xffd873,
goldDark: 0x986426,
dark: 0x152638
};
function signed(value) {
return value >= 0 ? `+${value}` : `${value}`;
}
function coordinate(col, row) {
return `${FILES[col]}${row + 1}`;
}
function cellPosition(col, row) {
return new THREE.Vector3(
(col - CENTER_COL) * STEP,
TILE_TOP,
(row - CENTER_ROW) * STEP
);
}
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 makeTextSprite(
text,
{
foreground = "#eaf7ff",
background = "rgba(5,18,30,0.88)",
border = "rgba(79,245,217,0.55)",
fontSize = 43
} = {}
) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(ctx, 5, 5, 502, 118, 18);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 10;
return sprite;
}
function makeBox(width, height, depth, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
return mesh;
}
// -------------------------------------------------------------------------
// Ground and board
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x07111d,
roughness: 0.93,
metalness: 0.03
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.29;
ground.receiveShadow = true;
scene.add(ground);
const underGlow = new THREE.Mesh(
new THREE.BoxGeometry(6.1, 0.08, 6.1),
new THREE.MeshStandardMaterial({
color: 0x0b3440,
emissive: 0x0c7f75,
emissiveIntensity: 0.45,
roughness: 0.55
})
);
underGlow.position.y = -0.25;
underGlow.receiveShadow = true;
scene.add(underGlow);
const boardBase = makeBox(
5.48,
0.26,
5.48,
new THREE.MeshStandardMaterial({
color: 0x10263a,
roughness: 0.58,
metalness: 0.24
}),
0,
-0.11,
0
);
scene.add(boardBase);
const lightTileMaterial = new THREE.MeshStandardMaterial({
color: 0xd4dfd9,
roughness: 0.76,
metalness: 0.04
});
const darkTileMaterial = new THREE.MeshStandardMaterial({
color: 0x17364c,
roughness: 0.68,
metalness: 0.1
});
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
const tile = makeBox(
STEP - 0.035,
0.16,
STEP - 0.035,
(row + col) % 2 === 0 ? lightTileMaterial : darkTileMaterial,
(col - CENTER_COL) * STEP,
0.08,
(row - CENTER_ROW) * STEP,
false
);
tile.receiveShadow = true;
scene.add(tile);
}
}
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xb78635,
roughness: 0.36,
metalness: 0.64
});
const frameLongGeometry = new THREE.BoxGeometry(0.15, 0.17, 5.48);
const frameShortGeometry = new THREE.BoxGeometry(5.48, 0.17, 0.15);
const frameOffset = 2.66;
for (const sign of [-1, 1]) {
const side = new THREE.Mesh(frameLongGeometry, frameMaterial);
side.position.set(sign * frameOffset, 0.025, 0);
side.castShadow = true;
side.receiveShadow = true;
scene.add(side);
const end = new THREE.Mesh(frameShortGeometry, frameMaterial);
end.position.set(0, 0.025, sign * frameOffset);
end.castShadow = true;
end.receiveShadow = true;
scene.add(end);
}
// Coordinate labels around the board.
for (let i = 0; i < 5; i++) {
const fileLabel = makeTextSprite(FILES[i], {
foreground: "#9eb8c8",
background: "rgba(7,17,31,0.72)",
border: "rgba(143,170,189,0.2)",
fontSize: 48
});
fileLabel.position.set((i - 2) * STEP, 0.18, 2.98);
fileLabel.scale.set(0.48, 0.12, 1);
scene.add(fileLabel);
const rankLabel = makeTextSprite(String(i + 1), {
foreground: "#9eb8c8",
background: "rgba(7,17,31,0.72)",
border: "rgba(143,170,189,0.2)",
fontSize: 48
});
rankLabel.position.set(-2.98, 0.18, (i - 2) * STEP);
rankLabel.scale.set(0.48, 0.12, 1);
scene.add(rankLabel);
}
// -------------------------------------------------------------------------
// Verified knight destinations
// -------------------------------------------------------------------------
const OFFSETS = [
{ dx: -2, dz: -1 },
{ dx: -2, dz: 1 },
{ dx: -1, dz: -2 },
{ dx: -1, dz: 2 },
{ dx: 1, dz: -2 },
{ dx: 1, dz: 2 },
{ dx: 2, dz: -1 },
{ dx: 2, dz: 1 }
];
const markerMeshes = [];
const markers = [];
const markerPlateGeometry = new THREE.BoxGeometry(STEP - 0.08, 0.024, STEP - 0.08);
const markerCornerGeometry = new THREE.BoxGeometry(0.095, 0.105, 0.095);
OFFSETS.forEach((offset, index) => {
const col = CENTER_COL + offset.dx;
const row = CENTER_ROW + offset.dz;
const position = cellPosition(col, row);
const group = new THREE.Group();
group.position.set(position.x, 0, position.z);
const plateMaterial = new THREE.MeshStandardMaterial({
color: COLORS.cyanDark,
emissive: COLORS.cyanDark,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.18,
roughness: 0.42,
metalness: 0.08,
depthWrite: false
});
const plate = new THREE.Mesh(markerPlateGeometry, plateMaterial);
plate.position.y = TILE_TOP + 0.018;
plate.userData.offsetIndex = index;
plate.userData.isDestination = true;
group.add(plate);
markerMeshes.push(plate);
const cornerMaterial = new THREE.MeshStandardMaterial({
color: COLORS.cyan,
emissive: COLORS.cyan,
emissiveIntensity: 0.75,
roughness: 0.35,
metalness: 0.12
});
const corners = [];
const cornerOffset = STEP * 0.39;
for (const xSign of [-1, 1]) {
for (const zSign of [-1, 1]) {
const corner = new THREE.Mesh(markerCornerGeometry, cornerMaterial);
corner.position.set(
xSign * cornerOffset,
TILE_TOP + 0.055,
zSign * cornerOffset
);
corner.castShadow = true;
group.add(corner);
corners.push(corner);
}
}
const label = makeTextSprite(
`${coordinate(col, row)} Δ ${signed(offset.dx)},${signed(offset.dz)}`,
{
foreground: "#cffff4",
background: "rgba(4,20,31,0.92)",
border: "rgba(79,245,217,0.65)",
fontSize: 39
}
);
label.position.set(
offset.dx * 0.11,
0.57,
offset.dz * 0.11
);
label.scale.set(1.38, 0.345, 1);
group.add(label);
scene.add(group);
markers.push({ group, plate, corners, cornerMaterial, offset });
});
// -------------------------------------------------------------------------
// Voxel knight token
// -------------------------------------------------------------------------
const knight = new THREE.Group();
knight.position.set(0, TILE_TOP, 0);
scene.add(knight);
const knightDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x754719,
roughness: 0.42,
metalness: 0.52
});
const knightGoldMaterial = new THREE.MeshStandardMaterial({
color: COLORS.gold,
roughness: 0.36,
metalness: 0.58
});
const knightLightMaterial = new THREE.MeshStandardMaterial({
color: COLORS.goldLight,
roughness: 0.3,
metalness: 0.48
});
const knightMidMaterial = new THREE.MeshStandardMaterial({
color: 0xc98c2d,
roughness: 0.42,
metalness: 0.5
});
knight.add(
makeBox(
0.78, 0.12, 0.66,
knightDarkMaterial,
0, 0.06, 0
)
);
knight.add(
makeBox(
0.66, 0.075, 0.55,
knightGoldMaterial,
0, 0.157, 0
)
);
const knightRows = [
"0111010",
"0111110",
"0111100",
"0111100",
"0011110",
"0001110",
"0000111",
"0000011"
];
const voxel = 0.17;
const knightDepth = 0.29;
knightRows.forEach((row, gy) => {
[...row].forEach((cell, gx) => {
if (cell !== "1") return;
let material = knightGoldMaterial;
if (gx <= 1 && gy < 4) material = knightDarkMaterial;
else if ((gx + gy) % 3 === 0) material = knightLightMaterial;
else if ((gx + gy) % 3 === 1) material = knightMidMaterial;
knight.add(
makeBox(
voxel * 0.96,
voxel * 0.96,
knightDepth,
material,
(gx - 4) * voxel,
0.205 + (gy + 0.5) * voxel,
0
)
);
});
});
// Ear.
knight.add(
makeBox(
voxel * 0.9,
voxel * 0.95,
knightDepth * 0.8,
knightLightMaterial,
(5 - 4) * voxel,
0.205 + 8.5 * voxel,
0
)
);
// Eye and muzzle details.
knight.add(
makeBox(
0.055,
0.055,
0.025,
new THREE.MeshStandardMaterial({
color: 0x061018,
roughness: 0.25,
metalness: 0.15
}),
0.365,
1.37,
0.155
)
);
knight.add(
makeBox(
0.10,
0.09,
0.24,
knightDarkMaterial,
0.52,
1.26,
0
)
);
knight.rotation.y = -0.18;
// Small cyan corner brackets under the origin token.
const originBracketMaterial = new THREE.MeshStandardMaterial({
color: COLORS.cyan,
emissive: COLORS.cyan,
emissiveIntensity: 0.85,
roughness: 0.35
});
const originBracketGeometry = new THREE.BoxGeometry(0.11, 0.075, 0.11);
const originBracketOffset = 0.49;
for (const xSign of [-1, 1]) {
for (const zSign of [-1, 1]) {
const bracket = new THREE.Mesh(originBracketGeometry, originBracketMaterial);
bracket.position.set(
xSign * originBracketOffset,
TILE_TOP + 0.035,
zSign * originBracketOffset
);
scene.add(bracket);
}
}
// -------------------------------------------------------------------------
// Dynamic jump/path visuals
// -------------------------------------------------------------------------
const jumpGroup = new THREE.Group();
const pathGroup = new THREE.Group();
const blockerGroup = new THREE.Group();
scene.add(jumpGroup, pathGroup, blockerGroup);
const jumpBeadGeometry = new THREE.BoxGeometry(0.082, 0.082, 0.082);
const jumpBeadMaterial = new THREE.MeshStandardMaterial({
color: COLORS.cyan,
emissive: COLORS.cyan,
emissiveIntensity: 1.6,
roughness: 0.28,
metalness: 0.08
});
const pathCubeGeometry = new THREE.BoxGeometry(0.075, 0.045, 0.075);
const pathCubeMaterial = new THREE.MeshStandardMaterial({
color: COLORS.amber,
emissive: COLORS.amber,
emissiveIntensity: 0.85,
roughness: 0.42,
metalness: 0.08
});
const pathPlateGeometry = new THREE.BoxGeometry(STEP - 0.13, 0.018, STEP - 0.13);
const pathPlateMaterial = new THREE.MeshStandardMaterial({
color: COLORS.amberDark,
emissive: COLORS.amberDark,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.38,
depthWrite: false,
roughness: 0.6
});
const blockerGeometry = new THREE.BoxGeometry(0.25, 0.25, 0.25);
const blockerMaterial = new THREE.MeshStandardMaterial({
color: COLORS.amber,
emissive: 0x8d3e0d,
emissiveIntensity: 0.65,
roughness: 0.42,
metalness: 0.2
});
const blockerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x49301e,
roughness: 0.58,
metalness: 0.22
});
let selectedIndex = 7;
let mode = "compare";
let blockerOn = true;
let animationOn = false;
let animationClock = 0;
let jumpCurve = null;
function clearDynamicGroup(group) {
while (group.children.length) {
group.remove(group.children[group.children.length - 1]);
}
}
function selectedOffset() {
return OFFSETS[selectedIndex];
}
function selectedDestination() {
const offset = selectedOffset();
return cellPosition(
CENTER_COL + offset.dx,
CENTER_ROW + offset.dz
);
}
function createJumpCurve() {
const destination = selectedDestination();
return new THREE.QuadraticBezierCurve3(
new THREE.Vector3(0, TILE_TOP, 0),
new THREE.Vector3(
destination.x * 0.5,
TILE_TOP + 2.25,
destination.z * 0.5
),
destination.clone()
);
}
function buildJumpVisual() {
clearDynamicGroup(jumpGroup);
jumpCurve = createJumpCurve();
// A deliberately segmented airborne path: cubes, not a continuous board line.
const beadCount = 23;
for (let i = 1; i <= beadCount; i++) {
const point = jumpCurve.getPoint(i / (beadCount + 1));
const bead = new THREE.Mesh(jumpBeadGeometry, jumpBeadMaterial);
bead.position.copy(point);
bead.castShadow = true;
jumpGroup.add(bead);
}
}
function getRouteCells(offset) {
let col = CENTER_COL;
let row = CENTER_ROW;
const route = [{ col, row }];
function moveAxis(axis, amount) {
const direction = Math.sign(amount);
for (let i = 0; i < Math.abs(amount); i++) {
if (axis === "col") col += direction;
else row += direction;
route.push({ col, row });
}
}
// Short axis first creates an intuitive orthogonally continuous comparison.
if (Math.abs(offset.dx) >= Math.abs(offset.dz)) {
moveAxis("row", offset.dz);
moveAxis("col", offset.dx);
} else {
moveAxis("col", offset.dx);
moveAxis("row", offset.dz);
}
return route;
}
function buildPathVisual() {
clearDynamicGroup(pathGroup);
const route = getRouteCells(selectedOffset());
// Highlight every intervening square used by the comparison path.
for (let i = 1; i < route.length - 1; i++) {
const position = cellPosition(route[i].col, route[i].row);
const plate = new THREE.Mesh(pathPlateGeometry, pathPlateMaterial);
plate.position.set(position.x, TILE_TOP + 0.014, position.z);
pathGroup.add(plate);
}
// A tight chain of amber voxels forms a continuous orthogonal path.
for (let segment = 0; segment < route.length - 1; segment++) {
const a = cellPosition(route[segment].col, route[segment].row);
const b = cellPosition(route[segment + 1].col, route[segment + 1].row);
const distance = a.distanceTo(b);
const steps = Math.ceil(distance / 0.073);
for (let step = 0; step < steps; step++) {
const t = step / steps;
const point = a.clone().lerp(b, t);
const cube = new THREE.Mesh(pathCubeGeometry, pathCubeMaterial);
cube.position.set(point.x, TILE_TOP + 0.044, point.z);
cube.castShadow = true;
pathGroup.add(cube);
}
}
}
function buildBlocker() {
clearDynamicGroup(blockerGroup);
const route = getRouteCells(selectedOffset());
const cell = route[route.length - 2];
const position = cellPosition(cell.col, cell.row);
blockerGroup.position.set(position.x, TILE_TOP, position.z);
for (let i = 0; i < 3; i++) {
const block = new THREE.Mesh(
blockerGeometry,
i === 1 ? blockerDarkMaterial : blockerMaterial
);
block.position.y = 0.125 + i * 0.25;
block.castShadow = true;
block.receiveShadow = true;
blockerGroup.add(block);
}
blockerGroup.visible = blockerOn;
}
function refreshMarkerStyles(hoveredIndex = -1) {
markers.forEach((marker, index) => {
const selected = index === selectedIndex;
const hovered = index === hoveredIndex;
marker.plate.material.color.setHex(
selected ? COLORS.cyan : COLORS.cyanDark
);
marker.plate.material.emissive.setHex(
selected ? COLORS.cyan : COLORS.cyanDark
);
marker.plate.material.emissiveIntensity = selected ? 0.95 : 0.32;
marker.plate.material.opacity = selected ? 0.45 : hovered ? 0.31 : 0.18;
marker.cornerMaterial.color.setHex(
selected ? 0xbaffef : COLORS.cyan
);
marker.cornerMaterial.emissiveIntensity = selected ? 1.45 : 0.72;
marker.corners.forEach((corner) => {
corner.scale.y = selected ? 1.65 : hovered ? 1.3 : 1;
});
});
}
function updateInfo() {
const offset = selectedOffset();
const col = CENTER_COL + offset.dx;
const row = CENTER_ROW + offset.dz;
const destination = coordinate(col, row);
const route = getRouteCells(offset);
const routeText = route
.map((cell) => coordinate(cell.col, cell.row))
.join(" → ");
const blockerCell = route[route.length - 2];
const blockerSquare = coordinate(blockerCell.col, blockerCell.row);
$("#proofCoord").textContent = destination;
$("#proofOffset").textContent =
`Δfile ${signed(offset.dx)} · Δrank ${signed(offset.dz)}`;
const larger = Math.abs(offset.dx) === 2 ? "file" : "rank";
const smaller = larger === "file" ? "rank" : "file";
const largerValue = larger === "file" ? Math.abs(offset.dx) : Math.abs(offset.dz);
const smallerValue = smaller === "file" ? Math.abs(offset.dx) : Math.abs(offset.dz);
$("#proofRule").textContent =
`|Δ${larger}| = ${largerValue}, |Δ${smaller}| = ${smallerValue} → legal`;
$("#proofJump").textContent =
`C3 → ${destination} · direct airborne move`;
$("#proofPath").textContent =
`C3 → ${routeText.replace(/^C3 → /, "")} · comparison only`;
$("#proofBlocker").textContent = blockerOn
? `${blockerSquare} · ignored by a knight jump`
: `${blockerSquare} · wall test disabled`;
}
function updateSelection(index) {
selectedIndex = index;
animationClock = 0;
buildJumpVisual();
buildPathVisual();
buildBlocker();
refreshMarkerStyles();
updateInfo();
jumpGroup.visible = mode !== "path";
pathGroup.visible = mode !== "jump";
}
function setMode(nextMode) {
mode = nextMode;
jumpGroup.visible = mode !== "path";
pathGroup.visible = mode !== "jump";
document.querySelectorAll("[data-mode]").forEach((button) => {
button.classList.toggle("active", button.dataset.mode === mode);
});
updateInfo();
}
// -------------------------------------------------------------------------
// Direct camera controls — no add-ons
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
let hoveredIndex = -1;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickDestination(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(markerMeshes, false);
if (hits.length) {
updateSelection(hits[0].object.userData.offsetIndex);
}
}
function findHover(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(markerMeshes, false);
const nextHovered = hits.length ? hits[0].object.userData.offsetIndex : -1;
if (nextHovered !== hoveredIndex) {
hoveredIndex = nextHovered;
refreshMarkerStyles(hoveredIndex);
canvas.style.cursor = hoveredIndex >= 0 ? "pointer" : "grab";
}
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) {
findHover(event);
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
cameraYaw -= dx * 0.006;
cameraPitch += dy * 0.005;
cameraPitch = THREE.MathUtils.clamp(cameraPitch, 0.28, 1.24);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
const wasClick =
Math.abs(event.clientX - pointerStartX) +
Math.abs(event.clientY - pointerStartY) < 7;
dragging = false;
canvas.releasePointerCapture(event.pointerId);
canvas.style.cursor = hoveredIndex >= 0 ? "pointer" : "grab";
if (wasClick) pickDestination(event);
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointerleave", () => {
if (dragging) return;
hoveredIndex = -1;
refreshMarkerStyles();
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
8.4,
19
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
document.querySelectorAll("[data-mode]").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
$("#blockerBtn").addEventListener("click", () => {
blockerOn = !blockerOn;
$("#blockerBtn").classList.toggle("active", blockerOn);
blockerGroup.visible = blockerOn;
updateInfo();
});
$("#animateBtn").addEventListener("click", () => {
animationOn = !animationOn;
animationClock = 0;
$("#animateBtn").classList.toggle("active", animationOn);
$("#animateBtn").textContent = animationOn ? "LEAP: ON" : "ANIMATE LEAP";
if (!animationOn) {
knight.position.set(0, TILE_TOP, 0);
knight.rotation.set(0, -0.18, 0);
}
});
$("#resetBtn").addEventListener("click", () => {
cameraYaw = 0.72;
cameraPitch = 0.72;
cameraRadius = 13.4;
updateCamera();
updateSelection(7);
});
window.addEventListener("keydown", (event) => {
if (event.repeat) return;
if (event.key === "1") setMode("jump");
if (event.key === "2") setMode("path");
if (event.key === "3") setMode("compare");
if (event.key.toLowerCase() === "r") $("#resetBtn").click();
if (event.code === "Space") {
event.preventDefault();
$("#animateBtn").click();
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function smoothstep(t) {
const clamped = THREE.MathUtils.clamp(t, 0, 1);
return clamped * clamped * (3 - 2 * clamped);
}
function updateKnightAnimation(delta) {
if (!animationOn || !jumpCurve) return;
animationClock += delta;
const outbound = 0.92;
const pause = 0.30;
const inbound = 0.92;
const cycle = outbound + pause + inbound;
const phase = animationClock % cycle;
let t = 0;
let tilt = 0;
if (phase < outbound) {
t = smoothstep(phase / outbound);
tilt = Math.sin(Math.PI * t) * 0.25;
} else if (phase < outbound + pause) {
t = 1;
} else {
t = 1 - smoothstep((phase - outbound - pause) / inbound);
tilt = -Math.sin(Math.PI * t) * 0.22;
}
const point = jumpCurve.getPoint(t);
knight.position.copy(point);
knight.rotation.set(0, -0.18, tilt);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateKnightAnimation(delta);
if (mode !== "path") {
jumpBeadMaterial.emissiveIntensity =
1.35 + Math.sin(clock.elapsedTime * 3.4) * 0.35;
}
renderer.render(scene, camera);
}
updateSelection(selectedIndex);
setMode(mode);
resize();
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```