Prompt specification
Build or customize the Three.js 3D scene "Ordered Tiles With a Reading Arrow" 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: Ordered Tiles With a Reading Arrow
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ordered-tiles-with-a-reading-arrow-x3437
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows written symbol order and reading direction. Arrange original symbol tiles on a track with a marked start and direction. Show that reversing the order changes the encoded sequence while preserving individual symbols. Low-poly.
Working Three.js Starter (ordered-tiles-with-a-reading-arrow-x3437):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reading Order Lab — Three.js</title>
<style>
:root {
--bg: #08111f;
--panel: rgba(12, 23, 40, 0.88);
--panel-border: rgba(164, 211, 255, 0.16);
--text: #f5f7fb;
--muted: #93a4bd;
--accent: #65f0c2;
--accent-2: #ffce69;
}
* {
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;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.intro {
position: absolute;
top: 30px;
left: 34px;
width: min(460px, calc(100vw - 190px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
content: "";
background: var(--accent);
box-shadow: 0 0 14px rgba(101, 240, 194, 0.7);
}
h1 {
margin: 0;
max-width: 450px;
font-size: clamp(32px, 4vw, 58px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.intro p {
max-width: 420px;
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.direction-card {
position: absolute;
top: 30px;
right: 32px;
min-width: 190px;
padding: 15px 17px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: rgba(10, 20, 36, 0.76);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
}
.direction-card > span {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
.direction-value {
display: flex;
align-items: center;
gap: 11px;
}
#directionArrow {
display: inline-block;
color: var(--accent);
font-size: 31px;
line-height: 1;
transition: transform 450ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#directionArrow.reversed {
transform: rotate(180deg);
}
#directionText {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
}
.sequence-panel {
position: absolute;
right: 22px;
bottom: 22px;
left: 22px;
z-index: 3;
max-width: 920px;
margin: 0 auto;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 14px 18px;
border-bottom: 1px solid rgba(164, 211, 255, 0.1);
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.identity {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
}
.identity-check {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(101, 240, 194, 0.35);
border-radius: 50%;
color: var(--accent);
background: rgba(101, 240, 194, 0.08);
font-weight: 900;
}
.identity strong {
color: var(--accent);
font-size: 11px;
letter-spacing: 0;
text-transform: none;
}
.identity small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.comparison {
display: grid;
grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr);
align-items: center;
gap: 12px;
padding: 16px 18px 15px;
}
.sequence {
min-width: 0;
}
.sequence.current {
padding: 12px;
border: 1px solid rgba(101, 240, 194, 0.19);
border-radius: 14px;
background: rgba(101, 240, 194, 0.035);
}
.sequence-label {
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.sequence.current .sequence-label {
color: var(--accent);
}
.code-line {
min-height: 34px;
color: #dfe8f6;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: clamp(15px, 2vw, 23px);
font-weight: 700;
letter-spacing: 0.08em;
white-space: nowrap;
}
.sequence.current .code-line {
color: var(--accent-2);
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 10px;
}
.chip {
display: flex;
width: 48px;
height: 51px;
flex-direction: column;
align-items: center;
justify-content: center;
border: 1px solid color-mix(in srgb, var(--c) 46%, transparent);
border-radius: 10px;
background: color-mix(in srgb, var(--c) 13%, #111d30);
box-shadow: inset 0 1px rgba(255, 255, 255, 0.07);
animation: chip-in 360ms both;
animation-delay: var(--delay, 0ms);
}
.chip-glyph {
color: var(--c);
font-size: 23px;
font-weight: 800;
line-height: 1;
}
.chip-code {
margin-top: 5px;
color: #dce7f6;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
@keyframes chip-in {
from {
opacity: 0;
transform: translateY(8px) scale(0.92);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.swap {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border: 1px solid rgba(164, 211, 255, 0.16);
border-radius: 50%;
color: var(--muted);
background: rgba(255, 255, 255, 0.025);
font-size: 20px;
}
.panel-footer {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 18px;
border-top: 1px solid rgba(164, 211, 255, 0.1);
background: rgba(0, 0, 0, 0.12);
}
.button {
display: inline-flex;
min-height: 38px;
align-items: center;
justify-content: center;
gap: 9px;
padding: 0 14px;
border: 1px solid rgba(164, 211, 255, 0.16);
border-radius: 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.button:hover {
border-color: rgba(101, 240, 194, 0.5);
background: rgba(101, 240, 194, 0.08);
transform: translateY(-1px);
}
.button:active {
transform: translateY(0);
}
.button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.button.primary {
border-color: rgba(101, 240, 194, 0.42);
color: #06231c;
background: var(--accent);
font-size: 12px;
font-weight: 850;
}
.button.primary:hover {
background: #8af7d4;
}
.button-icon {
font-size: 18px;
line-height: 1;
}
.camera-hint {
margin-left: auto;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.025em;
}
.toast {
position: fixed;
top: 26px;
left: 50%;
z-index: 5;
max-width: calc(100vw - 32px);
padding: 10px 15px;
border: 1px solid rgba(101, 240, 194, 0.24);
border-radius: 999px;
color: #dffff5;
background: rgba(8, 27, 31, 0.9);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition:
opacity 220ms ease,
transform 220ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.tile-tooltip {
position: fixed;
z-index: 8;
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border: 1px solid rgba(164, 211, 255, 0.2);
border-radius: 10px;
color: var(--text);
background: rgba(8, 17, 31, 0.94);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
opacity: 0;
pointer-events: none;
transform: translateY(5px);
transition:
opacity 120ms ease,
transform 120ms ease;
}
.tile-tooltip.visible {
opacity: 1;
transform: translateY(0);
}
.tooltip-glyph {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border-radius: 7px;
color: #07111e;
background: var(--tip-color, #65f0c2);
font-size: 19px;
font-weight: 900;
}
.tooltip-copy strong,
.tooltip-copy small {
display: block;
}
.tooltip-copy strong {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 11px;
}
.tooltip-copy small {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
width: calc(100vw - 112px);
}
.intro h1 {
font-size: clamp(27px, 8vw, 42px);
}
.intro p {
display: none;
}
.direction-card {
top: 16px;
right: 15px;
min-width: 76px;
padding: 10px;
}
.direction-card > span {
display: none;
}
#directionText {
display: none;
}
.sequence-panel {
right: 10px;
bottom: 10px;
left: 10px;
border-radius: 16px;
}
.panel-heading {
padding: 11px 12px;
}
.identity small {
display: none;
}
.comparison {
grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
gap: 6px;
padding: 11px;
}
.sequence.current {
padding: 8px;
}
.code-line {
overflow: hidden;
font-size: 12px;
letter-spacing: 0.025em;
text-overflow: ellipsis;
}
.chips {
gap: 4px;
}
.chip {
width: 33px;
height: 43px;
border-radius: 8px;
}
.chip-glyph {
font-size: 18px;
}
.chip-code {
font-size: 7px;
}
.swap {
width: 27px;
height: 27px;
font-size: 15px;
}
.panel-footer {
padding: 10px 12px;
}
.camera-hint {
display: none;
}
}
@media (max-height: 650px) {
.intro p,
.identity small {
display: none;
}
.sequence-panel {
bottom: 10px;
}
.panel-heading {
padding-top: 9px;
padding-bottom: 9px;
}
.comparison {
padding-top: 9px;
padding-bottom: 9px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly symbol track"></div>
<div class="hud">
<header class="intro">
<div class="eyebrow">Order Lab / 01</div>
<h1>Reading is a sequence.</h1>
<p>
The same six written symbols can produce a different encoded message
when the reading direction changes.
</p>
</header>
<div class="direction-card">
<span>Reading direction</span>
<div class="direction-value">
<strong id="directionArrow">→</strong>
<span id="directionText">LEFT → RIGHT</span>
</div>
</div>
</div>
<section class="sequence-panel" aria-label="Encoded sequence comparison">
<div class="panel-heading">
<strong>Encoded sequence</strong>
<div class="identity">
<span class="identity-check">✓</span>
<div>
<strong>Same tile inventory</strong>
<small>6 identities preserved · 0 added · 0 removed</small>
</div>
</div>
</div>
<div class="comparison">
<div class="sequence">
<div class="sequence-label">Track order · left → right</div>
<div class="code-line" id="originalCode"></div>
<div class="chips" id="originalChips"></div>
</div>
<div class="swap" aria-hidden="true">↔</div>
<div class="sequence current">
<div class="sequence-label" id="currentLabel">Current read · left → right</div>
<div class="code-line" id="currentCode" aria-live="polite"></div>
<div class="chips" id="currentChips"></div>
</div>
</div>
<div class="panel-footer">
<button class="button primary" id="reverseButton" type="button">
<span class="button-icon">↔</span>
<span id="reverseButtonLabel">Reverse reading order</span>
</button>
<button class="button" id="resetCameraButton" type="button">
Reset camera
</button>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Hover a tile</div>
</div>
</section>
<div class="toast" id="toast" role="status"></div>
<div class="tile-tooltip" id="tileTooltip">
<span class="tooltip-glyph" id="tipGlyph"></span>
<div class="tooltip-copy">
<strong id="tipCode"></strong>
<small id="tipName"></small>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 18, 38);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xbcdcff, 0x172033, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.0);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x55e8c2, 24, 18, 2);
cyanLight.position.set(7, 4, -4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff8d70, 18, 16, 2);
warmLight.position.set(-7, 3, 4);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Written symbols
// -------------------------------------------------------------------------
const symbols = [
{
glyph: "△",
code: "17",
name: "Peak",
color: 0xffb45e,
css: "#ffb45e",
kind: 0
},
{
glyph: "◇",
code: "42",
name: "Frame",
color: 0x55d6be,
css: "#55d6be",
kind: 1
},
{
glyph: "◎",
code: "08",
name: "Eye",
color: 0xff6f91,
css: "#ff6f91",
kind: 2
},
{
glyph: "ϟ",
code: "63",
name: "Bolt",
color: 0x91a7ff,
css: "#91a7ff",
kind: 3
},
{
glyph: "⋈",
code: "29",
name: "Cross",
color: 0xe6dc6a,
css: "#e6dc6a",
kind: 4
},
{
glyph: "✳",
code: "51",
name: "Star",
color: 0xa981ff,
css: "#a981ff",
kind: 5
}
];
const symbolCount = symbols.length;
const spacing = 1.48;
const tilePositions = symbols.map(
(_, index) => (index - (symbolCount - 1) / 2) * spacing
);
function createGlyphTexture(symbol) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
ctx.translate(128, 120);
ctx.strokeStyle = "#ffffff";
ctx.fillStyle = "#ffffff";
ctx.lineWidth = 15;
ctx.lineCap = "square";
ctx.lineJoin = "miter";
ctx.shadowColor = "rgba(0,0,0,0.35)";
ctx.shadowBlur = 9;
switch (symbol.kind) {
case 0: {
ctx.beginPath();
ctx.moveTo(-74, 54);
ctx.lineTo(0, -72);
ctx.lineTo(74, 54);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 15, 10, 0, Math.PI * 2);
ctx.fill();
break;
}
case 1: {
ctx.beginPath();
ctx.moveTo(0, -80);
ctx.lineTo(70, 0);
ctx.lineTo(0, 80);
ctx.lineTo(-70, 0);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-24, 0);
ctx.lineTo(24, 0);
ctx.moveTo(0, -28);
ctx.lineTo(0, 28);
ctx.stroke();
break;
}
case 2: {
ctx.beginPath();
ctx.arc(0, 0, 69, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, 18, 0, Math.PI * 2);
ctx.fill();
break;
}
case 3: {
ctx.beginPath();
ctx.moveTo(-60, -75);
ctx.lineTo(43, -75);
ctx.lineTo(-12, 8);
ctx.lineTo(58, 8);
ctx.lineTo(-48, 82);
ctx.lineTo(-20, 17);
ctx.lineTo(-75, 17);
ctx.closePath();
ctx.fill();
break;
}
case 4: {
ctx.beginPath();
ctx.moveTo(-61, -75);
ctx.lineTo(61, -75);
ctx.lineTo(0, 0);
ctx.lineTo(61, 75);
ctx.lineTo(-61, 75);
ctx.lineTo(0, 0);
ctx.closePath();
ctx.stroke();
break;
}
case 5: {
const points = [];
for (let i = 0; i < 12; i++) {
const angle = -Math.PI / 2 + (i * Math.PI) / 6;
const radius = i % 2 === 0 ? 83 : 31;
points.push({
x: Math.cos(angle) * radius,
y: Math.sin(angle) * radius
});
}
ctx.beginPath();
points.forEach((point, index) => {
if (index === 0) ctx.moveTo(point.x, point.y);
else ctx.lineTo(point.x, point.y);
});
ctx.closePath();
ctx.fill();
ctx.beginPath();
ctx.arc(0, 0, 13, 0, Math.PI * 2);
ctx.fillStyle = "#152033";
ctx.fill();
break;
}
}
ctx.shadowBlur = 0;
ctx.fillStyle = "#ffffff";
ctx.font = "700 28px ui-monospace, SFMono-Regular, Consolas, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(symbol.code, 128, 221);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
// -------------------------------------------------------------------------
// Ground and faceted environment
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CircleGeometry(32, 36),
new THREE.MeshStandardMaterial({
color: 0x0c1828,
roughness: 1,
metalness: 0,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(38, 38, 0x33506c, 0x1b3048);
grid.position.y = -0.235;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
let randomSeed = 9147;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const decor = new THREE.Group();
const decorMaterials = [
new THREE.MeshStandardMaterial({
color: 0x16283d,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x1c3147,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x24354b,
roughness: 0.95,
flatShading: true
})
];
for (let i = 0; i < 34; i++) {
const x = (random() - 0.5) * 30;
const z = (random() - 0.5) * 19;
if (Math.abs(x) < 7.2 && Math.abs(z) < 2.2) continue;
const radius = 0.25 + random() * 0.65;
const geometry =
i % 3 === 0
? new THREE.ConeGeometry(radius, radius * 2.3, 5)
: new THREE.DodecahedronGeometry(radius, 0);
const rock = new THREE.Mesh(
geometry,
decorMaterials[i % decorMaterials.length]
);
rock.position.set(x, -0.13 + radius * 0.42, z);
rock.scale.y = 0.65 + random() * 1.25;
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
decor.add(rock);
}
scene.add(decor);
// -------------------------------------------------------------------------
// Low-poly track
// -------------------------------------------------------------------------
function createRoundedRectangle(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const trackShape = createRoundedRectangle(13.4, 1.72, 0.34);
const trackGeometry = new THREE.ExtrudeGeometry(trackShape, {
depth: 0.16,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.07,
bevelThickness: 0.05
});
trackGeometry.rotateX(-Math.PI / 2);
const track = new THREE.Mesh(
trackGeometry,
new THREE.MeshStandardMaterial({
color: 0x27394f,
roughness: 0.76,
metalness: 0.16,
flatShading: true
})
);
track.position.y = -0.02;
track.receiveShadow = true;
track.castShadow = true;
scene.add(track);
const railGeometry = new THREE.BoxGeometry(12.35, 0.1, 0.09);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0xe1b96d,
roughness: 0.48,
metalness: 0.55,
flatShading: true
});
for (const z of [-0.62, 0.62]) {
const rail = new THREE.Mesh(railGeometry, railMaterial);
rail.position.set(0, 0.21, z);
rail.castShadow = true;
scene.add(rail);
}
const tieGeometry = new THREE.BoxGeometry(0.14, 0.055, 1.34);
const tieMaterial = new THREE.MeshStandardMaterial({
color: 0x71839a,
roughness: 0.9,
flatShading: true
});
for (let x = -5.7; x <= 5.7; x += 0.76) {
const tie = new THREE.Mesh(tieGeometry, tieMaterial);
tie.position.set(x, 0.17, 0);
tie.receiveShadow = true;
scene.add(tie);
}
// Direction chevrons on the front side of the track.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.23, -0.1);
arrowShape.lineTo(0.01, -0.1);
arrowShape.lineTo(0.01, -0.23);
arrowShape.lineTo(0.29, 0);
arrowShape.lineTo(0.01, 0.23);
arrowShape.lineTo(0.01, 0.1);
arrowShape.lineTo(-0.23, 0.1);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
arrowGeometry.rotateX(-Math.PI / 2);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0x65f0c2,
emissive: 0x176b59,
emissiveIntensity: 1.1,
roughness: 0.55,
side: THREE.DoubleSide,
flatShading: true
});
const directionArrows = [];
for (const x of [-5, -2.5, 0, 2.5, 5]) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.set(x, -0.16, 1.19);
scene.add(arrow);
directionArrows.push(arrow);
}
// -------------------------------------------------------------------------
// Symbol tiles
// -------------------------------------------------------------------------
const tiles = [];
const hitMeshes = [];
const baseGeometry = new THREE.CylinderGeometry(0.56, 0.58, 0.12, 6);
const tileGeometry = new THREE.CylinderGeometry(0.5, 0.52, 0.22, 6);
const symbolGeometry = new THREE.PlaneGeometry(0.78, 0.78);
symbols.forEach((symbol, index) => {
const group = new THREE.Group();
group.position.set(tilePositions[index], 0.39, 0);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x152235,
roughness: 0.78,
metalness: 0.18,
flatShading: true
})
);
base.rotation.y = Math.PI / 6;
base.castShadow = true;
base.receiveShadow = true;
base.userData.symbolIndex = index;
group.add(base);
const top = new THREE.Mesh(
tileGeometry,
new THREE.MeshStandardMaterial({
color: symbol.color,
roughness: 0.7,
metalness: 0.04,
flatShading: true
})
);
top.position.y = 0.13;
top.rotation.y = Math.PI / 6;
top.castShadow = true;
top.receiveShadow = true;
top.userData.symbolIndex = index;
group.add(top);
const edgeLines = new THREE.LineSegments(
new THREE.EdgesGeometry(tileGeometry, 18),
new THREE.LineBasicMaterial({
color: 0x172033,
transparent: true,
opacity: 0.34
})
);
edgeLines.position.y = 0.13;
edgeLines.rotation.y = Math.PI / 6;
group.add(edgeLines);
const glyph = new THREE.Mesh(
symbolGeometry,
new THREE.MeshBasicMaterial({
map: createGlyphTexture(symbol),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
})
);
glyph.rotation.x = -Math.PI / 2;
glyph.position.y = 0.245;
group.add(glyph);
scene.add(group);
tiles.push({
group,
top,
symbolIndex: index,
baseY: 0.39
});
hitMeshes.push(base, top);
});
// -------------------------------------------------------------------------
// Start marker
// -------------------------------------------------------------------------
function createTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(7, 18, 31, 0.9)";
ctx.strokeStyle = "rgba(101, 240, 194, 0.6)";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.roundRect(12, 12, 488, 104, 24);
ctx.fill();
ctx.stroke();
ctx.fillStyle = "#65f0c2";
ctx.font = "800 43px ui-sans-serif, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 67);
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,
toneMapped: false
})
);
sprite.scale.set(1.45, 0.36, 1);
return sprite;
}
const startMarker = new THREE.Group();
startMarker.position.set(-5.9, 0.2, 1.48);
const markerBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.25, 0.14, 6),
new THREE.MeshStandardMaterial({
color: 0x65f0c2,
emissive: 0x123e32,
emissiveIntensity: 0.7,
roughness: 0.6,
flatShading: true
})
);
markerBase.position.y = 0.02;
markerBase.castShadow = true;
startMarker.add(markerBase);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 1.35, 6),
new THREE.MeshStandardMaterial({
color: 0xc7d3df,
roughness: 0.48,
metalness: 0.55,
flatShading: true
})
);
pole.position.y = 0.72;
pole.castShadow = true;
startMarker.add(pole);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.03, 1.3, 0,
0.68, 1.08, 0,
0.03, 0.83, 0
],
3
)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: 0x65f0c2,
emissive: 0x174b3e,
emissiveIntensity: 0.8,
side: THREE.DoubleSide,
roughness: 0.62,
flatShading: true
})
);
flag.castShadow = true;
startMarker.add(flag);
const startLabel = createTextSprite("START");
startLabel.position.set(0.35, 1.7, 0);
startMarker.add(startLabel);
scene.add(startMarker);
// -------------------------------------------------------------------------
// Animated reading cursor
// -------------------------------------------------------------------------
const scanner = new THREE.Group();
scanner.visible = false;
const scannerDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
new THREE.MeshBasicMaterial({
color: 0xffce69,
wireframe: true,
toneMapped: false
})
);
scanner.add(scannerDiamond);
const scannerPointer = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.38, 3),
new THREE.MeshStandardMaterial({
color: 0xffce69,
emissive: 0x7a5410,
emissiveIntensity: 1.2,
flatShading: true
})
);
scannerPointer.rotation.z = -Math.PI / 2;
scannerPointer.position.set(0.29, 0.03, 0);
scanner.add(scannerPointer);
const scannerBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 0.5, 4),
new THREE.MeshBasicMaterial({
color: 0xffce69,
transparent: true,
opacity: 0.5,
toneMapped: false
})
);
scannerBeam.position.y = -0.3;
scanner.add(scannerBeam);
scene.add(scanner);
// -------------------------------------------------------------------------
// Direct camera controls: no OrbitControls or addons
// -------------------------------------------------------------------------
const cameraState = {
radius: window.innerWidth < 700 ? 21 : 16.5,
theta: 0.38,
phi: 0.84,
target: new THREE.Vector3(0, 0.3, 0)
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const tooltip = document.getElementById("tileTooltip");
const tipGlyph = document.getElementById("tipGlyph");
const tipCode = document.getElementById("tipCode");
const tipName = document.getElementById("tipName");
let hoveredSymbol = -1;
let dragging = false;
let movedWhileDragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateHover(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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(hitMeshes, false);
if (!hits.length) {
hoveredSymbol = -1;
tooltip.classList.remove("visible");
renderer.domElement.style.cursor = dragging ? "grabbing" : "grab";
return;
}
hoveredSymbol = hits[0].object.userData.symbolIndex;
const symbol = symbols[hoveredSymbol];
tipGlyph.textContent = symbol.glyph;
tipGlyph.style.setProperty("--tip-color", symbol.css);
tipCode.textContent = `Code ${symbol.code}`;
tipName.textContent = `${symbol.name} · tile ${String(hoveredSymbol + 1).padStart(2, "0")}`;
tooltip.style.left = `${Math.min(event.clientX + 16, window.innerWidth - 190)}px`;
tooltip.style.top = `${Math.min(event.clientY + 16, window.innerHeight - 75)}px`;
tooltip.classList.add("visible");
renderer.domElement.style.cursor = "pointer";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
movedWhileDragging = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
tooltip.classList.remove("visible");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) {
movedWhileDragging = true;
}
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.35,
1.34
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
} else {
updateHover(event);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
hoveredSymbol = -1;
tooltip.classList.remove("visible");
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
resetCamera();
});
// -------------------------------------------------------------------------
// Sequence UI and interaction
// -------------------------------------------------------------------------
const originalCode = document.getElementById("originalCode");
const currentCode = document.getElementById("currentCode");
const originalChips = document.getElementById("originalChips");
const currentChips = document.getElementById("currentChips");
const currentLabel = document.getElementById("currentLabel");
const directionArrow = document.getElementById("directionArrow");
const directionText = document.getElementById("directionText");
const reverseButton = document.getElementById("reverseButton");
const reverseButtonLabel = document.getElementById("reverseButtonLabel");
const resetCameraButton = document.getElementById("resetCameraButton");
const toast = document.getElementById("toast");
let direction = 1;
let markerTargetX = -5.9;
let targetArrowAngle = 0;
let arrowAngle = 0;
let scanning = false;
let scanElapsed = 0;
let scanDuration = 1;
let scanStartX = 0;
let scanEndX = 0;
let toastTimer;
function chipMarkup(symbol, index) {
return `
<div
class="chip"
style="--c:${symbol.css}; --delay:${index * 45}ms"
title="${symbol.name}, code ${symbol.code}"
>
<span class="chip-glyph">${symbol.glyph}</span>
<span class="chip-code">${symbol.code}</span>
</div>
`;
}
function updateSequenceUI() {
const originalOrder = symbols.map((_, index) => index);
const currentOrder =
direction === 1
? [...originalOrder]
: [...originalOrder].reverse();
originalCode.textContent = originalOrder
.map((index) => symbols[index].code)
.join(" · ");
currentCode.textContent = currentOrder
.map((index) => symbols[index].code)
.join(" · ");
originalChips.innerHTML = originalOrder
.map((index, chipIndex) => chipMarkup(symbols[index], chipIndex))
.join("");
currentChips.innerHTML = currentOrder
.map((index, chipIndex) => chipMarkup(symbols[index], chipIndex))
.join("");
currentLabel.textContent =
direction === 1
? "Current read · left → right"
: "Current read · right → left";
directionArrow.classList.toggle("reversed", direction === -1);
directionText.textContent =
direction === 1 ? "LEFT → RIGHT" : "RIGHT → LEFT";
reverseButtonLabel.textContent =
direction === 1 ? "Reverse reading order" : "Restore original direction";
reverseButton.setAttribute("aria-pressed", String(direction === -1));
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 2300);
}
function startScan() {
scanStartX =
direction === 1
? tilePositions[0]
: tilePositions[symbolCount - 1];
scanEndX =
direction === 1
? tilePositions[symbolCount - 1]
: tilePositions[0];
scanElapsed = 0;
scanDuration = Math.abs(scanEndX - scanStartX) / 3.4;
scanning = true;
scanner.visible = true;
scanner.position.set(scanStartX, 1.1, 0);
scanner.rotation.y = direction === 1 ? 0 : Math.PI;
}
reverseButton.addEventListener("click", () => {
direction *= -1;
targetArrowAngle = direction === 1 ? 0 : Math.PI;
markerTargetX = direction === 1 ? -5.9 : 5.9;
updateSequenceUI();
startScan();
showToast(
direction === -1
? "Same six symbols. Reading from the right reverses the code."
: "Reading from the left restores the original code."
);
});
function resetCamera() {
cameraState.radius = window.innerWidth < 700 ? 21 : 16.5;
cameraState.theta = 0.38;
cameraState.phi = 0.84;
cameraState.target.set(0, 0.3, 0);
updateCamera();
showToast("Camera reset.");
}
resetCameraButton.addEventListener("click", resetCamera);
updateSequenceUI();
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 700 ? 52 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
onResize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Tile hover lift.
tiles.forEach((tile) => {
const lifted = tile.symbolIndex === hoveredSymbol ? 0.085 : 0;
tile.group.position.y = THREE.MathUtils.damp(
tile.group.position.y,
tile.baseY + lifted,
10,
delta
);
});
// Move the physical start marker to the selected reading end.
startMarker.position.x = THREE.MathUtils.damp(
startMarker.position.x,
markerTargetX,
5,
delta
);
// Rotate all direction arrows into the new reading direction.
arrowAngle = THREE.MathUtils.damp(
arrowAngle,
targetArrowAngle,
5.5,
delta
);
directionArrows.forEach((arrow) => {
arrow.rotation.y = arrowAngle;
});
// Scan the tiles in the current reading direction.
if (scanning) {
scanElapsed += delta;
const progress = Math.min(scanElapsed / scanDuration, 1);
scanner.position.x = THREE.MathUtils.lerp(
scanStartX,
scanEndX,
progress
);
scanner.position.y =
1.08 + Math.sin(progress * Math.PI) * 0.16;
scannerDiamond.rotation.y = elapsed * 2.2;
scannerDiamond.rotation.x = elapsed * 1.35;
if (progress >= 1) {
scanning = false;
scanner.visible = false;
}
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```