Prompt specification
Build or customize the Three.js 3D scene "Tactile Pattern Memory Puzzle" 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: Tactile Pattern Memory Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tactile-pattern-memory-puzzle-x3424
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Create an original pattern-matching game using six-dot arrays, clearly separated from real Braille literacy instruction. Require orientation-aware matching and label fictional patterns as game symbols.
Working Three.js Starter (tactile-pattern-memory-puzzle-x3424):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DOTLOOP — Fictional Symbol Match</title>
<style>
:root {
--bg: #070a16;
--panel: rgba(12, 18, 35, 0.82);
--line: rgba(155, 190, 255, 0.18);
--text: #eef5ff;
--muted: #93a5c7;
--cyan: #67f7df;
--pink: #ff6ba8;
--gold: #ffd166;
--red: #ff647c;
--green: #7cf7a8;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 7px);
grid-auto-rows: 7px;
gap: 4px;
padding: 9px;
border: 1px solid rgba(103, 247, 223, 0.4);
background: rgba(7, 12, 25, 0.72);
box-shadow: 0 0 28px rgba(103, 247, 223, 0.12);
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
background: var(--cyan);
box-shadow: 0 0 8px rgba(103, 247, 223, 0.65);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(3) {
opacity: 0.25;
}
.brand-copy strong {
display: block;
font-size: 19px;
line-height: 1;
letter-spacing: 0.22em;
}
.brand-copy small {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stats {
display: flex;
align-items: stretch;
gap: 8px;
pointer-events: none;
}
.stat {
min-width: 82px;
padding: 9px 12px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
}
.stat span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 3px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 17px;
letter-spacing: 0.06em;
}
.small-button {
border: 1px solid var(--line);
color: var(--text);
background: var(--panel);
padding: 0 15px;
cursor: pointer;
pointer-events: auto;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.small-button:hover {
border-color: rgba(103, 247, 223, 0.7);
background: rgba(22, 39, 61, 0.9);
}
.small-button:active {
transform: translateY(1px);
}
.disclaimer {
position: fixed;
z-index: 9;
top: 82px;
left: 50%;
width: min(720px, calc(100% - 40px));
transform: translateX(-50%);
padding: 10px 14px;
border: 1px solid rgba(255, 209, 102, 0.35);
background:
linear-gradient(
90deg,
rgba(255, 209, 102, 0.08),
rgba(12, 18, 35, 0.88),
rgba(255, 209, 102, 0.08)
);
color: #f7e5b4;
text-align: center;
font-size: 11px;
line-height: 1.5;
letter-spacing: 0.035em;
pointer-events: none;
}
.disclaimer b {
color: var(--gold);
letter-spacing: 0.1em;
}
.objective {
position: fixed;
z-index: 8;
top: 132px;
left: 50%;
width: min(650px, calc(100% - 40px));
transform: translateX(-50%);
text-align: center;
color: #c5d2e9;
font-size: 12px;
line-height: 1.55;
pointer-events: none;
text-shadow: 0 2px 12px #000;
}
.objective strong {
color: var(--cyan);
}
.controls {
position: fixed;
z-index: 12;
left: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 10px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
}
.rotate-button {
min-width: 108px;
padding: 11px 13px;
border: 1px solid rgba(103, 247, 223, 0.35);
color: var(--text);
background: rgba(103, 247, 223, 0.08);
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
.rotate-button:hover:not(:disabled) {
border-color: var(--cyan);
background: rgba(103, 247, 223, 0.18);
}
.rotate-button:active:not(:disabled) {
transform: translateY(1px);
}
.rotate-button:disabled {
opacity: 0.38;
cursor: default;
}
.orientation {
min-width: 105px;
padding: 0 8px;
}
.orientation span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.orientation strong {
display: block;
margin-top: 3px;
color: var(--gold);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
letter-spacing: 0.08em;
}
.progress {
position: fixed;
z-index: 10;
right: 20px;
bottom: 26px;
display: flex;
gap: 6px;
pointer-events: none;
}
.progress i {
width: 22px;
height: 5px;
background: rgba(147, 165, 199, 0.2);
border: 1px solid rgba(147, 165, 199, 0.18);
}
.progress i.done {
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 12px rgba(103, 247, 223, 0.45);
}
.feedback {
position: fixed;
z-index: 15;
left: 50%;
bottom: 102px;
width: min(560px, calc(100% - 40px));
transform: translate(-50%, 12px);
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 13px 14px 13px 17px;
border: 1px solid var(--line);
background: rgba(12, 18, 35, 0.94);
backdrop-filter: blur(15px);
opacity: 0;
visibility: hidden;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease,
visibility 180ms ease;
}
.feedback.show {
opacity: 1;
visibility: visible;
transform: translate(-50%, 0);
pointer-events: auto;
}
.feedback[data-kind="success"] {
border-color: rgba(124, 247, 168, 0.65);
box-shadow: 0 0 35px rgba(124, 247, 168, 0.1);
}
.feedback[data-kind="bad"] {
border-color: rgba(255, 100, 124, 0.65);
}
.feedback[data-kind="warn"] {
border-color: rgba(255, 209, 102, 0.65);
}
.feedback p {
margin: 0;
color: #dce7f8;
font-size: 12px;
line-height: 1.45;
}
.next-button {
flex: 0 0 auto;
padding: 10px 14px;
border: 1px solid var(--cyan);
color: #07111c;
background: var(--cyan);
font-weight: 800;
cursor: pointer;
}
.next-button[hidden] {
display: none;
}
.modal {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
padding: 24px;
background: rgba(3, 6, 15, 0.72);
backdrop-filter: blur(9px);
opacity: 1;
visibility: visible;
transition:
opacity 220ms ease,
visibility 220ms ease;
}
.modal.hidden {
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.modal-card {
width: min(570px, 100%);
padding: 30px;
border: 1px solid rgba(103, 247, 223, 0.32);
background:
linear-gradient(145deg, rgba(18, 28, 50, 0.98), rgba(8, 12, 26, 0.98));
box-shadow:
0 30px 100px rgba(0, 0, 0, 0.55),
0 0 60px rgba(103, 247, 223, 0.07);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.modal h1 {
margin: 10px 0 12px;
font-size: clamp(30px, 6vw, 52px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.modal h2 {
margin: 10px 0 12px;
font-size: 34px;
letter-spacing: -0.03em;
}
.modal p {
color: #b7c6df;
font-size: 14px;
line-height: 1.65;
}
.rules {
display: grid;
gap: 9px;
margin: 22px 0;
}
.rule {
display: grid;
grid-template-columns: 30px 1fr;
gap: 10px;
align-items: start;
color: #dce6f8;
font-size: 13px;
line-height: 1.45;
}
.rule b {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border: 1px solid rgba(103, 247, 223, 0.4);
color: var(--cyan);
background: rgba(103, 247, 223, 0.08);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.warning {
margin: 20px 0;
padding: 13px 14px;
border-left: 3px solid var(--gold);
background: rgba(255, 209, 102, 0.07);
color: #f1dfb0;
font-size: 12px;
line-height: 1.55;
}
.primary-button {
width: 100%;
padding: 14px 18px;
border: 0;
color: #06131c;
background: var(--cyan);
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition:
transform 150ms ease,
box-shadow 150ms ease;
}
.primary-button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(103, 247, 223, 0.22);
}
.fine-print {
margin: 12px 0 0;
color: #788aa9;
font-size: 10px;
line-height: 1.5;
text-align: center;
}
.result-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 22px 0;
}
.result-grid div {
padding: 14px 10px;
border: 1px solid var(--line);
text-align: center;
}
.result-grid span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.result-grid strong {
display: block;
margin-top: 6px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 23px;
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand-copy small,
.stat.score-stat {
display: none;
}
.brand-copy strong {
font-size: 14px;
}
.stat {
min-width: 62px;
padding: 7px 8px;
}
.stat strong {
font-size: 14px;
}
.small-button {
padding: 0 10px;
font-size: 11px;
}
.disclaimer {
top: 66px;
width: calc(100% - 20px);
font-size: 9px;
}
.objective {
top: 118px;
font-size: 10px;
}
.controls {
left: 10px;
bottom: 10px;
gap: 5px;
padding: 7px;
}
.rotate-button {
min-width: 82px;
padding: 10px 8px;
font-size: 11px;
}
.orientation {
min-width: 76px;
padding: 0 3px;
}
.progress {
right: 10px;
bottom: 20px;
gap: 3px;
}
.progress i {
width: 13px;
}
.feedback {
bottom: 82px;
}
.modal-card {
padding: 24px;
}
}
@media (max-height: 680px) {
.objective {
display: none;
}
.disclaimer {
top: 70px;
padding-block: 7px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional six-dot symbol matching game"></main>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<strong>DOTLOOP</strong>
<small>Fictional signal arcade</small>
</div>
</div>
<div class="stats">
<div class="stat score-stat">
<span>Score</span>
<strong id="scoreValue">0000</strong>
</div>
<div class="stat">
<span>Round</span>
<strong id="roundValue">1/8</strong>
</div>
<div class="stat">
<span>Time</span>
<strong id="timeValue">75</strong>
</div>
<button class="small-button" id="restartButton" type="button">Restart</button>
</div>
</header>
<div class="disclaimer">
<b>FICTIONAL GAME SYMBOLS — NOT BRAILLE.</b>
These invented six-position arrays are a visual arcade puzzle,
not Braille reading, writing, or literacy instruction.
</div>
<div class="objective">
Rotate the large signal until its <strong>gold tab points upward</strong>.
Then choose the option with the <strong>identical occupied positions</strong>.
Turned and mirrored decoys are included.
</div>
<div class="controls" aria-label="Target rotation controls">
<button class="rotate-button" id="rotateCCW" type="button" aria-label="Rotate target counterclockwise 90 degrees">
↶ 90°
</button>
<div class="orientation">
<span>Target turn</span>
<strong id="orientationValue">90° CW</strong>
</div>
<button class="rotate-button" id="rotateCW" type="button" aria-label="Rotate target clockwise 90 degrees">
↷ 90°
</button>
</div>
<div class="progress" id="progress" aria-label="Round progress"></div>
<div class="feedback" id="feedback" role="status" aria-live="polite">
<p id="feedbackText"></p>
<button class="next-button" id="nextButton" type="button" hidden>Next signal</button>
</div>
<section class="modal" id="introModal">
<div class="modal-card">
<div class="eyebrow">DOTLOOP / Arcade puzzle</div>
<h1>Match the turned signal.</h1>
<p>
Each invented game symbol occupies a six-position, 2 × 3 array.
Align the target, then identify the exact matching array among decoys.
</p>
<div class="rules">
<div class="rule">
<b>01</b>
<span>Rotate the target in quarter-turns until the gold tab is at the top.</span>
</div>
<div class="rule">
<b>02</b>
<span>Choose the option whose raised dots occupy exactly the same six positions.</span>
</div>
<div class="rule">
<b>03</b>
<span>Watch for turned, flipped, and mirrored patterns. Earn points before time expires.</span>
</div>
</div>
<div class="warning">
<strong>Separation from real-world notation:</strong>
DOTLOOP uses fictional, decorative game-symbol names only.
It does not teach or assess Braille, reading, writing, language, or literacy.
</div>
<button class="primary-button" id="startButton" type="button">Start 75-second run</button>
<p class="fine-print">
Drag the background to tilt the view. Use keys 1–4 to answer,
R to rotate clockwise, and Q to rotate counterclockwise.
</p>
</div>
</section>
<section class="modal hidden" id="endModal">
<div class="modal-card">
<div class="eyebrow">Run complete</div>
<h2 id="endTitle">Signals resolved.</h2>
<p id="endMessage"></p>
<div class="result-grid">
<div>
<span>Score</span>
<strong id="endScore">0</strong>
</div>
<div>
<span>Matched</span>
<strong id="endMatched">0/8</strong>
</div>
<div>
<span>Accuracy</span>
<strong id="endAccuracy">0%</strong>
</div>
</div>
<button class="primary-button" id="playAgainButton" type="button">Play again</button>
<p class="fine-print">Fictional game symbols only. No literacy instruction.</p>
</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and game state
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const sceneContainer = $("#scene");
const scoreValue = $("#scoreValue");
const roundValue = $("#roundValue");
const timeValue = $("#timeValue");
const progress = $("#progress");
const orientationValue = $("#orientationValue");
const rotateCW = $("#rotateCW");
const rotateCCW = $("#rotateCCW");
const feedback = $("#feedback");
const feedbackText = $("#feedbackText");
const nextButton = $("#nextButton");
const introModal = $("#introModal");
const endModal = $("#endModal");
const endTitle = $("#endTitle");
const endMessage = $("#endMessage");
const endScore = $("#endScore");
const endMatched = $("#endMatched");
const endAccuracy = $("#endAccuracy");
const TOTAL_ROUNDS = 8;
const START_TIME = 75;
const QUARTER_TURN = Math.PI / 2;
let score = 0;
let roundIndex = 0;
let timeLeft = START_TIME;
let attempts = 0;
let correctRounds = 0;
let gameStarted = false;
let gameOver = false;
let roundLocked = false;
let currentSteps = 1;
let targetMask = 43;
let choiceMasks = [43, 23, 53, 27];
let selectedGood = -1;
let previousFamily = -1;
// Every mask represents occupancy in a 2 × 3 array.
// Bit order: top-left, top-right, middle-left, middle-right,
// bottom-left, bottom-right.
const families = [
[43, 23, 53, 27],
[37, 29, 21, 39],
[46, 29, 15, 27],
[58, 53, 11, 22],
[30, 45, 15, 23]
];
const symbolNames = {
43: "MOSSWICK",
37: "CINDERLOOM",
46: "GLIMMER",
58: "VELUM",
30: "TANGLE",
23: "FERNSPOOL",
27: "LATCH",
53: "ORBWEAVE",
29: "PIXEL",
21: "HALO",
39: "NOOK",
15: "SPARK",
11: "DUNE",
22: "RIBBON",
45: "GLOVE"
};
const optionColors = [0x67f7df, 0xff6ba8, 0xffd166, 0x8e9cff];
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
document.body.innerHTML = `
<main style="padding:40px;font-family:system-ui;color:white">
<h1>WebGL is unavailable</h1>
<p>This game requires a browser with WebGL enabled.</p>
</main>
`;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional fictional six-dot game symbol scene"
);
renderer.domElement.tabIndex = 0;
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x070a16);
scene.fog = new THREE.Fog(0x070a16, 18, 34);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraLookAt = new THREE.Vector3(0, 2.25, 0);
let cameraYaw = 0;
let cameraPitch = 0.42;
let cameraZoom = 1;
function updateCamera() {
const distance = 18;
camera.position.set(
Math.sin(cameraYaw) * distance * Math.cos(cameraPitch),
cameraLookAt.y + Math.sin(cameraPitch) * distance,
Math.cos(cameraYaw) * distance * Math.cos(cameraPitch)
);
camera.lookAt(cameraLookAt);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(9.2, 13.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
updateCamera();
resize();
const hemiLight = new THREE.HemisphereLight(0x9fb8ff, 0x101426, 1.8);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x49f6df, 18, 16, 2);
cyanLight.position.set(-5, 4, -2);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4f9a, 15, 15, 2);
pinkLight.position.set(5, 3, 2);
scene.add(pinkLight);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
const materials = {
stage: new THREE.MeshStandardMaterial({
color: 0x11182a,
roughness: 0.86,
metalness: 0.12
}),
stageEdge: new THREE.MeshStandardMaterial({
color: 0x243252,
roughness: 0.62,
metalness: 0.4
}),
darkBoard: new THREE.MeshStandardMaterial({
color: 0x0b1121,
roughness: 0.66,
metalness: 0.25
}),
emptySlot: new THREE.MeshStandardMaterial({
color: 0x24304a,
roughness: 0.8,
metalness: 0.16
}),
gold: new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6b3d00,
emissiveIntensity: 0.7,
roughness: 0.35,
metalness: 0.45
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededNoise(seed) {
const value = Math.sin(seed * 12.9898) * 43758.5453;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Stage and decorative voxel environment
// -------------------------------------------------------------------------
addBox(13.8, 0.42, 10.2, materials.stage, 0, -0.26, 0);
addBox(14.2, 0.16, 10.6, materials.stageEdge, 0, -0.53, 0);
const tileGeometry = new THREE.BoxGeometry(0.93, 0.075, 0.93);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0.08
});
const tileColumns = 13;
const tileRows = 9;
const tileMesh = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileColumns * tileRows
);
tileMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < tileRows; row++) {
for (let column = 0; column < tileColumns; column++) {
const x = (column - (tileColumns - 1) / 2) * 1.0;
const z = (row - (tileRows - 1) / 2) * 1.0;
dummy.position.set(x, -0.01, z);
dummy.rotation.y = 0;
dummy.updateMatrix();
tileMesh.setMatrixAt(tileIndex, dummy.matrix);
const variation = seededNoise(tileIndex + 3);
tileColor.setHSL(
0.63,
0.25 + variation * 0.12,
0.09 + variation * 0.035
);
tileMesh.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tileMesh.instanceMatrix.needsUpdate = true;
if (tileMesh.instanceColor) {
tileMesh.instanceColor.needsUpdate = true;
}
scene.add(tileMesh);
// Target pedestal.
addBox(2.7, 0.34, 1.9, materials.stageEdge, 0, 0.18, -2.55);
addBox(1.8, 0.13, 1.15, materials.stage, 0, 0.41, -2.55);
addBox(0.48, 1.15, 0.48, materials.stageEdge, 0, 0.95, -2.55);
addBox(1.5, 0.12, 0.9, materials.stageEdge, 0, 1.56, -2.55);
const floatingBlocks = [];
function addFloatingBlock(x, y, z, scale, color, phase) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.userData.baseY = y;
group.userData.phase = phase;
const mainMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.13,
roughness: 0.45,
metalness: 0.35
});
const core = addBox(
scale,
scale,
scale,
mainMaterial,
0,
0,
0,
group
);
core.rotation.y = phase;
const satellite = addBox(
scale * 0.42,
scale * 0.42,
scale * 0.42,
materials.stageEdge,
scale * 0.65,
scale * 0.55,
0,
group
);
satellite.rotation.z = Math.PI / 4;
scene.add(group);
floatingBlocks.push(group);
}
addFloatingBlock(-6.2, 3.3, -3.5, 0.62, 0x284f7a, 0.4);
addFloatingBlock(6.1, 4.2, -3.9, 0.78, 0x63305f, 1.1);
addFloatingBlock(-6.5, 1.7, 2.8, 0.44, 0x285e62, 2.3);
addFloatingBlock(6.4, 2.1, 3.6, 0.5, 0x63305f, 3.1);
addFloatingBlock(-4.9, 5.2, -1.8, 0.34, 0x345d8c, 0.7);
addFloatingBlock(4.8, 5.7, -0.9, 0.31, 0x7b3f59, 2.8);
// Voxel pylons around the stage.
const pylonColors = [0x1a2741, 0x22314d, 0x17243b];
for (let side = 0; side < 2; side++) {
for (let index = 0; index < 5; index++) {
const x = side === 0 ? -7.1 : 7.1;
const z = -4.1 + index * 1.95;
const height = 1.2 + seededNoise(index + side * 9) * 2.8;
for (let level = 0; level < Math.floor(height / 0.45); level++) {
const material = new THREE.MeshStandardMaterial({
color: pylonColors[(index + level) % pylonColors.length],
roughness: 0.8,
metalness: 0.12
});
addBox(
0.48,
0.42,
0.48,
material,
x + (level % 2) * 0.07,
0.18 + level * 0.43,
z,
scene,
false
);
}
}
}
// -------------------------------------------------------------------------
// Text sprites
// -------------------------------------------------------------------------
function createTextSprite(title, subtitle, accent = "#67f7df") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.65, 0.62, 1);
sprite.renderOrder = 20;
sprite.userData.canvas = canvas;
sprite.userData.texture = texture;
paintTextSprite(sprite, title, subtitle, accent);
return sprite;
}
function paintTextSprite(sprite, title, subtitle, accent) {
const canvas = sprite.userData.canvas;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(8, 13, 27, 0.88)";
context.strokeStyle = "rgba(137, 169, 221, 0.34)";
context.lineWidth = 3;
context.beginPath();
context.rect(8, 10, canvas.width - 16, canvas.height - 20);
context.fill();
context.stroke();
context.fillStyle = accent;
context.fillRect(8, 10, 7, canvas.height - 20);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#f4f8ff";
context.font = "800 42px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillText(title, canvas.width / 2, 64);
context.fillStyle = accent;
context.font = "700 22px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillText(subtitle, canvas.width / 2, 108);
sprite.userData.texture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Six-position signal construction
// -------------------------------------------------------------------------
function buildSignal(parent, scale, accent, showBorder = true) {
const group = new THREE.Group();
parent.add(group);
const boardMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1121,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.63,
metalness: 0.25
});
const board = addBox(
1.55 * scale,
2.15 * scale,
0.22 * scale,
boardMaterial,
0,
0,
0,
group
);
const borderMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.25,
roughness: 0.35,
metalness: 0.45
});
if (showBorder) {
addBox(
0.08 * scale,
2.28 * scale,
0.25 * scale,
borderMaterial,
-0.81 * scale,
0,
0,
group
);
addBox(
0.08 * scale,
2.28 * scale,
0.25 * scale,
borderMaterial,
0.81 * scale,
0,
0,
group
);
addBox(
1.7 * scale,
0.08 * scale,
0.25 * scale,
borderMaterial,
0,
-1.12 * scale,
0,
group
);
addBox(
1.7 * scale,
0.08 * scale,
0.25 * scale,
borderMaterial,
0,
1.12 * scale,
0,
group
);
}
const activeMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.34,
roughness: 0.28,
metalness: 0.35
});
const dots = [];
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 2; column++) {
const x = (column - 0.5) * 0.62 * scale;
const y = (1 - row) * 0.62 * scale;
const active = addBox(
0.36 * scale,
0.36 * scale,
0.34 * scale,
activeMaterial,
x,
y,
0.25 * scale,
group
);
const inactive = addBox(
0.18 * scale,
0.18 * scale,
0.11 * scale,
materials.emptySlot,
x,
y,
0.16 * scale,
group
);
dots.push({ active, inactive });
}
}
return {
group,
board,
boardMaterial,
dots
};
}
function setSignalMask(signal, mask) {
signal.dots.forEach((dot, index) => {
const occupied = Boolean(mask & (1 << index));
dot.active.visible = occupied;
dot.inactive.visible = !occupied;
});
}
// Large rotating target.
const targetRoot = new THREE.Group();
targetRoot.position.set(0, 3.3, -2.55);
scene.add(targetRoot);
const targetSignal = buildSignal(targetRoot, 1.15, 0x67f7df, true);
const targetMarker = new THREE.Group();
targetRoot.add(targetMarker);
addBox(
0.22,
0.34,
0.24,
materials.gold,
0,
1.43,
0.04,
targetMarker
);
addBox(
0.42,
0.12,
0.24,
materials.gold,
0,
1.27,
0.04,
targetMarker
);
const targetLabel = createTextSprite(
"UNKNOWN SIGNAL",
"ALIGN THEN MATCH",
"#ffd166"
);
targetLabel.position.set(0, 5.25, -2.35);
targetLabel.scale.set(2.9, 0.68, 1);
scene.add(targetLabel);
// Four selectable signal tiles.
const optionRoots = [];
const optionPickMeshes = [];
const optionX = [-4.65, -1.55, 1.55, 4.65];
for (let index = 0; index < 4; index++) {
const root = new THREE.Group();
root.position.set(optionX[index], 1.45, 1.55);
root.userData.baseY = 1.45;
root.userData.hovered = false;
root.userData.flashUntil = 0;
root.userData.flashColor = 0xffffff;
const signal = buildSignal(root, 0.78, optionColors[index], true);
const label = createTextSprite(
"SYMBOL",
"GAME SYMBOL",
`#${optionColors[index].toString(16).padStart(6, "0")}`
);
label.position.set(0, -1.1, 0.15);
label.scale.set(2.12, 0.5, 1);
root.add(label);
root.traverse((object) => {
if (object.isMesh) {
object.userData.choiceIndex = index;
optionPickMeshes.push(object);
}
});
scene.add(root);
optionRoots.push({ root, signal, label });
}
// -------------------------------------------------------------------------
// Direct camera controls and picking — no imported controls/addons
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let hoveredIndex = -1;
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
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 pickOption(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(optionPickMeshes, false);
if (!intersections.length) {
return -1;
}
return intersections[0].object.userData.choiceIndex;
}
function updateHover(event) {
const nextHovered = gameStarted && !gameOver ? pickOption(event) : -1;
if (nextHovered !== hoveredIndex) {
hoveredIndex = nextHovered;
}
renderer.domElement.style.cursor = pointerDown
? "grabbing"
: hoveredIndex >= 0
? "pointer"
: "grab";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const totalDistance = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (totalDistance > 5) {
pointerMoved = true;
}
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
cameraYaw = THREE.MathUtils.clamp(
cameraYaw - deltaX * 0.003,
-0.38,
0.38
);
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.0023,
0.2,
0.76
);
updateCamera();
} else {
updateHover(event);
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
renderer.domElement.releasePointerCapture(event.pointerId);
if (!pointerMoved && gameStarted && !gameOver) {
const index = pickOption(event);
if (index >= 0) {
selectChoice(index);
}
}
pointerDown = false;
updateHover(event);
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom - event.deltaY * 0.001,
0.8,
1.28
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Game logic
// -------------------------------------------------------------------------
function shuffled(array) {
const result = [...array];
for (let index = result.length - 1; index > 0; index--) {
const randomIndex = Math.floor(Math.random() * (index + 1));
[result[index], result[randomIndex]] = [
result[randomIndex],
result[index]
];
}
return result;
}
function symbolName(mask) {
return symbolNames[mask] || `SIGNAL-${mask}`;
}
function updateHud() {
scoreValue.textContent = String(score).padStart(4, "0");
roundValue.textContent = `${Math.min(roundIndex + 1, TOTAL_ROUNDS)}/${TOTAL_ROUNDS}`;
timeValue.textContent = String(Math.max(0, Math.ceil(timeLeft))).padStart(2, "0");
progress.replaceChildren();
for (let index = 0; index < TOTAL_ROUNDS; index++) {
const segment = document.createElement("i");
const completed = index < roundIndex || (index === roundIndex && selectedGood >= 0);
if (completed) {
segment.classList.add("done");
}
progress.appendChild(segment);
}
}
function updateOrientationUI() {
const degrees = currentSteps * 90;
orientationValue.textContent =
currentSteps === 0 ? "UPRIGHT" : `${degrees}° CW`;
rotateCW.disabled = roundLocked || !gameStarted || gameOver;
rotateCCW.disabled = roundLocked || !gameStarted || gameOver;
}
function rotateTarget(direction) {
if (!gameStarted || roundLocked || gameOver) return;
currentSteps = (currentSteps + direction + 4) % 4;
targetRoot.rotation.z = -currentSteps * QUARTER_TURN;
updateOrientationUI();
}
function showFeedback(kind, message, showNext = false) {
feedback.dataset.kind = kind;
feedbackText.textContent = message;
feedback.classList.add("show");
nextButton.hidden = !showNext;
}
function hideFeedback() {
feedback.classList.remove("show");
nextButton.hidden = true;
}
function flashOption(index, color) {
optionRoots[index].root.userData.flashUntil = performance.now() + 650;
optionRoots[index].root.userData.flashColor = color;
}
function updateChoiceLabels() {
optionRoots.forEach((option, index) => {
const mask = choiceMasks[index];
const accent = `#${optionColors[index].toString(16).padStart(6, "0")}`;
paintTextSprite(
option.label,
symbolName(mask),
`GAME SYMBOL · GS-${mask}`,
accent
);
});
}
function startRound() {
if (roundIndex >= TOTAL_ROUNDS) {
endGame();
return;
}
let familyIndex;
do {
familyIndex = Math.floor(Math.random() * families.length);
} while (
families.length > 1 &&
familyIndex === previousFamily
);
previousFamily = familyIndex;
const family = families[familyIndex];
targetMask = family[0];
choiceMasks = shuffled(family);
currentSteps = 1 + Math.floor(Math.random() * 3);
targetRoot.rotation.z = -currentSteps * QUARTER_TURN;
selectedGood = -1;
roundLocked = false;
setSignalMask(targetSignal, targetMask);
optionRoots.forEach((option, index) => {
setSignalMask(option.signal, choiceMasks[index]);
option.root.userData.flashUntil = 0;
option.root.scale.set(1, 1, 1);
});
updateChoiceLabels();
paintTextSprite(
targetLabel,
"UNKNOWN SIGNAL",
"ALIGN THEN MATCH",
"#ffd166"
);
hideFeedback();
updateOrientationUI();
updateHud();
}
function selectChoice(index) {
if (!gameStarted || gameOver || roundLocked) return;
attempts++;
if (currentSteps !== 0) {
flashOption(index, 0xffd166);
showFeedback(
"warn",
"Not yet. The gold tab must point upward. Turn the target until the readout says UPRIGHT.",
false
);
return;
}
if (choiceMasks[index] === targetMask) {
roundLocked = true;
selectedGood = index;
correctRounds++;
const earned = 100 + Math.ceil(timeLeft * 1.5);
score += earned;
paintTextSprite(
targetLabel,
`${symbolName(targetMask)} FOUND`,
`SIGNAL · GS-${targetMask}`,
"#7cf7a8"
);
showFeedback(
"success",
`Exact match: ${symbolName(targetMask)}. +${earned} signal points.`,
true
);
updateOrientationUI();
} else {
score = Math.max(0, score - 20);
flashOption(index, 0xff647c);
showFeedback(
"bad",
"Not an exact array. Check every row and column—turned and mirrored decoys are present.",
false
);
}
updateHud();
}
function resetGame() {
score = 0;
roundIndex = 0;
timeLeft = START_TIME;
attempts = 0;
correctRounds = 0;
gameStarted = true;
gameOver = false;
previousFamily = -1;
hoveredIndex = -1;
introModal.classList.add("hidden");
endModal.classList.add("hidden");
startRound();
}
function endGame() {
gameOver = true;
roundLocked = true;
hideFeedback();
updateOrientationUI();
const accuracy = attempts > 0 ? Math.round((correctRounds / attempts) * 100) : 0;
endTitle.textContent =
score >= 1000 ? "Signal master." : "Signals resolved.";
endMessage.textContent =
score >= 1000
? "You tracked every turned array cleanly. The arcade awards you an extra flourish."
: "The signal grid is quiet again. Try another run and watch the orientation marker more closely.";
endScore.textContent = String(score);
endMatched.textContent = `${correctRounds}/${TOTAL_ROUNDS}`;
endAccuracy.textContent = `${accuracy}%`;
endModal.classList.remove("hidden");
updateHud();
}
rotateCW.addEventListener("click", () => rotateTarget(1));
rotateCCW.addEventListener("click", () => rotateTarget(-1));
nextButton.addEventListener("click", () => {
if (!roundLocked) return;
roundIndex++;
if (roundIndex >= TOTAL_ROUNDS) {
endGame();
} else {
startRound();
}
});
$("#startButton").addEventListener("click", resetGame);
$("#restartButton").addEventListener("click", resetGame);
$("#playAgainButton").addEventListener("click", resetGame);
window.addEventListener("keydown", (event) => {
if (!gameStarted || gameOver) return;
if (["1", "2", "3", "4"].includes(event.key)) {
selectChoice(Number(event.key) - 1);
} else if (event.key.toLowerCase() === "r") {
rotateTarget(1);
} else if (event.key.toLowerCase() === "q") {
rotateTarget(-1);
} else if (event.key === "Enter" && !nextButton.hidden) {
nextButton.click();
}
});
setInterval(() => {
if (!gameStarted || gameOver) return;
timeLeft -= 1;
if (timeLeft <= 0) {
timeLeft = 0;
endGame();
}
updateHud();
}, 1000);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const now = performance.now();
floatingBlocks.forEach((block, index) => {
block.rotation.y += 0.003 + index * 0.0004;
block.rotation.x = Math.sin(elapsed * 0.35 + block.userData.phase) * 0.08;
block.position.y =
block.userData.baseY +
Math.sin(elapsed * 0.75 + block.userData.phase) * 0.13;
});
targetMarker.rotation.z = Math.sin(elapsed * 2.2) * 0.018;
optionRoots.forEach((option, index) => {
const isHovered = hoveredIndex === index;
const isCorrect = selectedGood === index;
const flashing = now < option.root.userData.flashUntil;
const targetY = option.root.userData.baseY + (isHovered ? 0.09 : 0);
option.root.position.y = THREE.MathUtils.lerp(
option.root.position.y,
targetY,
0.12
);
const targetScale = isHovered ? 1.035 : 1;
const nextScale = THREE.MathUtils.lerp(
option.root.scale.x,
targetScale,
0.13
);
option.root.scale.setScalar(nextScale);
let emissive = 0x000000;
let intensity = 0;
if (isCorrect) {
emissive = 0x41e989;
intensity = 0.5;
} else if (flashing) {
emissive = option.root.userData.flashColor;
intensity = 0.62;
} else if (isHovered) {
emissive = optionColors[index];
intensity = 0.27;
}
option.signal.boardMaterial.emissive.setHex(emissive);
option.signal.boardMaterial.emissiveIntensity = intensity;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// Initialize an attractive demo state behind the introductory panel.
setSignalMask(targetSignal, targetMask);
optionRoots.forEach((option, index) => {
setSignalMask(option.signal, choiceMasks[index]);
});
updateChoiceLabels();
updateOrientationUI();
updateHud();
</script>
</body>
</html>
```