Prompt specification
Build or customize the Three.js 3D scene "Pattern Rule Versus Memorized Sequence" 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: Pattern Rule Versus Memorized Sequence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pattern-rule-versus-memorized-sequence-x3468
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: pattern rule versus memorized sequence. Create a puzzle with repeated patterns and one generated continuation task. Clearly distinguish copying a sequence from inferring a stated rule that can predict new steps.
Working Three.js Starter (pattern-rule-versus-memorized-sequence-x3468):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Pattern Lab — Copy vs. Infer</title>
<style>
:root {
color-scheme: dark;
--bg: #071117;
--panel: #0d1a22;
--panel-2: #12242e;
--line: #24404c;
--text: #e8f4f7;
--muted: #91aab4;
--cyan: #49ddd5;
--amber: #ffc857;
--coral: #ff7272;
--purple: #b78aff;
--green: #72e6a1;
--danger: #ff8585;
}
* {
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;
}
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
}
#hud {
position: relative;
z-index: 5;
min-width: 0;
height: 100%;
overflow-y: auto;
padding: 24px 22px;
background:
radial-gradient(circle at 15% 0%, rgba(73, 221, 213, 0.09), transparent 34%),
linear-gradient(180deg, #0c1921 0%, #09151c 100%);
border-right: 1px solid var(--line);
box-shadow: 16px 0 50px rgba(0, 0, 0, 0.24);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 22px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid rgba(73, 221, 213, 0.45);
border-radius: 12px;
background: rgba(73, 221, 213, 0.08);
color: var(--cyan);
font-size: 22px;
font-weight: 800;
box-shadow: inset 0 0 20px rgba(73, 221, 213, 0.08);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: 0.02em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 18px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(0, 0, 0, 0.15);
}
.tab {
min-height: 52px;
padding: 9px 8px;
border: 0;
border-radius: 10px;
color: var(--muted);
background: transparent;
cursor: pointer;
transition: 160ms ease;
}
.tab strong,
.tab small {
display: block;
}
.tab strong {
font-size: 13px;
margin-bottom: 3px;
}
.tab small {
font-size: 10px;
line-height: 1.2;
}
.tab:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.035);
}
.tab.active {
color: #071117;
background: var(--cyan);
box-shadow: 0 5px 18px rgba(73, 221, 213, 0.18);
}
.tab[data-mode="rule"].active {
background: var(--amber);
}
.card {
margin-bottom: 14px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: linear-gradient(145deg, rgba(20, 39, 49, 0.92), rgba(10, 24, 31, 0.92));
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#ruleMode .eyebrow {
color: var(--amber);
}
.card h2 {
margin: 0 0 9px;
font-size: 21px;
line-height: 1.18;
}
.card p {
margin: 0;
color: #b4c7ce;
font-size: 13px;
line-height: 1.55;
}
.rule-box {
margin-top: 13px;
padding: 12px 13px;
border-left: 3px solid var(--amber);
border-radius: 0 10px 10px 0;
background: rgba(255, 200, 87, 0.07);
color: #f7e6bd;
font-size: 12px;
line-height: 1.55;
}
.task-id {
display: inline-flex;
margin-top: 11px;
padding: 5px 8px;
border: 1px solid rgba(255, 200, 87, 0.25);
border-radius: 999px;
color: var(--amber);
background: rgba(255, 200, 87, 0.06);
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.selection {
min-height: 39px;
margin-top: 14px;
padding: 10px 12px;
border: 1px dashed #36515d;
border-radius: 10px;
color: var(--text);
background: rgba(0, 0, 0, 0.14);
font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.quick-label {
margin: 14px 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.quick-choices {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.quick-choices button {
min-height: 38px;
border: 1px solid #36515d;
border-radius: 9px;
color: var(--text);
background: #10242d;
cursor: pointer;
font-weight: 800;
transition: 140ms ease;
}
.quick-choices button:hover {
border-color: var(--cyan);
transform: translateY(-1px);
}
.quick-choices button.active {
border-color: var(--cyan);
color: #071117;
background: var(--cyan);
}
#ruleMode .quick-choices button.active {
border-color: var(--amber);
background: var(--amber);
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 14px;
}
.actions button,
.view-button {
min-height: 39px;
padding: 9px 12px;
border: 1px solid #36515d;
border-radius: 10px;
color: var(--text);
background: #132832;
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: 140ms ease;
}
.actions button:hover,
.view-button:hover {
border-color: #6b8a97;
transform: translateY(-1px);
}
.actions .primary {
flex: 1;
border-color: var(--cyan);
color: #061216;
background: var(--cyan);
}
#ruleMode .actions .primary {
border-color: var(--amber);
background: var(--amber);
}
#status {
min-height: 48px;
margin-top: 13px;
padding: 11px 12px;
border-radius: 10px;
color: var(--muted);
background: rgba(0, 0, 0, 0.16);
font-size: 12px;
line-height: 1.45;
}
#status[data-state="good"] {
color: #baf5cf;
background: rgba(114, 230, 161, 0.1);
border: 1px solid rgba(114, 230, 161, 0.28);
}
#status[data-state="bad"] {
color: #ffc1c1;
background: rgba(255, 114, 114, 0.09);
border: 1px solid rgba(255, 114, 114, 0.28);
}
.compare-card {
padding: 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(6, 16, 22, 0.58);
}
.compare-card h3 {
margin: 0 0 12px;
font-size: 12px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.compare-row {
display: grid;
grid-template-columns: 73px 1fr;
gap: 11px;
padding: 10px 0;
border-top: 1px solid rgba(93, 126, 138, 0.18);
}
.compare-row:first-of-type {
border-top: 0;
}
.compare-row strong {
font-size: 11px;
letter-spacing: 0.07em;
}
.compare-row:nth-child(2) strong {
color: var(--cyan);
}
.compare-row:nth-child(3) strong {
color: var(--amber);
}
.compare-row span {
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #071117;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.stage-badge {
position: absolute;
z-index: 3;
top: 20px;
left: 20px;
padding: 9px 12px;
border: 1px solid rgba(73, 221, 213, 0.4);
border-radius: 999px;
color: var(--cyan);
background: rgba(7, 17, 23, 0.78);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
.stage-badge.rule {
border-color: rgba(255, 200, 87, 0.45);
color: var(--amber);
}
.stage-hint {
position: absolute;
z-index: 3;
right: 20px;
bottom: 18px;
padding: 8px 11px;
border-radius: 9px;
color: var(--muted);
background: rgba(7, 17, 23, 0.7);
font-size: 11px;
pointer-events: none;
}
.view-button {
position: absolute;
z-index: 4;
top: 16px;
right: 18px;
background: rgba(10, 27, 35, 0.85);
backdrop-filter: blur(10px);
}
#loading {
position: absolute;
z-index: 8;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: #071117;
font-size: 13px;
letter-spacing: 0.08em;
}
@media (max-width: 820px) {
html,
body {
overflow: auto;
}
#app {
display: flex;
flex-direction: column;
min-height: 100%;
}
#stage {
order: 0;
width: 100%;
height: 55vh;
min-height: 390px;
}
#hud {
order: 1;
width: 100%;
height: auto;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
}
@media (max-width: 480px) {
#hud {
padding: 20px 16px;
}
.stage-hint {
display: none;
}
.card h2 {
font-size: 19px;
}
}
</style>
</head>
<body>
<div id="app">
<aside id="hud">
<div class="brand">
<div class="brand-mark">V</div>
<div>
<h1>Voxel Pattern Lab</h1>
<p>Copy vs. infer</p>
</div>
</div>
<nav class="tabs" aria-label="Puzzle mode">
<button class="tab active" data-mode="copy" aria-selected="true">
<strong>01 · Copy</strong>
<small>Recall observed frames</small>
</button>
<button class="tab" data-mode="rule" aria-selected="false">
<strong>02 · Infer</strong>
<small>Predict an unseen frame</small>
</button>
</nav>
<section id="copyMode" class="card">
<div class="eyebrow">Memorization trial · no unseen prediction</div>
<h2>Reproduce the repeated trio</h2>
<p>
Observe the three back-row frames. The first motif returns in frame 3.
Hide the examples, then select candidates in the same order:
first, second, third.
</p>
<div id="copySelection" class="selection">No frames selected</div>
<div class="quick-label">Candidate keys</div>
<div id="copyQuickChoices" class="quick-choices"></div>
<div class="actions">
<button id="hideSource">Hide sequence</button>
<button id="copyReset">Reset</button>
<button id="copyCheck" class="primary">Check copy</button>
</div>
</section>
<section id="ruleMode" class="card" hidden>
<div class="eyebrow">Rule trial · generated unseen continuation</div>
<h2>Predict the fourth frame</h2>
<p>
Three generated frames demonstrate one transformation. Apply the
stated rule and select the candidate that can represent frame 4.
</p>
<div class="rule-box">
<strong>Stated rule:</strong> Each step adds one solid block to the
right end of the base row. The white marker moves clockwise around
the outer square by one corner. New blocks use the next color in the
repeating cycle:
<strong>cyan → amber → coral → cyan</strong>.
</div>
<div id="ruleTaskId" class="task-id">GENERATED TASK</div>
<div id="ruleSelection" class="selection">No candidate selected</div>
<div class="quick-label">Candidate keys</div>
<div id="ruleQuickChoices" class="quick-choices"></div>
<div class="actions">
<button id="generateRule">New task</button>
<button id="ruleReset">Reset</button>
<button id="ruleCheck" class="primary">Check prediction</button>
</div>
</section>
<div id="status" role="status" aria-live="polite">
Select a mode, then use the voxel candidates or the letter keys.
</div>
<section class="compare-card">
<h3>What the two trials test</h3>
<div class="compare-row">
<strong>COPY</strong>
<span>
Exact reproduction of observed frames. A perfect copy still does
not determine what an unseen next frame should be.
</span>
</div>
<div class="compare-row">
<strong>INFER</strong>
<span>
Use a stated transformation and its examples to derive a prediction
for a frame that was never shown.
</span>
</div>
</section>
</aside>
<main id="stage" aria-label="Interactive voxel puzzle">
<div id="loading">Loading voxel engine…</div>
<div id="stageBadge" class="stage-badge">Memory / exact copy</div>
<button id="resetView" class="view-button">Reset view</button>
<div class="stage-hint">Drag to orbit · Scroll to zoom · Click a candidate</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const COLORS = {
cyan: 0x49ddd5,
amber: 0xffc857,
coral: 0xff7272,
purple: 0xb78aff,
green: 0x72e6a1,
white: 0xf3f8fa,
dark: 0x0b171e
};
const stage = $("#stage");
const loading = $("#loading");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional voxel puzzle. Drag to orbit, scroll to zoom, and click candidates."
);
renderer.domElement.tabIndex = 0;
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071117);
scene.fog = new THREE.Fog(0x071117, 17, 31);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const orbit = {
theta: 0.02,
phi: 0.93,
radius: 15.2,
target: new THREE.Vector3(0, 0.55, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.radius * Math.cos(orbit.phi) + orbit.target.y,
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
const hemisphere = new THREE.HemisphereLight(0xbfefff, 0x102028, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd9f7ff, 3.2);
keyLight.position.set(-4, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x39d6d0, 14, 18, 2);
rimLight.position.set(5, 4, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffc857, 9, 15, 2);
warmLight.position.set(-5, 2, 5);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 26),
new THREE.MeshStandardMaterial({
color: 0x08151b,
roughness: 0.94,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.19;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x244b56, 0x153039);
grid.position.y = -0.175;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
let content = new THREE.Group();
scene.add(content);
let mode = "copy";
let candidateRoots = [];
let sourceVoxelRoots = [];
let copyCandidates = [];
let copyPicks = [];
let copyHidden = false;
let ruleCandidates = [];
let rulePick = null;
let hoveredCandidate = -1;
let ruleSeed = 4817;
let ruleState = createRuleState(ruleSeed);
function seededRandom(seed) {
let t = seed >>> 0;
return function () {
t += 0x6d2b79f5;
let r = Math.imul(t ^ (t >>> 15), 1 | t);
r ^= r + Math.imul(r ^ (r >>> 7), 61 | r);
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
};
}
function shuffled(items, random = Math.random) {
const result = [...items];
for (let i = result.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
function disposeContent() {
scene.remove(content);
content.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
content = new THREE.Group();
scene.add(content);
}
function makeTextSprite(text, color = "#d8f7f4", width = 2.4) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const x = 16;
const y = 15;
const w = 480;
const h = 80;
const radius = 19;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + w - radius, y);
context.quadraticCurveTo(x + w, y, x + w, y + radius);
context.lineTo(x + w, y + h - radius);
context.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
context.lineTo(x + radius, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = "rgba(7, 20, 27, 0.9)";
context.fill();
context.strokeStyle = color;
context.globalAlpha = 0.5;
context.lineWidth = 3;
context.stroke();
context.globalAlpha = 1;
context.fillStyle = color;
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 56);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.219, 1);
sprite.renderOrder = 20;
return sprite;
}
function makePedestal(x, z, label, candidate = false) {
const root = new THREE.Group();
root.position.set(x, 0, z);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x10242d,
roughness: 0.72,
metalness: 0.12,
emissive: 0x000000
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(1.9, 0.18, 1.52),
baseMaterial
);
base.position.y = -0.07;
base.castShadow = true;
base.receiveShadow = true;
root.add(base);
const top = new THREE.Mesh(
new THREE.BoxGeometry(1.78, 0.055, 1.4),
new THREE.MeshStandardMaterial({
color: candidate ? 0x102a32 : 0x0d2028,
roughness: 0.86,
metalness: 0.05
})
);
top.position.y = 0.035;
top.receiveShadow = true;
root.add(top);
const accentMaterial = new THREE.MeshStandardMaterial({
color: candidate ? 0x49ddd5 : 0x315762,
emissive: candidate ? 0x123b3d : 0x071719,
emissiveIntensity: 0.8,
roughness: 0.45
});
const accent = new THREE.Mesh(
new THREE.BoxGeometry(1.22, 0.035, 0.035),
accentMaterial
);
accent.position.set(0, 0.078, 0.72);
root.add(accent);
const points = [];
const gridWidth = 1.5;
const gridDepth = 1.0;
for (let col = 0; col <= 6; col++) {
const px = -gridWidth / 2 + col * 0.25;
points.push(
new THREE.Vector3(px, 0.075, -gridDepth / 2),
new THREE.Vector3(px, 0.075, gridDepth / 2)
);
}
for (let row = 0; row <= 4; row++) {
const pz = -gridDepth / 2 + row * 0.25;
points.push(
new THREE.Vector3(-gridWidth / 2, 0.075, pz),
new THREE.Vector3(gridWidth / 2, 0.075, pz)
);
}
const gridGeometry = new THREE.BufferGeometry().setFromPoints(points);
const gridLines = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x31545f,
transparent: true,
opacity: 0.4
})
);
root.add(gridLines);
const labelSprite = makeTextSprite(
label,
candidate ? "#49ddd5" : "#a6c5ce",
candidate ? 1.1 : 1.45
);
labelSprite.position.y = 1.55;
root.add(labelSprite);
root.userData.baseMaterial = baseMaterial;
root.userData.accentMaterial = accentMaterial;
return root;
}
function makeVoxelModel(model) {
const root = new THREE.Group();
for (const cell of model.cells) {
const material = new THREE.MeshStandardMaterial({
color: cell.color,
roughness: 0.58,
metalness: 0.07,
emissive: cell.color,
emissiveIntensity: cell.role === "marker" ? 0.22 : 0.035
});
const voxel = new THREE.Mesh(
new THREE.BoxGeometry(0.215, 0.215, 0.215),
material
);
voxel.position.set(
(cell.c - 3) * 0.25,
0.21 + cell.r * 0.25,
0
);
voxel.castShadow = true;
voxel.receiveShadow = true;
root.add(voxel);
}
return root;
}
function signature(model) {
return model.cells
.map((cell) => `${cell.c},${cell.r},${cell.color}`)
.sort()
.join("|");
}
function makeCopyModel(name, cells) {
return {
name,
cells: cells.map(([c, r, color]) => ({
c,
r,
color,
role: "block"
}))
};
}
const shape = [
[0, 0],
[1, 0],
[2, 0],
[0, 1],
[1, 1]
];
const copyModels = {
A: makeCopyModel(
"A",
shape.map(([c, r]) => [c, r, COLORS.cyan])
),
B: makeCopyModel(
"B",
shape.map(([c, r]) => [c + 4, r + 3, COLORS.amber])
),
C: makeCopyModel(
"C",
shape.map(([c, r]) => [c + 4, r, COLORS.purple])
),
D: makeCopyModel(
"D",
[
[4, 3],
[5, 3],
[6, 3],
[6, 4],
[5, 4]
].map(([c, r]) => [c, r, COLORS.green])
)
};
function createRuleState(seed) {
const random = seededRandom(seed);
return {
seed,
startLength: 2 + Math.floor(random() * 2),
colorPhase: Math.floor(random() * 3),
markerStart: Math.floor(random() * 4)
};
}
const ruleColors = [COLORS.cyan, COLORS.amber, COLORS.coral];
const markerCorners = [
{ c: 0, r: 4 },
{ c: 6, r: 4 },
{ c: 6, r: 0 },
{ c: 0, r: 0 }
];
function buildRuleModel(state, step, lengthOverride = null) {
const length = lengthOverride ?? state.startLength + step;
const markerIndex =
(state.markerStart + step + 4) % markerCorners.length;
const marker = markerCorners[markerIndex];
const cells = [];
for (let i = 0; i < length; i++) {
cells.push({
c: i,
r: 1,
color: ruleColors[(state.colorPhase + i) % ruleColors.length],
role: "block"
});
}
cells.push({
c: marker.c,
r: marker.r,
color: COLORS.white,
role: "marker"
});
return { cells };
}
function addSectionTitle(text, z, color) {
const title = makeTextSprite(text, color, 4.2);
title.position.set(0, 2.12, z);
content.add(title);
}
function renderCopyMode() {
disposeContent();
candidateRoots = [];
sourceVoxelRoots = [];
copyPicks = [];
copyHidden = false;
addSectionTitle("OBSERVED SEQUENCE • COPY", -2.55, "#7de9df");
const sourceModels = [copyModels.A, copyModels.B, copyModels.A];
const sourceX = [-2.8, 0, 2.8];
sourceModels.forEach((model, index) => {
const pedestal = makePedestal(
sourceX[index],
-2.55,
`FRAME ${index + 1}`,
false
);
const voxels = makeVoxelModel(model);
pedestal.add(voxels);
sourceVoxelRoots.push(voxels);
content.add(pedestal);
});
addSectionTitle("CHOOSE A, B, C, D", 2.55, "#a6c5ce");
copyCandidates = shuffled(
[copyModels.A, copyModels.B, copyModels.C, copyModels.D],
seededRandom(9031)
);
const candidateX = [-4.2, -1.4, 1.4, 4.2];
copyCandidates.forEach((model, index) => {
const pedestal = makePedestal(
candidateX[index],
2.55,
String.fromCharCode(65 + index),
true
);
pedestal.userData.candidateIndex = index;
pedestal.userData.modelRoot = makeVoxelModel(model);
pedestal.add(pedestal.userData.modelRoot);
candidateRoots.push(pedestal);
content.add(pedestal);
});
$("#hideSource").textContent = "Hide sequence";
updateCopySelection();
updateCandidateVisuals();
buildQuickChoices("copy");
}
function renderRuleMode() {
disposeContent();
candidateRoots = [];
sourceVoxelRoots = [];
rulePick = null;
addSectionTitle("GENERATED EXAMPLES • FRAMES 1–3", -2.55, "#ffe09a");
const sourceModels = [0, 1, 2].map((step) =>
buildRuleModel(ruleState, step)
);
const sourceX = [-2.8, 0, 2.8];
sourceModels.forEach((model, index) => {
const pedestal = makePedestal(
sourceX[index],
-2.55,
`FRAME ${index + 1}`,
false
);
pedestal.add(makeVoxelModel(model));
content.add(pedestal);
});
addSectionTitle("WHICH CANDIDATE IS FRAME 4?", 2.55, "#ffe09a");
const correct = buildRuleModel(ruleState, 3);
const wrongMarker = {
cells: correct.cells.map((cell) => ({ ...cell }))
};
wrongMarker.cells.find((cell) => cell.role === "marker").color =
COLORS.coral;
const wrongColor = {
cells: correct.cells.map((cell) => ({ ...cell }))
};
const lastBlock = wrongColor.cells
.filter((cell) => cell.role === "block")
.sort((a, b) => a.c - b.c)
.pop();
lastBlock.color =
lastBlock.color === COLORS.cyan ? COLORS.coral : COLORS.cyan;
const stalled = {
cells: correct.cells
.filter((cell) => {
if (cell.role !== "block") return true;
return cell.c !== correct.cells.filter((c) => c.role === "block").length - 1;
})
.map((cell) => ({ ...cell }))
};
ruleCandidates = shuffled([
{ ...correct, isCorrect: true, label: "correct continuation" },
{ ...wrongMarker, isCorrect: false, label: "incorrect marker" },
{ ...wrongColor, isCorrect: false, label: "incorrect new-block color" },
{ ...stalled, isCorrect: false, label: "missing new block" }
]);
const candidateX = [-4.2, -1.4, 1.4, 4.2];
ruleCandidates.forEach((model, index) => {
const pedestal = makePedestal(
candidateX[index],
2.55,
String.fromCharCode(65 + index),
true
);
pedestal.userData.candidateIndex = index;
pedestal.userData.modelRoot = makeVoxelModel(model);
pedestal.add(pedestal.userData.modelRoot);
candidateRoots.push(pedestal);
content.add(pedestal);
});
$("#ruleTaskId").textContent =
`GENERATED CONTINUATION #R-${1000 + (ruleState.seed % 9000)}`;
updateRuleSelection();
updateCandidateVisuals();
buildQuickChoices("rule");
}
function buildQuickChoices(which) {
const container =
which === "copy"
? $("#copyQuickChoices")
: $("#ruleQuickChoices");
container.innerHTML = "";
for (let i = 0; i < 4; i++) {
const button = document.createElement("button");
button.textContent = String.fromCharCode(65 + i);
button.setAttribute(
"aria-label",
`Select candidate ${String.fromCharCode(65 + i)}`
);
button.addEventListener("click", () => selectCandidate(i));
container.appendChild(button);
}
}
function selectCandidate(index) {
if (mode === "copy") {
if (copyPicks.length >= 3) {
setStatus(
"Three frames are already selected. Reset the sequence or check your copy.",
"bad"
);
return;
}
copyPicks.push(index);
updateCopySelection();
updateCandidateVisuals();
setStatus("Selection updated. Check the exact order when ready.");
return;
}
rulePick = index;
updateRuleSelection();
updateCandidateVisuals();
setStatus(
`Candidate ${String.fromCharCode(65 + index)} selected. Check the prediction when ready.`
);
}
function updateCopySelection() {
const text = copyPicks.length
? copyPicks
.map((index) => String.fromCharCode(65 + index))
.join(" → ")
: "No frames selected";
$("#copySelection").textContent = text;
const buttons = $("#copyQuickChoices").children;
for (let i = 0; i < buttons.length; i++) {
const count = copyPicks.filter((pick) => pick === i).length;
buttons[i].classList.toggle("active", count > 0);
buttons[i].textContent =
count > 1
? `${String.fromCharCode(65 + i)} ×${count}`
: String.fromCharCode(65 + i);
}
}
function updateRuleSelection() {
$("#ruleSelection").textContent =
rulePick === null
? "No candidate selected"
: `Selected candidate ${String.fromCharCode(65 + rulePick)}`;
const buttons = $("#ruleQuickChoices").children;
for (let i = 0; i < buttons.length; i++) {
buttons[i].classList.toggle("active", i === rulePick);
}
}
function updateCandidateVisuals() {
candidateRoots.forEach((root, index) => {
const selected =
mode === "copy"
? copyPicks.includes(index)
: index === rulePick;
const hovered = hoveredCandidate === index;
const accent = selected || hovered;
const baseMaterial = root.userData.baseMaterial;
const accentMaterial = root.userData.accentMaterial;
baseMaterial.color.setHex(accent ? 0x1b4149 : 0x10242d);
baseMaterial.emissive.setHex(accent ? 0x0c3439 : 0x000000);
baseMaterial.emissiveIntensity = accent ? 0.55 : 0;
accentMaterial.color.setHex(
selected
? mode === "copy"
? COLORS.cyan
: COLORS.amber
: hovered
? 0x7b9ca6
: mode === "copy"
? 0x24767a
: 0x8f7337
);
root.userData.modelRoot.scale.setScalar(selected ? 1.045 : 1);
});
}
function setStatus(message, state = "neutral") {
const status = $("#status");
status.textContent = message;
status.dataset.state = state;
}
function checkCopy() {
if (copyPicks.length !== 3) {
setStatus("Select exactly three candidate frames before checking.", "bad");
return;
}
const desired = [copyModels.A, copyModels.B, copyModels.A];
const correct = copyPicks.every(
(candidateIndex, position) =>
signature(copyCandidates[candidateIndex]) ===
signature(desired[position])
);
if (correct) {
setStatus(
"Exact copy complete. You reproduced the observed frames—including the repeated first frame. This demonstrates recall, but it still does not determine an unseen frame 4.",
"good"
);
} else {
setStatus(
"Not an exact copy. Check the voxel color, position, orientation, and frame order.",
"bad"
);
}
}
function checkRule() {
if (rulePick === null) {
setStatus("Select the candidate that represents the unseen fourth frame.", "bad");
return;
}
const selected = ruleCandidates[rulePick];
const correct = ruleCandidates.find((candidate) => candidate.isCorrect);
if (signature(selected) === signature(correct)) {
setStatus(
"Prediction correct. Frame 4 was derived from the stated rule rather than remembered from the examples: the base grew, the marker moved clockwise, and the color cycle repeated.",
"good"
);
} else {
setStatus(
"That candidate breaks the rule. Check all three components: base length, marker corner, and the color of the newly added block.",
"bad"
);
}
}
function setMode(nextMode) {
mode = nextMode;
document.querySelectorAll(".tab").forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-selected", String(active));
});
$("#copyMode").hidden = mode !== "copy";
$("#ruleMode").hidden = mode !== "rule";
const badge = $("#stageBadge");
badge.classList.toggle("rule", mode === "rule");
badge.textContent =
mode === "copy"
? "Memory / exact copy"
: "Rule / unseen prediction";
if (mode === "copy") {
renderCopyMode();
setStatus(
"Observe the three frames, or hide them and select three candidates in the same order."
);
} else {
renderRuleMode();
setStatus(
"Read the stated rule, inspect the three generated examples, and select the predicted fourth frame."
);
}
}
// Direct camera controls: no addons are used.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function setPointerFromEvent(event) {
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;
}
function candidateAtPointer(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(candidateRoots, true);
if (!intersections.length) return -1;
let object = intersections[0].object;
while (object && object.userData.candidateIndex === undefined) {
object = object.parent;
}
return object ? object.userData.candidateIndex : -1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.38,
1.32
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
const index = candidateAtPointer(event);
if (index !== hoveredCandidate) {
hoveredCandidate = index;
renderer.domElement.style.cursor = index >= 0 ? "pointer" : "grab";
updateCandidateVisuals();
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!pointerMoved) {
const index = candidateAtPointer(event);
if (index >= 0) selectCandidate(index);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerMoved = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
hoveredCandidate = -1;
updateCandidateVisuals();
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
9.5,
22
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.fov = camera.aspect < 1.2 ? 50 : 40;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
document.querySelectorAll(".tab").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
$("#hideSource").addEventListener("click", () => {
copyHidden = !copyHidden;
sourceVoxelRoots.forEach((root) => {
root.visible = !copyHidden;
});
$("#hideSource").textContent = copyHidden
? "Show sequence"
: "Hide sequence";
setStatus(
copyHidden
? "The source frames are hidden. Select the remembered frames in order."
: "The source frames are visible again."
);
});
$("#copyReset").addEventListener("click", () => {
copyPicks = [];
updateCopySelection();
updateCandidateVisuals();
setStatus("Copy sequence reset.");
});
$("#copyCheck").addEventListener("click", checkCopy);
$("#ruleReset").addEventListener("click", () => {
rulePick = null;
updateRuleSelection();
updateCandidateVisuals();
setStatus("Prediction reset.");
});
$("#ruleCheck").addEventListener("click", checkRule);
$("#generateRule").addEventListener("click", () => {
ruleSeed = (ruleSeed + 7919) >>> 0;
ruleState = createRuleState(ruleSeed);
renderRuleMode();
setStatus(
"A new generated continuation task is ready. The examples changed, but the stated rule is the same."
);
});
$("#resetView").addEventListener("click", () => {
orbit.theta = 0.02;
orbit.phi = 0.93;
orbit.radius = 15.2;
updateCamera();
});
resize();
updateCamera();
setMode("copy");
loading.remove();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```