Prompt specification
Build or customize the Three.js 3D scene "Test a Rule With an Unseen Shape" 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: Test a Rule With an Unseen Shape
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/test-a-rule-with-an-unseen-shape-x3598
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: test a rule with an unseen shape. Create a tabletop game where activation depends on a geometric property rather than object identity. Introduce a new shape and evaluate the same property consistently. Return one self-contained HTML file.
Working Three.js Starter (test-a-rule-with-an-unseen-shape-x3598):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Rule Lab — Will It Activate?</title>
<style>
:root {
--ink: #18343a;
--muted: #657a7b;
--paper: #fffdf5;
--line: #cad9d2;
--teal: #246b70;
--mint: #38d39a;
--coral: #ef705f;
--gold: #f3bd58;
--shadow: 0 18px 50px rgba(30, 62, 61, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.ui-layer {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel,
.dock,
.scene-chip {
pointer-events: auto;
}
.header {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 47px;
height: 47px;
border-radius: 13px;
background: var(--ink);
box-shadow: 0 8px 22px rgba(24, 52, 58, 0.18);
display: grid;
place-items: center;
transform: rotate(-3deg);
}
.brand-mark svg {
width: 29px;
height: 29px;
fill: #f8f2dd;
}
.eyebrow {
margin: 0 0 4px;
color: var(--teal);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
line-height: 0.95;
letter-spacing: -0.055em;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 13px;
font-weight: 550;
}
.progress-wrap {
min-width: 175px;
padding: 12px 14px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 15px;
background: rgba(255, 253, 245, 0.72);
backdrop-filter: blur(12px);
box-shadow: 0 8px 26px rgba(38, 74, 70, 0.09);
}
.progress-title {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.step {
height: 6px;
overflow: hidden;
border-radius: 10px;
background: #d8e1dc;
position: relative;
}
.step::after {
content: "";
position: absolute;
inset: 0;
transform: translateX(-105%);
background: var(--teal);
transition: transform .35s ease;
}
.step.done::after,
.step.current::after { transform: translateX(0); }
.step.current::after { background: var(--gold); }
.rule-panel,
.inspector {
position: absolute;
top: 122px;
width: 306px;
border: 1px solid rgba(255,255,255,.86);
border-radius: 21px;
background: rgba(255, 253, 245, 0.91);
backdrop-filter: blur(16px);
box-shadow: var(--shadow);
}
.rule-panel { left: 28px; }
.inspector { right: 28px; width: 278px; }
.panel-inner { padding: 20px; }
.rule-kicker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.rule-number {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .1em;
}
.badge {
display: inline-flex;
align-items: center;
min-height: 24px;
padding: 5px 9px;
border-radius: 999px;
background: #e4f1e9;
color: #246b70;
font-size: 9px;
font-weight: 900;
letter-spacing: .1em;
text-transform: uppercase;
white-space: nowrap;
}
.badge.transfer {
color: #7a4c08;
background: #fff0c8;
}
.rule-panel h2,
.inspector h2 {
margin: 12px 0 8px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -.04em;
}
.rule-panel p,
.inspector p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.logic {
margin-top: 15px;
padding: 12px;
border: 1px solid #dbe4dd;
border-radius: 13px;
background: #f5f4e9;
}
.logic-row {
display: grid;
grid-template-columns: 22px 1fr auto;
align-items: center;
gap: 8px;
padding: 6px 0;
font-size: 12px;
font-weight: 750;
}
.logic-icon {
width: 20px;
height: 20px;
display: grid;
place-items: center;
border-radius: 6px;
background: var(--teal);
color: white;
font-size: 11px;
}
.logic-row small {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.property-note {
display: flex;
align-items: center;
gap: 8px;
margin-top: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.property-note::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--gold);
transform: rotate(45deg);
}
.piece-meta {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}
.inspector h2 { margin-bottom: 3px; }
.piece-description {
min-height: 42px;
}
.map-shell {
display: flex;
justify-content: center;
margin: 16px 0 13px;
padding: 12px;
border-radius: 16px;
background: #edf1e9;
border: 1px solid #dbe3dc;
}
.mini-map {
display: grid;
grid-template-columns: repeat(3, 28px);
grid-template-rows: repeat(3, 28px);
gap: 4px;
}
.mini-cell {
position: relative;
border-radius: 5px;
background: #d8dfd9;
box-shadow: inset 0 0 0 1px rgba(31,65,66,.08);
transition: background .25s ease, transform .25s ease;
}
.mini-cell.filled {
background: var(--teal);
box-shadow: inset 0 3px 0 rgba(255,255,255,.18), 0 3px 8px rgba(27,75,75,.12);
}
.mini-cell.active { background: var(--mint); }
.mini-cell.inactive { background: var(--coral); }
.mini-cell.gap::after {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 9px;
height: 2px;
border-radius: 2px;
background: #a83c34;
transform: translate(-50%, -50%) rotate(-45deg);
}
.readout {
padding-top: 13px;
border-top: 1px solid #dce4dd;
}
.readout-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 5px 0;
font-size: 11px;
}
.readout-label {
color: var(--muted);
font-weight: 700;
}
.readout-value {
font-weight: 850;
text-align: right;
}
.readout-value.good { color: #18855e; }
.readout-value.bad { color: #bf4e42; }
.readout-value.sealed { color: #879693; }
.dock {
position: absolute;
left: 50%;
bottom: 25px;
width: min(590px, calc(100% - 32px));
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,.9);
border-radius: 22px;
background: rgba(255, 253, 245, 0.95);
backdrop-filter: blur(18px);
box-shadow: 0 22px 65px rgba(28, 63, 61, .2);
overflow: hidden;
}
.question-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 12px 16px;
border-bottom: 1px solid #dce4dd;
background: #f3f2e8;
}
.question-bar strong {
font-size: 13px;
letter-spacing: -.01em;
}
.question-bar span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.prediction-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 11px;
padding: 13px;
}
.predict-button {
min-height: 68px;
border: 1.5px solid #cbd8d2;
border-radius: 15px;
background: white;
color: var(--ink);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 11px;
font-size: 13px;
font-weight: 900;
letter-spacing: .035em;
transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.predict-button:hover {
transform: translateY(-2px);
border-color: var(--teal);
background: #f7fbf7;
}
.predict-button:active { transform: translateY(0); }
.button-icon {
width: 32px;
height: 32px;
display: grid;
place-items: center;
border-radius: 10px;
background: #edf2ed;
font-size: 17px;
}
.predict-button.activate .button-icon {
color: #147955;
background: #dcf7e9;
}
.predict-button.dark .button-icon {
color: #b84d43;
background: #fde6e1;
}
.key-hint {
color: #91a09d;
font-size: 9px;
font-weight: 800;
border: 1px solid #d4ddd7;
border-radius: 5px;
padding: 2px 5px;
margin-left: 4px;
}
.result-area {
padding: 15px;
}
.result-main {
display: grid;
grid-template-columns: 43px 1fr;
gap: 12px;
align-items: start;
}
.result-symbol {
width: 43px;
height: 43px;
display: grid;
place-items: center;
border-radius: 13px;
color: white;
font-size: 21px;
font-weight: 900;
}
.result-area.good .result-symbol { background: var(--mint); }
.result-area.bad .result-symbol { background: var(--coral); }
.result-area.good h3 { color: #177957; }
.result-area.bad h3 { color: #b84b40; }
.result-area h3 {
margin: 1px 0 3px;
font-size: 16px;
letter-spacing: -.025em;
}
.result-area p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.continue-button {
width: 100%;
margin-top: 13px;
min-height: 43px;
border: 0;
border-radius: 12px;
background: var(--ink);
color: white;
cursor: pointer;
font-weight: 850;
font-size: 12px;
letter-spacing: .04em;
transition: transform .16s ease, background .16s ease;
}
.continue-button:hover {
transform: translateY(-1px);
background: #24535a;
}
.scene-chip {
position: absolute;
left: 50%;
bottom: 169px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 9px 13px;
border: 1px solid rgba(255,255,255,.85);
border-radius: 999px;
background: rgba(255,253,245,.85);
color: var(--muted);
box-shadow: 0 8px 22px rgba(29,61,59,.1);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
white-space: nowrap;
transition: color .25s ease, background .25s ease;
}
.scene-chip::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: #8da19d;
box-shadow: 0 0 0 4px rgba(141,161,157,.13);
}
.scene-chip.active { color: #147a57; }
.scene-chip.active::before { background: var(--mint); box-shadow: 0 0 0 4px rgba(56,211,154,.16); }
.scene-chip.inactive { color: #ae493f; }
.scene-chip.inactive::before { background: var(--coral); box-shadow: 0 0 0 4px rgba(239,112,95,.16); }
.scene-hint {
position: absolute;
left: 29px;
bottom: 30px;
color: rgba(24,52,58,.56);
font-size: 9px;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dce8e3;
color: var(--ink);
font-size: 12px;
font-weight: 850;
letter-spacing: .12em;
text-transform: uppercase;
transition: opacity .4s ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
[hidden] { display: none !important; }
@media (max-width: 1050px) {
.rule-panel { width: 270px; left: 18px; }
.inspector { width: 244px; right: 18px; }
.header { left: 18px; right: 18px; }
.scene-hint { display: none; }
}
@media (max-width: 760px) {
.header { top: 14px; left: 14px; right: 14px; }
.brand-mark { width: 39px; height: 39px; border-radius: 11px; }
.brand-mark svg { width: 24px; height: 24px; }
h1 { font-size: 28px; }
.subtitle { display: none; }
.progress-wrap { min-width: 112px; padding: 9px 10px; }
.progress-title span:first-child { display: none; }
.rule-panel {
top: 83px;
left: 12px;
right: 12px;
width: auto;
}
.rule-panel .panel-inner { padding: 13px 15px; }
.rule-panel h2 { margin: 8px 0 4px; font-size: 19px; }
.rule-panel p { font-size: 11px; line-height: 1.4; }
.logic, .property-note { display: none; }
.inspector {
top: auto;
right: 12px;
bottom: 135px;
width: 185px;
}
.inspector .panel-inner { padding: 13px; }
.inspector h2 { margin: 8px 0 3px; font-size: 19px; }
.piece-description { display: none; }
.map-shell { margin: 10px 0; padding: 8px; }
.mini-map {
grid-template-columns: repeat(3, 23px);
grid-template-rows: repeat(3, 23px);
gap: 3px;
}
.readout { padding-top: 8px; }
.readout-row { font-size: 9px; }
.dock {
bottom: 10px;
width: calc(100% - 24px);
border-radius: 17px;
}
.question-bar { padding: 9px 12px; }
.question-bar strong { font-size: 11px; }
.question-bar span { display: none; }
.prediction-grid { padding: 9px; gap: 8px; }
.predict-button { min-height: 58px; font-size: 11px; }
.button-icon { width: 28px; height: 28px; }
.key-hint { display: none; }
.result-area { padding: 11px; }
.result-area p { font-size: 11px; }
.scene-chip { bottom: 125px; font-size: 8px; padding: 7px 10px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D voxel tabletop"></canvas>
<div class="ui-layer">
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32">
<path d="M16 2 29 9.5v13L16 30 3 22.5v-13L16 2Zm0 5.4L8.1 11.8v8.4L16 24.6l7.9-4.4v-8.4L16 7.4Zm-7.9 4.4L16 16.6l7.9-4.8M16 16.6v8"/>
</svg>
</div>
<div>
<p class="eyebrow">Voxel Rule Lab · Table 01</p>
<h1>Will it wake?</h1>
<p class="subtitle">Learn the property. Test the unseen shape.</p>
</div>
</div>
<div class="progress-wrap" aria-label="Game progress">
<div class="progress-title">
<span>Rule transfer</span>
<span id="progressText">01 / 03</span>
</div>
<div class="steps">
<span class="step current"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</div>
</header>
<section class="panel rule-panel" aria-labelledby="ruleTitle">
<div class="panel-inner">
<div class="rule-kicker">
<p class="eyebrow" style="margin:0">The Active Rule</p>
<span class="rule-number">RULE 07</span>
</div>
<h2 id="ruleTitle">Every line stays whole.</h2>
<p>
A piece activates when every occupied <strong>row</strong> and every occupied
<strong>column</strong> in its top-down footprint is one unbroken run.
</p>
<div class="logic" aria-label="Rule logic">
<div class="logic-row">
<span class="logic-icon">✓</span>
<span>Rows have no gaps</span>
<small>AND</small>
</div>
<div class="logic-row">
<span class="logic-icon">✓</span>
<span>Columns have no gaps</span>
<small>THEN</small>
</div>
</div>
<div class="property-note">Property, not object identity</div>
</div>
</section>
<aside class="panel inspector" aria-labelledby="pieceTitle">
<div class="panel-inner">
<div class="piece-meta">
<p class="eyebrow" style="margin:0">Current piece</p>
<span id="pieceBadge" class="badge">Calibration 01</span>
</div>
<h2 id="pieceTitle">The Square</h2>
<p id="pieceDescription" class="piece-description">A compact, familiar footprint.</p>
<div class="map-shell">
<div id="miniMap" class="mini-map" aria-label="Top-down footprint map"></div>
</div>
<div class="readout">
<div class="readout-row">
<span class="readout-label">Rows</span>
<span id="rowsReadout" class="readout-value sealed">Sealed</span>
</div>
<div class="readout-row">
<span class="readout-label">Columns</span>
<span id="colsReadout" class="readout-value sealed">Sealed</span>
</div>
</div>
</div>
</aside>
<div id="sceneChip" class="scene-chip">Prediction sealed</div>
<section class="dock" aria-label="Prediction controls">
<div class="question-bar">
<strong id="questionText">Will The Square activate?</strong>
<span>Choose before the readout</span>
</div>
<div id="predictionArea" class="prediction-grid">
<button class="predict-button dark" data-prediction="dark" type="button">
<span class="button-icon">◐</span>
<span>STAY DARK <span class="key-hint">1</span></span>
</button>
<button class="predict-button activate" data-prediction="active" type="button">
<span class="button-icon">✦</span>
<span>ACTIVATE <span class="key-hint">2</span></span>
</button>
</div>
<div id="resultArea" class="result-area" hidden>
<div class="result-main">
<div id="resultSymbol" class="result-symbol">✓</div>
<div>
<h3 id="resultTitle">Correct — it activates.</h3>
<p id="resultText"></p>
</div>
</div>
<button id="continueButton" class="continue-button" type="button">CONTINUE TO THE NEXT PIECE</button>
</div>
</section>
<div class="scene-hint">Drag to orbit · scroll to zoom · double-click to reset</div>
</div>
<div id="loading">Setting the table…</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const $ = id => document.getElementById(id);
const COLORS = {
background: 0xdce8e3,
table: 0xc9d8d1,
board: 0x315c61,
boardTop: 0xe9eee3,
gridA: 0xaac1b8,
gridB: 0xcbd9d0,
voxel: 0x286f75,
voxelTop: 0xfaf1d7,
active: 0x38d39a,
inactive: 0xef705f,
neutralFrame: 0xb8c9c1,
ink: 0x18343a
};
const rounds = [
{
name: 'The Square',
badge: 'Calibration 01',
badgeClass: '',
description: 'A compact, familiar footprint.',
matrix: [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
},
{
name: 'The C',
badge: 'Calibration 02',
badgeClass: '',
description: 'Look carefully between its upper and lower arms.',
matrix: [
[1, 1, 1],
[1, 0, 0],
[1, 1, 1]
]
},
{
name: 'The Cross',
badge: 'Unseen · Transfer',
badgeClass: 'transfer',
description: 'First appearance. The rule has not changed.',
matrix: [
[0, 1, 0],
[1, 1, 1],
[0, 1, 0]
]
}
];
let roundIndex = 0;
let score = 0;
let answered = false;
let finished = false;
let currentAnalysis = null;
let currentPieceGroup = null;
let currentVoxelMaterials = [];
let currentEdgeMaterials = [];
let currentTopMaterials = [];
const canvas = $('scene');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(COLORS.background, 16, 29);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 100);
const target = new THREE.Vector3(0, 0.6, 0);
const cameraState = {
azimuth: 0.58,
polar: 0.77,
radius: 15,
zoom: 1.32
};
const hemi = new THREE.HemisphereLight(0xffffff, 0x82958c, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff6df, 3.2);
keyLight.position.set(5.5, 10, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcde9ff, 1.05);
fillLight.position.set(-5, 5, -3);
scene.add(fillLight);
const table = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({ color: COLORS.table, roughness: 0.92, metalness: 0.02 })
);
table.rotation.x = -Math.PI / 2;
table.position.y = -0.43;
table.receiveShadow = true;
scene.add(table);
const boardBase = new THREE.Mesh(
new THREE.BoxGeometry(8.25, 0.42, 6.25),
new THREE.MeshStandardMaterial({ color: COLORS.board, roughness: 0.72, metalness: 0.05 })
);
boardBase.position.y = -0.18;
boardBase.castShadow = true;
boardBase.receiveShadow = true;
scene.add(boardBase);
const boardTop = new THREE.Mesh(
new THREE.BoxGeometry(8.02, 0.14, 6.02),
new THREE.MeshStandardMaterial({ color: COLORS.boardTop, roughness: 0.88 })
);
boardTop.position.y = 0.1;
boardTop.castShadow = true;
boardTop.receiveShadow = true;
scene.add(boardTop);
const grid = new THREE.GridHelper(7.7, 14, COLORS.gridA, COLORS.gridB);
grid.position.y = 0.176;
grid.material.transparent = true;
grid.material.opacity = 0.52;
scene.add(grid);
const pedestal = new THREE.Mesh(
new THREE.BoxGeometry(3.8, 0.24, 3.8),
new THREE.MeshStandardMaterial({ color: 0x244f55, roughness: 0.67 })
);
pedestal.position.y = 0.27;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const pedestalTop = new THREE.Mesh(
new THREE.BoxGeometry(3.58, 0.08, 3.58),
new THREE.MeshStandardMaterial({ color: 0xe7eee5, roughness: 0.9 })
);
pedestalTop.position.y = 0.43;
pedestalTop.receiveShadow = true;
scene.add(pedestalTop);
const frameMaterial = new THREE.MeshStandardMaterial({
color: COLORS.neutralFrame,
emissive: COLORS.neutralFrame,
emissiveIntensity: 0.08,
roughness: 0.55
});
const frameGroup = new THREE.Group();
const frameLongGeometry = new THREE.BoxGeometry(3.72, 0.09, 0.09);
const frameShortGeometry = new THREE.BoxGeometry(0.09, 0.09, 3.72);
for (const z of [-1.86, 1.86]) {
const rail = new THREE.Mesh(frameLongGeometry, frameMaterial);
rail.position.set(0, 0.5, z);
rail.castShadow = true;
frameGroup.add(rail);
}
for (const x of [-1.86, 1.86]) {
const rail = new THREE.Mesh(frameShortGeometry, frameMaterial);
rail.position.set(x, 0.5, 0);
rail.castShadow = true;
frameGroup.add(rail);
}
scene.add(frameGroup);
const beaconLight = new THREE.PointLight(0xffffff, 0, 5, 2);
beaconLight.position.set(0, 2.4, 0);
scene.add(beaconLight);
const particleGroup = new THREE.Group();
const particles = [];
for (let i = 0; i < 9; i++) {
const material = new THREE.MeshStandardMaterial({
color: COLORS.active,
emissive: COLORS.active,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0
});
const particle = new THREE.Mesh(new THREE.BoxGeometry(0.13, 0.13, 0.13), material);
const angle = (i / 9) * Math.PI * 2;
const radius = 0.55 + (i % 3) * 0.18;
particle.userData = {
x: Math.cos(angle) * radius,
z: Math.sin(angle) * radius,
offset: i / 9,
speed: 0.18 + (i % 4) * 0.018
};
particle.visible = false;
particleGroup.add(particle);
particles.push(particle);
}
scene.add(particleGroup);
const labelCanvas = document.createElement('canvas');
labelCanvas.width = 1024;
labelCanvas.height = 256;
const labelContext = labelCanvas.getContext('2d');
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
const labelMaterial = new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
depthWrite: false
});
const boardLabel = new THREE.Mesh(new THREE.PlaneGeometry(3.5, 0.72), labelMaterial);
boardLabel.rotation.x = -Math.PI / 2;
boardLabel.position.set(0, 0.183, 2.35);
scene.add(boardLabel);
function updateBoardLabel(name, badge) {
labelContext.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
labelContext.textAlign = 'center';
labelContext.textBaseline = 'middle';
labelContext.fillStyle = '#18343a';
labelContext.font = '900 70px system-ui, sans-serif';
labelContext.fillText(name.toUpperCase(), 512, 91);
labelContext.fillStyle = '#55706d';
labelContext.font = '800 27px system-ui, sans-serif';
labelContext.fillText(badge.toUpperCase(), 512, 174);
labelTexture.needsUpdate = true;
}
function analyzeFootprint(matrix) {
const rows = matrix.length;
const cols = matrix[0].length;
const rowData = [];
const colData = [];
for (let r = 0; r < rows; r++) {
const occupied = [];
for (let c = 0; c < cols; c++) {
if (matrix[r][c]) occupied.push(c);
}
const min = occupied.length ? Math.min(...occupied) : null;
const max = occupied.length ? Math.max(...occupied) : null;
const unbroken = occupied.length === 0 || occupied.length === max - min + 1;
rowData.push({ occupied, min, max, unbroken });
}
for (let c = 0; c < cols; c++) {
const occupied = [];
for (let r = 0; r < rows; r++) {
if (matrix[r][c]) occupied.push(r);
}
const min = occupied.length ? Math.min(...occupied) : null;
const max = occupied.length ? Math.max(...occupied) : null;
const unbroken = occupied.length === 0 || occupied.length === max - min + 1;
colData.push({ occupied, min, max, unbroken });
}
const brokenRows = rowData.map((d, i) => d.unbroken ? null : i).filter(i => i !== null);
const brokenCols = colData.map((d, i) => d.unbroken ? null : i).filter(i => i !== null);
return {
rows: rowData,
cols: colData,
brokenRows,
brokenCols,
active: brokenRows.length === 0 && brokenCols.length === 0
};
}
function disposeCurrentPiece() {
if (!currentPieceGroup) return;
currentPieceGroup.traverse(object => {
if (object.geometry) object.geometry.dispose();
});
scene.remove(currentPieceGroup);
currentPieceGroup = null;
currentVoxelMaterials = [];
currentEdgeMaterials = [];
currentTopMaterials = [];
}
function createPiece(matrix) {
disposeCurrentPiece();
const group = new THREE.Group();
const cellSize = 0.68;
const step = 0.77;
const height = 0.78;
const rows = matrix.length;
const cols = matrix[0].length;
const edgeGeometry = new THREE.EdgesGeometry(new THREE.BoxGeometry(cellSize, height, cellSize));
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
if (!matrix[r][c]) continue;
const x = (c - (cols - 1) / 2) * step;
const z = ((rows - 1) / 2 - r) * step;
const y = 0.48 + height / 2;
const bodyMaterial = new THREE.MeshStandardMaterial({
color: COLORS.voxel,
roughness: 0.62,
metalness: 0.05,
emissive: COLORS.voxel,
emissiveIntensity: 0.04
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(cellSize, height, cellSize),
bodyMaterial
);
body.position.set(x, y, z);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const topMaterial = new THREE.MeshStandardMaterial({
color: COLORS.voxelTop,
roughness: 0.78
});
const top = new THREE.Mesh(
new THREE.BoxGeometry(cellSize * 0.77, 0.055, cellSize * 0.77),
topMaterial
);
top.position.set(x, y + height / 2 + 0.027, z);
top.castShadow = true;
group.add(top);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x174d52,
transparent: true,
opacity: 0.28
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edges.position.copy(body.position);
group.add(edges);
currentVoxelMaterials.push(bodyMaterial);
currentTopMaterials.push(topMaterial);
currentEdgeMaterials.push(edgeMaterial);
}
}
currentPieceGroup = group;
currentPieceGroup.userData.spawn = 0;
scene.add(group);
}
function setPieceOutcome(active) {
const bodyColor = active ? COLORS.active : COLORS.inactive;
const edgeColor = active ? 0x117a54 : 0x9b3e36;
for (const material of currentVoxelMaterials) {
material.color.setHex(bodyColor);
material.emissive.setHex(bodyColor);
material.emissiveIntensity = active ? 0.14 : 0.08;
}
for (const material of currentEdgeMaterials) {
material.color.setHex(edgeColor);
material.opacity = active ? 0.42 : 0.34;
}
frameMaterial.color.setHex(bodyColor);
frameMaterial.emissive.setHex(bodyColor);
frameMaterial.emissiveIntensity = active ? 0.72 : 0.42;
beaconLight.color.setHex(bodyColor);
beaconLight.intensity = active ? 5.2 : 2.4;
for (const particle of particles) {
particle.visible = active;
particle.material.color.setHex(COLORS.active);
particle.material.emissive.setHex(COLORS.active);
}
}
function resetPieceColors() {
for (const material of currentVoxelMaterials) {
material.color.setHex(COLORS.voxel);
material.emissive.setHex(COLORS.voxel);
material.emissiveIntensity = 0.04;
}
for (const material of currentEdgeMaterials) {
material.color.setHex(0x174d52);
material.opacity = 0.28;
}
frameMaterial.color.setHex(COLORS.neutralFrame);
frameMaterial.emissive.setHex(COLORS.neutralFrame);
frameMaterial.emissiveIntensity = 0.08;
beaconLight.color.setHex(0xffffff);
beaconLight.intensity = 0;
for (const particle of particles) particle.visible = false;
}
function renderMiniMap(matrix, analysis = null, reveal = false) {
const map = $('miniMap');
map.innerHTML = '';
for (let r = 0; r < matrix.length; r++) {
for (let c = 0; c < matrix[r].length; c++) {
const cell = document.createElement('div');
cell.className = 'mini-cell';
if (matrix[r][c]) {
cell.classList.add('filled');
if (reveal) cell.classList.add(analysis.active ? 'active' : 'inactive');
} else if (reveal && analysis && analysis.brokenCols.includes(c)) {
const column = analysis.cols[c];
if (column.min !== null && column.max !== null && r > column.min && r < column.max) {
cell.classList.add('gap');
}
}
cell.setAttribute('aria-label', matrix[r][c] ? 'Occupied voxel' : 'Empty voxel');
map.appendChild(cell);
}
}
}
function updateProgress() {
$('progressText').textContent = `${String(Math.min(roundIndex + 1, 3)).padStart(2, '0')} / 03`;
document.querySelectorAll('.step').forEach((step, index) => {
step.classList.toggle('done', index < roundIndex || finished);
step.classList.toggle('current', index === roundIndex && !finished);
});
}
function loadRound() {
answered = false;
finished = false;
const round = rounds[roundIndex];
currentAnalysis = analyzeFootprint(round.matrix);
$('pieceTitle').textContent = round.name;
$('pieceDescription').textContent = round.description;
$('pieceBadge').textContent = round.badge;
$('pieceBadge').className = `badge ${round.badgeClass}`.trim();
$('questionText').textContent = `Will ${round.name} activate?`;
$('rowsReadout').textContent = 'Sealed';
$('colsReadout').textContent = 'Sealed';
$('rowsReadout').className = 'readout-value sealed';
$('colsReadout').className = 'readout-value sealed';
$('predictionArea').hidden = false;
$('resultArea').hidden = true;
$('resultArea').className = 'result-area';
$('sceneChip').className = 'scene-chip';
$('sceneChip').textContent = 'Prediction sealed';
renderMiniMap(round.matrix);
createPiece(round.matrix);
resetPieceColors();
updateBoardLabel(round.name, round.badge);
updateProgress();
}
function roundExplanation(round, analysis) {
if (roundIndex === 0) {
return analysis.active
? 'Every occupied row and column is continuous, so the Square activates.'
: 'The Square contains a broken line, so it stays dark.';
}
if (roundIndex === 1) {
const column = analysis.brokenCols[0] + 1;
return analysis.active
? 'Every occupied line remains continuous, so the C activates.'
: `The middle column contains a gap between the arms, so the C stays dark. Check column ${column}.`;
}
return analysis.active
? 'This shape is new, but every occupied row and column is still one unbroken run. The Cross activates under the same rule.'
: 'The new shape contains a broken occupied line. The rule remains unchanged, so it stays dark.';
}
function answerPrediction(prediction) {
if (answered || finished) return;
answered = true;
const round = rounds[roundIndex];
const analysis = analyzeFootprint(round.matrix);
const actual = analysis.active;
const correct = prediction === actual;
if (correct) score++;
$('predictionArea').hidden = true;
$('resultArea').hidden = false;
$('resultArea').className = `result-area ${correct ? 'good' : 'bad'}`;
$('resultSymbol').textContent = correct ? '✓' : '×';
$('resultTitle').textContent = correct
? (actual ? 'Correct — it activates.' : 'Correct — it stays dark.')
: (actual ? 'Not quite — it activates.' : 'Not quite — it stays dark.');
$('resultText').textContent = roundExplanation(round, analysis);
$('continueButton').textContent = roundIndex === rounds.length - 1
? 'FINISH THE TRANSFER'
: 'CONTINUE TO THE NEXT PIECE';
const rowsGood = analysis.brokenRows.length === 0;
const colsGood = analysis.brokenCols.length === 0;
$('rowsReadout').textContent = rowsGood
? `${analysis.rows.length}/${analysis.rows.length} continuous`
: `${analysis.rows.length - analysis.brokenRows.length}/${analysis.rows.length} continuous`;
$('colsReadout').textContent = colsGood
? `${analysis.cols.length}/${analysis.cols.length} continuous`
: `${analysis.cols.length - analysis.brokenCols.length}/${analysis.cols.length} continuous`;
$('rowsReadout').className = `readout-value ${rowsGood ? 'good' : 'bad'}`;
$('colsReadout').className = `readout-value ${colsGood ? 'good' : 'bad'}`;
$('sceneChip').className = `scene-chip ${actual ? 'active' : 'inactive'}`;
$('sceneChip').textContent = actual ? 'Rule output · activate' : 'Rule output · stay dark';
renderMiniMap(round.matrix, analysis, true);
setPieceOutcome(actual);
}
function continueGame() {
if (!answered) return;
if (roundIndex === rounds.length - 1) {
finished = true;
const analysis = analyzeFootprint(rounds[roundIndex].matrix);
const actual = analysis.active;
$('predictionArea').hidden = true;
$('resultArea').hidden = false;
$('resultArea').className = `result-area ${score === 3 ? 'good' : 'bad'}`;
$('resultSymbol').textContent = score === 3 ? '★' : `${score}/3`;
$('resultTitle').textContent = score === 3
? 'Perfect rule transfer.'
: `Transfer complete: ${score} of 3 correct.`;
$('resultText').textContent = actual
? 'The unseen Cross activates because every occupied row and column is continuous. You tested the geometric property, not the shape’s name.'
: 'The unseen shape was evaluated with the same row-and-column property used in the calibration rounds.';
$('continueButton').textContent = 'PLAY AGAIN';
updateProgress();
return;
}
roundIndex++;
loadRound();
}
document.querySelectorAll('[data-prediction]').forEach(button => {
button.addEventListener('click', () => {
answerPrediction(button.dataset.prediction === 'active');
});
});
$('continueButton').addEventListener('click', () => {
if (finished) {
score = 0;
roundIndex = 0;
loadRound();
} else {
continueGame();
}
});
window.addEventListener('keydown', event => {
if (event.key === '1') answerPrediction(false);
if (event.key === '2') answerPrediction(true);
if (event.key === 'Enter' && !event.repeat) {
if (finished) {
score = 0;
roundIndex = 0;
loadRound();
} else if (answered) {
continueGame();
}
}
});
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
target.x + cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
target.y + cameraState.radius * Math.cos(cameraState.polar),
target.z + cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
const aspect = width / height;
let frustumHeight = 6.25;
if (aspect < 0.8) frustumHeight = 10.8;
else if (aspect < 1.2) frustumHeight = 8.2;
camera.left = -frustumHeight * aspect / 2;
camera.right = frustumHeight * aspect / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
updateCamera();
}
window.addEventListener('resize', resize);
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener('pointerdown', event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= dx * 0.008;
cameraState.polar = THREE.MathUtils.clamp(cameraState.polar + dy * 0.006, 0.43, 1.16);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener('pointerup', stopDragging);
canvas.addEventListener('pointercancel', stopDragging);
canvas.addEventListener('wheel', event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom - event.deltaY * 0.001, 0.78, 2.05);
updateCamera();
}, { passive: false });
canvas.addEventListener('dblclick', () => {
cameraState.azimuth = 0.58;
cameraState.polar = 0.77;
cameraState.zoom = window.innerWidth < 760 ? 0.86 : 1.32;
updateCamera();
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (currentPieceGroup) {
currentPieceGroup.userData.spawn = Math.min(1, currentPieceGroup.userData.spawn + dt * 2.8);
const t = currentPieceGroup.userData.spawn;
const c1 = 1.70158;
const c3 = c1 + 1;
const eased = 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
currentPieceGroup.scale.setScalar(0.72 + eased * 0.28);
currentPieceGroup.position.y = (1 - eased) * -0.35;
}
const pulse = 0.72 + Math.sin(time * 3.2) * 0.16;
frameMaterial.emissiveIntensity = answered ? pulse : 0.08;
beaconLight.intensity = answered ? 3.5 + Math.sin(time * 3.2) * 1.2 : 0;
for (const particle of particles) {
if (!particle.visible) continue;
const data = particle.userData;
const phase = (time * data.speed + data.offset) % 1;
particle.position.set(
data.x,
0.9 + phase * 2.5,
data.z
);
particle.rotation.x = time * 0.8 + data.offset * 4;
particle.rotation.y = time * 1.1 + data.offset * 3;
const scale = Math.max(0.05, 1 - phase);
particle.scale.setScalar(scale);
particle.material.opacity = Math.sin(phase * Math.PI) * 0.8;
}
renderer.render(scene, camera);
}
resize();
loadRound();
animate();
requestAnimationFrame(() => {
$('loading').classList.add('hide');
setTimeout(() => $('loading').remove(), 450);
});
</script>
</body>
</html>
```