Prompt specification
Build or customize the Three.js 3D scene "Discover a Counterexample to a False Rule" 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: Discover a Counterexample to a False Rule
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/discover-a-counterexample-to-a-false-rule-x3600
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly rule-discovery game on a small workbench. There are red and blue blocks in several shapes, plus a gate that opens when a block has a circular footprint. A hypothesis card initially suggests that all red blocks open the gate. Let the player test individual blocks and leave each result beside the test platform. Include a red square block and a blue round block so the false color rule can be challenged by clear examples. Reveal the actual rule only after testing or on request. Keep the geometry and results consistent across resets; success should depend on the demonstrated property, not an item's name.
Working Three.js Starter (discover-a-counterexample-to-a-false-rule-x3600):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rule Lab — Workbench 01</title>
<style>
:root {
color-scheme: light;
--ink: #17211d;
--muted: #64716a;
--paper: rgba(249, 246, 235, 0.93);
--paper-solid: #f8f3e4;
--line: rgba(23, 33, 29, 0.15);
--red: #d85249;
--blue: #3978c8;
--green: #25855d;
--gold: #d6a544;
--shadow: 0 14px 40px rgba(23, 33, 29, 0.17);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #c7d0c8;
}
button, select { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
button:focus-visible,
select:focus-visible {
outline: 3px solid rgba(57, 120, 200, 0.45);
outline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 42%, rgba(23, 33, 29, 0.09) 100%),
linear-gradient(to bottom, rgba(255,255,255,0.12), transparent 25%);
}
header {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
min-height: 70px;
padding: 14px 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid rgba(23, 33, 29, 0.2);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 7px 20px rgba(23,33,29,0.12);
font: 800 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: 0.02em;
}
.brand p {
margin: 4px 0 0;
color: #435149;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.objective {
margin-right: 5px;
padding: 9px 12px;
border: 1px solid rgba(23, 33, 29, 0.13);
border-radius: 999px;
background: rgba(249, 246, 235, 0.78);
color: #445148;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.button {
min-height: 40px;
padding: 0 14px;
border: 1px solid rgba(23, 33, 29, 0.16);
border-radius: 11px;
background: var(--paper);
box-shadow: 0 7px 20px rgba(23, 33, 29, 0.10);
font-weight: 750;
transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
background: #fffdf4;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary {
border-color: #1f6849;
background: var(--green);
color: white;
}
.button.primary:hover:not(:disabled) { background: #2c9569; }
.button:disabled,
select:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.panel {
position: fixed;
z-index: 8;
border: 1px solid rgba(23, 33, 29, 0.14);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
#hypothesisPanel {
top: 84px;
right: 20px;
width: 326px;
max-height: calc(100vh - 108px);
overflow: auto;
padding: 17px;
}
.eyebrow {
margin: 0 0 9px;
color: var(--muted);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.hypothesis-card {
padding: 14px;
border: 1px solid rgba(214, 165, 68, 0.43);
border-radius: 13px;
background:
linear-gradient(135deg, rgba(255,255,255,0.7), rgba(255,244,199,0.55));
box-shadow: inset 3px 0 0 var(--gold);
}
#hypothesisText {
margin: 0;
font: 800 17px/1.25 Georgia, "Times New Roman", serif;
}
#hypothesisNote {
margin: 9px 0 0;
color: #69756e;
font-size: 12px;
line-height: 1.45;
}
.progress-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin: 14px 0 8px;
color: #4e5c54;
font: 750 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.progress-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 33, 29, 0.10);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--green));
transition: width 220ms ease;
}
#journal {
list-style: none;
padding: 0;
margin: 12px 0 0;
display: grid;
gap: 6px;
}
#journal li {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 7px 9px;
border: 1px solid rgba(23, 33, 29, 0.09);
border-radius: 9px;
background: rgba(255,255,255,0.42);
font-size: 11px;
}
.journal-empty {
display: block !important;
justify-content: center !important;
color: #7a857e;
border-style: dashed !important;
}
.result-pill {
padding: 3px 6px;
border-radius: 999px;
color: white;
font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
}
.result-pill.open { background: var(--green); }
.result-pill.closed { background: var(--red); }
#claimArea {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
#claimArea label {
display: block;
margin-bottom: 7px;
font-weight: 800;
font-size: 12px;
}
#claimArea select {
width: 100%;
height: 40px;
padding: 0 10px;
border: 1px solid rgba(23, 33, 29, 0.18);
border-radius: 9px;
background: #fffdf5;
color: var(--ink);
font-size: 12px;
}
#claimArea .hint {
margin: 7px 0 10px;
color: #738078;
font-size: 10px;
line-height: 1.35;
}
#claimButton { width: 100%; }
#inventoryPanel {
left: 20px;
bottom: 20px;
width: 300px;
padding: 15px;
}
.inventory-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.inventory-heading strong {
font-size: 14px;
}
#sampleCount {
color: var(--muted);
font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#blockList {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.sample-button {
min-height: 52px;
padding: 8px;
display: grid;
grid-template-columns: 27px 1fr auto;
align-items: center;
gap: 7px;
border: 1px solid rgba(23, 33, 29, 0.13);
border-radius: 10px;
background: rgba(255,255,255,0.56);
text-align: left;
transition: transform 100ms ease, border-color 100ms ease, background 100ms ease;
}
.sample-button:hover { transform: translateY(-1px); background: #fffdf4; }
.sample-button.selected {
border-color: rgba(57,120,200,0.72);
box-shadow: 0 0 0 2px rgba(57,120,200,0.12);
background: rgba(226,239,255,0.8);
}
.sample-button.tested { opacity: 0.64; }
.sample-name {
font-size: 11px;
font-weight: 800;
line-height: 1.15;
}
.sample-status {
color: var(--green);
font: 900 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-transform: uppercase;
}
.shape-icon {
width: 24px;
height: 24px;
display: inline-block;
flex: 0 0 auto;
}
.shape-icon.square {
width: 22px;
height: 22px;
margin-left: 1px;
border-radius: 2px;
background: currentColor;
box-shadow: inset -4px -4px 0 rgba(0,0,0,0.13);
}
.shape-icon.circle {
width: 23px;
height: 23px;
border-radius: 50%;
background: currentColor;
box-shadow: inset -4px -4px 0 rgba(0,0,0,0.13);
}
.shape-icon.triangle {
width: 0;
height: 0;
margin-left: 4px;
border-left: 12px solid transparent;
border-right: 12px solid transparent;
border-bottom: 23px solid currentColor;
filter: drop-shadow(-3px 3px 0 rgba(0,0,0,0.12));
}
.red { color: var(--red); }
.blue { color: var(--blue); }
#actionPanel {
position: fixed;
z-index: 9;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
width: min(430px, calc(100vw - 680px));
min-width: 310px;
padding: 12px;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
border: 1px solid rgba(23, 33, 29, 0.15);
border-radius: 16px;
background: rgba(249, 246, 235, 0.94);
box-shadow: var(--shadow);
}
#selectedName {
display: block;
margin-bottom: 3px;
font-size: 13px;
font-weight: 850;
}
#selectedState {
color: #718078;
font-size: 10px;
}
#testButton {
min-width: 150px;
height: 44px;
}
#sceneHint {
position: fixed;
z-index: 4;
left: 50%;
top: 79px;
transform: translateX(-50%);
padding: 7px 10px;
border-radius: 999px;
background: rgba(249, 246, 235, 0.64);
color: #55645c;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 30;
top: 122px;
left: 50%;
max-width: min(500px, calc(100vw - 40px));
transform: translate(-50%, -10px);
padding: 11px 15px;
border-radius: 11px;
background: rgba(23, 33, 29, 0.91);
color: #fffdf2;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#successBanner {
position: fixed;
z-index: 20;
top: 145px;
left: 50%;
transform: translate(-50%, -12px) scale(0.97);
width: min(460px, calc(100vw - 40px));
padding: 18px 20px;
border: 1px solid rgba(37,133,93,0.35);
border-radius: 17px;
background: rgba(239, 251, 240, 0.96);
box-shadow: var(--shadow);
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 250ms ease, transform 250ms ease;
}
#successBanner.show {
opacity: 1;
transform: translate(-50%, 0) scale(1);
}
#successBanner strong {
display: block;
margin: 4px 0 7px;
color: #176843;
font: 900 20px/1.1 Georgia, "Times New Roman", serif;
}
#successBanner span {
color: #4d6859;
font-size: 12px;
line-height: 1.4;
}
@media (max-width: 1100px) {
.objective { display: none; }
#hypothesisPanel { width: 292px; right: 12px; }
#inventoryPanel { left: 12px; width: 260px; }
#actionPanel { width: 340px; min-width: 0; }
}
@media (max-width: 780px) {
header {
padding: 10px 12px;
min-height: 60px;
}
.brand p { display: none; }
.brand-mark { width: 36px; height: 36px; }
.brand h1 { font-size: 14px; }
.header-actions .button { min-height: 36px; padding: 0 9px; font-size: 11px; }
#sceneHint { display: none; }
#hypothesisPanel {
top: 66px;
right: 9px;
width: min(270px, calc(100vw - 18px));
max-height: 39vh;
padding: 12px;
}
.hypothesis-card { padding: 10px; }
#hypothesisText { font-size: 14px; }
#journal { max-height: 100px; overflow: auto; }
#inventoryPanel {
left: 9px;
right: 9px;
bottom: 9px;
width: auto;
padding: 10px;
}
#blockList {
grid-template-columns: repeat(3, 1fr);
}
.sample-button {
min-height: 44px;
grid-template-columns: 23px 1fr;
}
.sample-status { display: none; }
#actionPanel {
left: auto;
right: 9px;
bottom: 166px;
transform: none;
width: 230px;
min-width: 0;
padding: 9px;
}
#testButton { min-width: 100px; height: 40px; font-size: 11px; }
#selectedName { font-size: 11px; }
#selectedState { font-size: 9px; }
#toast { top: 110px; }
#successBanner { top: 112px; }
}
@media (max-height: 680px) and (min-width: 781px) {
#hypothesisPanel {
max-height: calc(100vh - 92px);
padding: 12px;
}
#journal { max-height: 105px; overflow: auto; }
#inventoryPanel { padding: 10px; }
.sample-button { min-height: 43px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly rule discovery workbench"></div>
<div class="vignette"></div>
<header>
<div class="brand">
<div class="brand-mark">RL</div>
<div>
<h1>Rule Lab</h1>
<p>Workbench 01 · Find what earns an OPEN</p>
</div>
</div>
<div class="header-actions">
<div class="objective">Test all 6 samples · certify the property</div>
<button class="button" id="resetButton" title="Clear observations while keeping the same block geometry">
Reset
</button>
<button class="button" id="revealButton" title="Reveal the actual rule">
Ask for actual rule
</button>
</div>
</header>
<div id="sceneHint">DRAG TO ORBIT · SCROLL TO ZOOM · CLICK A BLOCK</div>
<aside class="panel" id="hypothesisPanel">
<p class="eyebrow">Working hypothesis</p>
<div class="hypothesis-card">
<h2 id="hypothesisText">All red blocks open the gate.</h2>
<p id="hypothesisNote">
This is only a starting guess. Test individual blocks and keep each result beside the platform.
</p>
</div>
<div class="progress-row">
<span>Evidence pinned</span>
<span id="progressText">0 / 6</span>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
<ul id="journal" aria-live="polite">
<li class="journal-empty">No samples tested yet.</li>
</ul>
<div id="claimArea">
<label for="claimSelect">Your rule claim</label>
<select id="claimSelect" disabled>
<option value="">Choose a property…</option>
<option value="red">The color is red</option>
<option value="blue">The color is blue</option>
<option value="square">The footprint is square</option>
<option value="triangle">The footprint is triangular</option>
<option value="circular">The footprint is circular</option>
<option value="any">Every block opens the gate</option>
</select>
<p class="hint">
Test all six blocks to unlock certification. A rule must explain every pinned OPEN and CLOSED result.
</p>
<button class="button primary" id="claimButton" disabled>Certify rule</button>
</div>
</aside>
<aside class="panel" id="inventoryPanel">
<div class="inventory-heading">
<strong>Sample blocks</strong>
<span id="sampleCount">6 available</span>
</div>
<div id="blockList"></div>
</aside>
<section id="actionPanel" aria-label="Test controls">
<div>
<strong id="selectedName">Select a block</strong>
<span id="selectedState">Choose a sample or click one in the scene.</span>
</div>
<button class="button primary" id="testButton" disabled>Test selected block</button>
</section>
<div id="toast" role="status" aria-live="polite"></div>
<div id="successBanner" role="status">
<div class="eyebrow">Rule certified</div>
<strong>The gate opens for a circular footprint.</strong>
<span>
Your claim agrees with all six demonstrated outcomes, including both OPEN and CLOSED examples.
</span>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc7d0c8);
scene.fog = new THREE.Fog(0xc7d0c8, 15, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
target: new THREE.Vector3(0.05, 0.58, 0),
radius: 11.5,
azimuth: 0.12,
polar: 1.02
};
function updateCamera() {
const horizontal = Math.sin(cameraState.polar) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.azimuth) * horizontal,
cameraState.target.y + Math.cos(cameraState.polar) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.azimuth) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf7f3df, 0x66756b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.5);
sun.position.set(5.5, 10, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(1536, 1536);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xbcd8ff, 1.05);
coolFill.position.set(-6, 5, -4);
scene.add(coolFill);
const materials = {
wood: new THREE.MeshStandardMaterial({
color: 0xa97849, roughness: 0.83, metalness: 0.02, flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x62482f, roughness: 0.88, flatShading: true
}),
edge: new THREE.MeshStandardMaterial({
color: 0x7a5837, roughness: 0.9, flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x7e8c87, roughness: 0.52, metalness: 0.56, flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x33413c, roughness: 0.48, metalness: 0.62, flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xece3c9, roughness: 0.9, flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0xd85249, roughness: 0.73, flatShading: true
}),
blue: new THREE.MeshStandardMaterial({
color: 0x3978c8, roughness: 0.7, flatShading: true
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, segments, position, material) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Workbench and room
// ---------------------------------------------------------------------
const workbench = new THREE.Group();
scene.add(workbench);
addBox(workbench, [9, 0.30, 5.2], [0, 0, 0], materials.wood);
addBox(workbench, [8.75, 0.035, 4.95], [0, 0.17, 0], materials.edge, false);
for (let i = -2; i <= 2; i++) {
addBox(workbench, [8.7, 0.009, 0.018], [0, 0.193, i * 0.94], materials.darkWood, false);
}
const legPositions = [
[-3.85, -2.15], [3.85, -2.15],
[-3.85, 2.15], [3.85, 2.15]
];
for (const [x, z] of legPositions) {
addBox(workbench, [0.36, 2.15, 0.36], [x, -1.05, z], materials.darkWood);
}
addBox(workbench, [7.9, 0.18, 0.28], [0, -1.63, -2.15], materials.darkWood);
addBox(workbench, [7.9, 0.18, 0.28], [0, -1.63, 2.15], materials.darkWood);
addBox(workbench, [2.25, 0.68, 0.12], [1.55, -0.52, 2.63], materials.darkWood);
addBox(workbench, [0.75, 0.08, 0.12], [1.55, -0.52, 2.71], materials.metal);
for (const x of [-4.18, 4.18]) {
for (const z of [-2.36, 2.36]) {
const bolt = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.07, 0),
materials.darkMetal
);
bolt.position.set(x, 0.19, z);
bolt.castShadow = true;
workbench.add(bolt);
}
}
const ground = new THREE.Mesh(
new THREE.CircleGeometry(24, 48),
new THREE.MeshStandardMaterial({
color: 0xb3beb5,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.14;
ground.receiveShadow = true;
scene.add(ground);
// Sample tray.
addBox(workbench, [2.12, 0.09, 2.93], [-2.78, 0.22, 0.20], materials.darkWood);
addBox(workbench, [1.94, 0.025, 2.72], [-2.78, 0.28, 0.20], materials.cream, false);
// Results tray beside the platform.
addBox(workbench, [2.40, 0.07, 2.85], [1.88, 0.22, 0.70], materials.darkWood);
addBox(workbench, [2.24, 0.022, 2.68], [1.88, 0.27, 0.70], materials.cream, false);
// Test platform.
addCylinder(workbench, 0.78, 0.84, 0.17, 12, [0, 0.255, 0.02], materials.darkMetal);
addCylinder(workbench, 0.68, 0.68, 0.035, 12, [0, 0.355, 0.02], materials.cream);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.018, 8),
materials.metal
);
marker.position.set(
Math.cos(angle) * 0.69,
0.378,
0.02 + Math.sin(angle) * 0.69
);
workbench.add(marker);
}
// Gate frame.
const gate = new THREE.Group();
workbench.add(gate);
addBox(gate, [0.16, 2.50, 0.18], [-0.96, 1.22, -1.52], materials.darkMetal);
addBox(gate, [0.16, 2.50, 0.18], [0.96, 1.22, -1.52], materials.darkMetal);
addBox(gate, [2.08, 0.18, 0.20], [0, 2.43, -1.52], materials.darkMetal);
const gatePivot = new THREE.Group();
gatePivot.position.set(-0.84, 0, -1.52);
gate.add(gatePivot);
for (const x of [0.24, 0.84, 1.44]) {
addBox(gatePivot, [0.10, 1.92, 0.11], [x, 1.23, 0], materials.metal);
}
addBox(gatePivot, [1.42, 0.10, 0.11], [0.84, 0.48, 0], materials.metal);
addBox(gatePivot, [1.42, 0.10, 0.11], [0.84, 1.22, 0], materials.metal);
addBox(gatePivot, [1.42, 0.10, 0.11], [0.84, 1.97, 0], materials.metal);
const gateBulbMaterial = new THREE.MeshStandardMaterial({
color: 0xc64e45,
emissive: 0x5a110d,
emissiveIntensity: 0.7,
roughness: 0.38,
flatShading: true
});
const gateBulb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.115, 1),
gateBulbMaterial
);
gateBulb.position.set(1.18, 2.43, -1.39);
gate.add(gateBulb);
let gateTarget = 0;
// ---------------------------------------------------------------------
// Label textures
// ---------------------------------------------------------------------
function makeCanvasTexture(draw, width = 512, height = 256) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeTrayLabel(text, x, z, width = 1.8) {
const texture = makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = "#2e3a34";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#f5ecd2";
ctx.font = "800 54px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2);
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.22),
new THREE.MeshBasicMaterial({
map: texture,
transparent: false,
toneMapped: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.294, z);
workbench.add(mesh);
}
makeTrayLabel("SAMPLES", -2.78, -1.04, 1.7);
makeTrayLabel("PINNED RESULTS", 1.88, -0.49, 2.05);
// ---------------------------------------------------------------------
// Catalog. Geometry, not item names, determines the gate outcome.
// ---------------------------------------------------------------------
const catalog = [
{ id: "red-square", label: "Red square", color: "red", shape: "square", home: [-3.20, -0.62] },
{ id: "blue-round", label: "Blue round", color: "blue", shape: "circle", home: [-2.34, -0.62] },
{ id: "red-round", label: "Red round", color: "red", shape: "circle", home: [-3.20, 0.18] },
{ id: "blue-square", label: "Blue square", color: "blue", shape: "square", home: [-2.34, 0.18] },
{ id: "red-triangle",label: "Red triangle",color: "red", shape: "triangle",home: [-3.20, 0.98] },
{ id: "blue-triangle",label:"Blue triangle",color:"blue",shape: "triangle",home:[-2.34, 0.98] }
];
const itemById = new Map();
const pickableMeshes = [];
function createBlock(spec) {
const group = new THREE.Group();
group.position.set(spec.home[0], 0.30, spec.home[1]);
let geometry;
if (spec.shape === "square") {
geometry = new THREE.BoxGeometry(0.72, 0.68, 0.72);
} else if (spec.shape === "circle") {
geometry = new THREE.CylinderGeometry(0.43, 0.43, 0.68, 12);
} else {
geometry = new THREE.CylinderGeometry(0.52, 0.52, 0.68, 3);
}
const material = materials[spec.color].clone();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = 0.34;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.itemId = spec.id;
if (spec.shape === "triangle") {
mesh.rotation.y = Math.PI / 2;
} else {
mesh.rotation.y = spec.shape === "circle" ? 0.18 : 0.08;
}
group.add(mesh);
workbench.add(group);
pickableMeshes.push(mesh);
/*
* Derive the footprint from the actual mesh geometry:
* - BoxGeometry => square
* - CylinderGeometry with 3 sides => triangular
* - CylinderGeometry with many sides => circular footprint
*
* The success logic later reads this geometry-derived property,
* never an item's id or display name.
*/
let footprint;
if (geometry.type === "BoxGeometry") {
footprint = {
kind: "square",
radialSegments: 4,
continuousBoundary: false
};
} else {
const radialSegments = geometry.parameters.radialSegments;
footprint = {
kind: radialSegments >= 8 ? "circle" : "triangle",
radialSegments,
continuousBoundary: radialSegments >= 8
};
}
const item = {
...spec,
mesh: group,
shapeMesh: mesh,
footprint,
homePosition: group.position.clone(),
homeRotation: group.rotation.clone()
};
itemById.set(spec.id, item);
return item;
}
catalog.forEach(createBlock);
function hasCircularFootprint(item) {
return (
item.footprint.continuousBoundary === true &&
item.footprint.radialSegments >= 8
);
}
// Selection halo.
const selectionHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.035, 6, 28),
new THREE.MeshBasicMaterial({
color: 0x3978c8,
transparent: true,
opacity: 0.88,
toneMapped: false
})
);
selectionHalo.rotation.x = Math.PI / 2;
scene.add(selectionHalo);
// ---------------------------------------------------------------------
// UI state
// ---------------------------------------------------------------------
const blockList = document.getElementById("blockList");
const selectedName = document.getElementById("selectedName");
const selectedState = document.getElementById("selectedState");
const testButton = document.getElementById("testButton");
const resetButton = document.getElementById("resetButton");
const revealButton = document.getElementById("revealButton");
const claimSelect = document.getElementById("claimSelect");
const claimButton = document.getElementById("claimButton");
const journal = document.getElementById("journal");
const progressText = document.getElementById("progressText");
const progressFill = document.getElementById("progressFill");
const hypothesisText = document.getElementById("hypothesisText");
const hypothesisNote = document.getElementById("hypothesisNote");
const toast = document.getElementById("toast");
const successBanner = document.getElementById("successBanner");
const tested = new Map();
let selectedId = "red-square";
let busy = false;
let ruleRevealed = false;
let certified = false;
let runToken = 0;
let toastTimer = 0;
function shapeIcon(shape, color) {
return `<span class="shape-icon ${shape} ${color}" aria-hidden="true"></span>`;
}
function buildInventory() {
blockList.innerHTML = "";
for (const item of catalog) {
const button = document.createElement("button");
button.className = "sample-button";
button.dataset.id = item.id;
button.innerHTML = `
${shapeIcon(item.shape, item.color)}
<span class="sample-name">${item.label}</span>
<span class="sample-status"></span>
`;
button.addEventListener("click", () => selectItem(item.id));
blockList.appendChild(button);
}
}
function selectItem(id) {
if (!itemById.has(id)) return;
selectedId = id;
updateUI();
}
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("show");
toastTimer = window.setTimeout(() => toast.classList.remove("show"), 2600);
}
function updateUI() {
const item = itemById.get(selectedId);
selectedName.textContent = item ? item.label : "Select a block";
if (!item) {
selectedState.textContent = "Choose a sample or click one in the scene.";
} else if (tested.has(item.id)) {
const result = tested.get(item.id);
selectedState.textContent = result.opened
? "OPEN result is pinned beside the platform."
: "CLOSED result is pinned beside the platform.";
} else {
selectedState.textContent = "Place this sample on the test platform.";
}
testButton.disabled = busy || !item || tested.has(item.id);
testButton.textContent = busy
? "Testing…"
: (tested.has(item.id) ? "Result pinned" : "Test selected block");
progressText.textContent = `${tested.size} / ${catalog.length}`;
progressFill.style.width = `${(tested.size / catalog.length) * 100}%`;
for (const button of blockList.querySelectorAll(".sample-button")) {
const id = button.dataset.id;
button.classList.toggle("selected", id === selectedId);
button.classList.toggle("tested", tested.has(id));
button.querySelector(".sample-status").textContent = tested.has(id)
? "tested"
: "";
}
if (tested.size === 0) {
journal.innerHTML = '<li class="journal-empty">No samples tested yet.</li>';
} else {
journal.innerHTML = catalog
.filter(item => tested.has(item.id))
.map(item => {
const result = tested.get(item.id);
return `
<li>
<span>${item.label}</span>
<span class="result-pill ${result.opened ? "open" : "closed"}">
${result.opened ? "OPEN" : "CLOSED"}
</span>
</li>
`;
})
.join("");
}
const allTested = tested.size === catalog.length;
const claimsUnlocked = allTested || ruleRevealed;
claimSelect.disabled = !claimsUnlocked || certified;
claimButton.disabled = !allTested || busy || certified || !claimSelect.value;
if (!claimsUnlocked) claimSelect.value = "";
if (!ruleRevealed && !certified) {
if (tested.size === 0) {
hypothesisText.textContent = "All red blocks open the gate.";
hypothesisNote.textContent =
"This is only a starting guess. Test individual blocks and keep each result beside the platform.";
} else if (allTested) {
hypothesisText.textContent = "All red blocks open the gate.";
hypothesisNote.textContent =
"Six examples are pinned. The color-only hypothesis is under review; choose the property that explains every result.";
} else {
const redCounterexample = catalog.some(item =>
item.color === "red" &&
tested.has(item.id) &&
!tested.get(item.id).opened
);
hypothesisText.textContent = "All red blocks open the gate.";
hypothesisNote.textContent = redCounterexample
? "At least one pinned red example did not open the gate. The hypothesis is being challenged."
: "Your observations are accumulating. Compare the physical properties of the samples, not only their names.";
}
}
if (ruleRevealed && !certified) {
hypothesisText.textContent =
"The gate opens when a block has a circular footprint.";
hypothesisNote.textContent =
"Footprint means the outline that would touch the platform. Color and item labels are not the rule.";
}
if (certified) {
hypothesisText.textContent =
"Certified rule: a circular footprint opens the gate.";
hypothesisNote.textContent =
"Every demonstrated result agrees with the certified geometric property.";
}
revealButton.disabled = ruleRevealed;
revealButton.textContent = ruleRevealed ? "Rule revealed" : "Ask for actual rule";
successBanner.classList.toggle("show", certified);
}
buildInventory();
// ---------------------------------------------------------------------
// Physical result cards
// ---------------------------------------------------------------------
const resultGroup = new THREE.Group();
workbench.add(resultGroup);
const resultPositions = [
[1.35, 0.02], [2.40, 0.02],
[1.35, 0.78], [2.40, 0.78],
[1.35, 1.54], [2.40, 1.54]
];
function createResultCard(item, opened) {
const statusColor = opened ? "#25855d" : "#d85249";
const statusText = opened ? "OPEN" : "CLOSED";
const texture = makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = "#fbf5e6";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = statusColor;
ctx.fillRect(0, 0, w, 28);
ctx.fillRect(0, h - 18, w, 18);
ctx.fillStyle = "#233129";
ctx.font = "800 31px ui-sans-serif, system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(item.label.toUpperCase(), 24, 78);
ctx.fillStyle = statusColor;
ctx.font = "900 72px ui-monospace, monospace";
ctx.fillText(statusText, 22, 160);
ctx.fillStyle = "#65736a";
ctx.font = "700 19px ui-monospace, monospace";
ctx.fillText(opened ? "GATE RESPONSE" : "NO OPENING", 24, 222);
ctx.strokeStyle = "#24332b";
ctx.lineWidth = 9;
ctx.strokeRect(4, 4, w - 8, h - 8);
}, 512, 256);
const card = new THREE.Group();
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(1.00, 0.64),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false,
side: THREE.DoubleSide
})
);
plane.rotation.x = -Math.PI / 2;
plane.position.y = 0.306;
card.add(plane);
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.05, 10),
new THREE.MeshStandardMaterial({
color: statusColor,
roughness: 0.58,
flatShading: true
})
);
pin.position.set(-0.38, 0.335, -0.22);
pin.castShadow = true;
card.add(pin);
resultGroup.add(card);
}
// ---------------------------------------------------------------------
// Animation helpers
// ---------------------------------------------------------------------
const tweens = [];
function tween(duration, update) {
return new Promise(resolve => {
tweens.push({
start: performance.now(),
duration,
update,
resolve,
token: runToken
});
});
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function updateTweens(now) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tweenData = tweens[i];
if (tweenData.token !== runToken) {
tweens.splice(i, 1);
tweenData.resolve(false);
continue;
}
const raw = Math.min(1, (now - tweenData.start) / tweenData.duration);
tweenData.update(easeInOutCubic(raw));
if (raw >= 1) {
tweens.splice(i, 1);
tweenData.resolve(true);
}
}
}
async function testSelectedBlock() {
if (busy) return;
const item = itemById.get(selectedId);
if (!item || tested.has(item.id)) return;
const token = runToken;
busy = true;
updateUI();
const startPosition = item.mesh.position.clone();
const platformPosition = new THREE.Vector3(0, 0.39, 0.02);
const homePosition = item.homePosition.clone();
const moved = await tween(720, amount => {
item.mesh.position.lerpVectors(startPosition, platformPosition, amount);
});
if (!moved || token !== runToken) return;
// This is the actual gate rule, derived from the mesh footprint.
const opened = hasCircularFootprint(item);
gateTarget = opened ? -1.43 : 0;
const gateMoved = await tween(480, () => {});
if (!gateMoved || token !== runToken) return;
tested.set(item.id, { opened });
createResultCard(item, opened);
updateUI();
showToast(
opened
? `${item.label}: OPEN — result pinned beside the platform.`
: `${item.label}: CLOSED — result pinned beside the platform.`
);
const held = await tween(1150, () => {});
if (!held || token !== runToken) return;
gateTarget = 0;
const returned = await tween(650, amount => {
item.mesh.position.lerpVectors(platformPosition, homePosition, amount);
});
if (!returned || token !== runToken) return;
busy = false;
updateUI();
}
testButton.addEventListener("click", testSelectedBlock);
// ---------------------------------------------------------------------
// Rule certification
// ---------------------------------------------------------------------
/*
* These predicates describe properties of an item. The certification
* check compares them to every demonstrated outcome. No item name is
* used to decide success.
*/
const claims = {
red: item => item.color === "red",
blue: item => item.color === "blue",
square: item => item.footprint.kind === "square",
triangle: item => item.footprint.kind === "triangle",
circular: item => hasCircularFootprint(item),
any: () => true
};
function revealActualRule() {
ruleRevealed = true;
claimSelect.value = "circular";
hypothesisText.textContent =
"The gate opens when a block has a circular footprint.";
hypothesisNote.textContent =
"Footprint means the outline that would touch the platform. Color and item labels are not the rule.";
updateUI();
showToast("Actual rule revealed. Test the remaining samples to certify it.");
}
revealButton.addEventListener("click", revealActualRule);
claimSelect.addEventListener("change", updateUI);
claimButton.addEventListener("click", () => {
if (tested.size !== catalog.length) {
showToast("Test every sample before certifying a rule.");
return;
}
const predicate = claims[claimSelect.value];
if (!predicate) return;
const outcomesContainBoth = [...tested.values()].some(r => r.opened) &&
[...tested.values()].some(r => !r.opened);
const fitsEveryObservation = catalog.every(item => {
const observation = tested.get(item.id);
return observation.opened === Boolean(predicate(item));
});
if (!outcomesContainBoth || !fitsEveryObservation) {
showToast(
"That claim conflicts with a pinned result. Compare the OPEN and CLOSED cards."
);
return;
}
certified = true;
ruleRevealed = true;
updateUI();
showToast("Rule certified from all six demonstrated outcomes.");
burstConfetti();
});
// ---------------------------------------------------------------------
// Reset. Geometry remains identical and observations are deterministic.
// ---------------------------------------------------------------------
function clearResultCards() {
while (resultGroup.children.length) {
const child = resultGroup.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const objectMaterials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of objectMaterials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
}
}
function resetExperiment() {
runToken++;
busy = false;
tested.clear();
ruleRevealed = false;
certified = false;
selectedId = "red-square";
claimSelect.value = "";
gateTarget = 0;
for (const item of catalog) {
item.mesh.position.copy(item.homePosition);
item.mesh.rotation.copy(item.homeRotation);
}
clearResultCards();
successBanner.classList.remove("show");
updateUI();
showToast("Experiment reset. The block geometry is unchanged.");
}
resetButton.addEventListener("click", resetExperiment);
// ---------------------------------------------------------------------
// Success confetti
// ---------------------------------------------------------------------
const confetti = [];
const confettiGeometry = new THREE.TetrahedronGeometry(0.075, 0);
const confettiColors = [0xd85249, 0x3978c8, 0xd6a544, 0x25855d];
function burstConfetti() {
for (let i = 0; i < 38; i++) {
const material = new THREE.MeshStandardMaterial({
color: confettiColors[i % confettiColors.length],
roughness: 0.75,
flatShading: true
});
const piece = new THREE.Mesh(confettiGeometry, material);
const angle = (i / 38) * Math.PI * 2;
piece.position.set(
Math.cos(angle) * (0.25 + (i % 5) * 0.08),
1.6 + (i % 7) * 0.08,
Math.sin(angle) * (0.25 + (i % 4) * 0.08)
);
piece.castShadow = true;
scene.add(piece);
confetti.push({
mesh: piece,
velocity: new THREE.Vector3(
Math.cos(angle) * (0.7 + (i % 3) * 0.25),
1.3 + (i % 5) * 0.18,
Math.sin(angle) * (0.7 + (i % 4) * 0.2)
),
spin: new THREE.Vector3(0.05 + i * 0.002, 0.03 + i * 0.003, 0.04)
});
}
}
function updateConfetti(delta) {
for (let i = confetti.length - 1; i >= 0; i--) {
const piece = confetti[i];
piece.velocity.y -= 2.4 * delta;
piece.mesh.position.addScaledVector(piece.velocity, delta);
piece.mesh.rotation.x += piece.spin.x;
piece.mesh.rotation.y += piece.spin.y;
piece.mesh.rotation.z += piece.spin.z;
if (piece.mesh.position.y < -1.9) {
scene.remove(piece.mesh);
piece.mesh.material.dispose();
confetti.splice(i, 1);
}
}
}
// ---------------------------------------------------------------------
// Direct camera controls and block picking
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragMoved = 0;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
dragMoved = 0;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
dragMoved += Math.abs(deltaX) + Math.abs(deltaY);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - deltaY * 0.005,
0.60,
1.42
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragging) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragMoved > 7) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickableMeshes, false);
if (hits.length) {
const id = hits[0].object.userData.itemId;
selectItem(id);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
7.3,
16
);
updateCamera();
}, { passive: false });
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const greenColor = new THREE.Color(0x36c47a);
const redColor = new THREE.Color(0xd85249);
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
updateTweens(now);
updateConfetti(delta);
// Ease the physical gate toward its target angle.
gatePivot.rotation.y += (gateTarget - gatePivot.rotation.y) * Math.min(1, delta * 7.5);
const desiredBulbColor = gateTarget < -0.2 ? greenColor : redColor;
gateBulbMaterial.color.lerp(desiredBulbColor, Math.min(1, delta * 8));
gateBulbMaterial.emissive.lerp(desiredBulbColor, Math.min(1, delta * 8));
gateBulbMaterial.emissiveIntensity = gateTarget < -0.2 ? 1.25 : 0.42;
const selected = itemById.get(selectedId);
if (selected) {
selectionHalo.visible = !busy || selected.id === selectedId;
selectionHalo.position.set(
selected.mesh.position.x,
selected.mesh.position.y + 0.015,
selected.mesh.position.z
);
selectionHalo.rotation.z = now * 0.00035;
} else {
selectionHalo.visible = false;
}
renderer.render(scene, camera);
}
updateUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```