Prompt specification
Build or customize the Three.js 3D scene "Choose-confirm-print interaction" 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: Choose-confirm-print interaction
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-confirm-print-interaction-x0478
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Animate a ticket kiosk through selection, confirmation, and printing states; the chosen destination stays visibly consistent across button highlight, summary panel, and printed ticket.
Working Three.js Starter (choose-confirm-print-interaction-x0478):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dbe8e2" />
<title>Northline — Ticket Kiosk</title>
<style>
:root {
--accent: #f26b4d;
--ink: #132d36;
--muted: #6c7f83;
--panel: rgba(250, 248, 240, 0.93);
--line: rgba(19, 45, 54, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#scene canvas:focus-visible {
outline: 3px solid var(--accent);
outline-offset: -4px;
}
.topbar {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
right: 390px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
border: 2px solid var(--ink);
border-radius: 14px 5px 14px 5px;
transform: rotate(-4deg);
background: rgba(250, 248, 240, 0.66);
box-shadow: 0 8px 20px rgba(19, 45, 54, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 9px;
right: 9px;
height: 3px;
border-radius: 3px;
background: var(--ink);
transform: rotate(-24deg);
}
.brand-mark::before {
top: 13px;
}
.brand-mark::after {
top: 23px;
left: 16px;
}
.brand-name {
font-size: 15px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand-sub {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 999px;
background: rgba(250, 248, 240, 0.72);
color: var(--ink);
font-size: 12px;
font-weight: 750;
box-shadow: 0 10px 30px rgba(19, 45, 54, 0.07);
backdrop-filter: blur(12px);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
bottom: 22px;
width: 344px;
padding: 25px;
overflow-y: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 26px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(19, 45, 54, 0.16);
backdrop-filter: blur(20px);
scrollbar-width: thin;
}
.panel.pulse {
animation: panelPulse 420ms ease;
}
@keyframes panelPulse {
0% { transform: scale(0.985); }
50% { transform: scale(1.008); }
100% { transform: scale(1); }
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live-badge {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--ink);
}
.live-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #42a36f;
box-shadow: 0 0 0 4px rgba(66, 163, 111, 0.13);
}
h1 {
max-width: 280px;
margin: 0 0 8px;
font-size: clamp(28px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.055em;
}
.intro {
margin: 0 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.state-label {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 17px;
padding: 7px 10px;
border-radius: 8px;
background: color-mix(in srgb, var(--accent) 14%, transparent);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.state-label::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
}
.section-title {
margin: 0 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.destination-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 18px;
}
.destination-button {
min-height: 54px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.54);
color: var(--ink);
cursor: pointer;
text-align: left;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.destination-button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.destination-button.active {
border-color: transparent;
background: var(--destination-color);
box-shadow: 0 7px 16px color-mix(in srgb, var(--destination-color) 28%, transparent);
}
.destination-button:disabled {
cursor: default;
opacity: 0.66;
}
.destination-button strong {
display: block;
font-size: 11px;
line-height: 1.2;
}
.destination-button span {
display: block;
margin-top: 4px;
color: rgba(19, 45, 54, 0.62);
font-size: 9px;
font-weight: 700;
}
.destination-button.active span {
color: rgba(19, 45, 54, 0.72);
}
.itinerary-card {
position: relative;
overflow: hidden;
padding: 17px;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(255, 255, 255, 0.64);
}
.itinerary-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 5px;
background: var(--accent);
}
.ticket-route {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.ticket-route::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
}
.route-name {
margin: 0 0 4px;
font-size: 24px;
line-height: 1.08;
letter-spacing: -0.04em;
}
.route-meta {
margin: 0;
color: var(--muted);
font-size: 11px;
}
.trip-facts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 16px;
}
.trip-fact {
padding-top: 9px;
border-top: 1px solid var(--line);
}
.trip-fact span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.trip-fact strong {
display: block;
margin-top: 4px;
font-size: 13px;
}
.steps {
display: flex;
align-items: flex-start;
justify-content: space-between;
margin: 20px 0;
}
.step {
position: relative;
flex: 1;
color: #a2afb0;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.step:not(:last-child)::after {
content: "";
position: absolute;
top: 9px;
left: 24px;
right: 7px;
height: 1px;
background: var(--line);
}
.step-dot {
position: relative;
z-index: 1;
width: 18px;
height: 18px;
margin-bottom: 7px;
border: 1px solid #c5cecc;
border-radius: 50%;
background: var(--panel);
}
.step.current {
color: var(--ink);
}
.step.current .step-dot {
border: 5px solid var(--accent);
}
.step.done {
color: #657879;
}
.step.done .step-dot {
border-color: var(--accent);
background: var(--accent);
}
.panel-actions {
display: flex;
gap: 8px;
}
.back-button,
.primary-button {
min-height: 44px;
border-radius: 11px;
cursor: pointer;
font-size: 11px;
font-weight: 850;
transition:
transform 160ms ease,
opacity 160ms ease,
box-shadow 160ms ease;
}
.back-button {
padding: 0 14px;
border: 1px solid var(--line);
background: transparent;
color: var(--ink);
}
.primary-button {
flex: 1;
border: 0;
background: var(--accent);
color: var(--ink);
box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 27%, transparent);
}
.primary-button:hover:not(:disabled),
.back-button:hover {
transform: translateY(-1px);
}
.primary-button:disabled {
cursor: wait;
opacity: 0.68;
}
.progress-track {
height: 5px;
margin: 0 0 18px;
overflow: hidden;
border-radius: 999px;
background: var(--line);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 80ms linear;
}
.panel-note {
margin: 16px 0 0;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.scene-hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 999px;
background: rgba(250, 248, 240, 0.68);
color: #536a6e;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
backdrop-filter: blur(12px);
pointer-events: none;
}
.mouse-icon {
width: 15px;
height: 21px;
border: 1.5px solid currentColor;
border-radius: 9px;
}
.mouse-icon::before {
content: "";
display: block;
width: 2px;
height: 5px;
margin: 3px auto 0;
border-radius: 2px;
background: currentColor;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 820px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
}
.brand-sub,
.top-status {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 44vh;
padding: 18px;
border-radius: 21px;
}
h1 {
max-width: none;
margin-bottom: 5px;
font-size: 25px;
}
.intro,
.panel-note,
.steps {
display: none;
}
.state-label {
margin-bottom: 12px;
}
.destination-grid {
grid-template-columns: repeat(4, 1fr);
margin-bottom: 12px;
}
.destination-button {
min-height: 48px;
padding: 8px;
}
.destination-button span {
display: none;
}
.itinerary-card {
padding: 13px;
}
.route-name {
font-size: 19px;
}
.trip-facts {
margin-top: 11px;
}
.scene-hint {
display: none;
}
}
@media (max-width: 520px) {
.destination-grid {
grid-template-columns: 1fr 1fr;
}
.trip-fact:nth-child(3) {
display: none;
}
.trip-facts {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-name">Northline</div>
<div class="brand-sub">Self-service terminal · Station 04</div>
</div>
</div>
<div class="top-status">
<span class="status-dot"></span>
<span id="topStatus">Kiosk ready</span>
</div>
</header>
<aside class="panel" id="panel">
<div class="eyebrow">
<span>Live itinerary</span>
<span class="live-badge">Kiosk online</span>
</div>
<h1 id="panelTitle">Where to next?</h1>
<p class="intro" id="panelIntro">
Choose a destination, check the details, then print your ticket.
</p>
<div class="state-label" id="stateLabel">01 · Selection</div>
<div class="section-title">Choose destination</div>
<div class="destination-grid" id="destinationGrid"></div>
<div class="section-title">Your journey</div>
<section class="itinerary-card" aria-live="polite">
<div class="ticket-route" id="routeMeta">Central Station → Alpine Loop</div>
<h2 class="route-name" id="routeName">Alpine Pass</h2>
<p class="route-meta" id="routeSubtitle">Mountain rail · One-way ticket</p>
<div class="trip-facts">
<div class="trip-fact">
<span>Departs</span>
<strong id="departTime">09:20</strong>
</div>
<div class="trip-fact">
<span>Platform</span>
<strong id="platform">A</strong>
</div>
<div class="trip-fact">
<span>Fare</span>
<strong id="price">$28</strong>
</div>
</div>
</section>
<div class="progress-track" aria-hidden="true">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="steps" aria-label="Ticket progress">
<div class="step current" data-step="selection">
<div class="step-dot"></div>
Select
</div>
<div class="step" data-step="confirmation">
<div class="step-dot"></div>
Confirm
</div>
<div class="step" data-step="printing">
<div class="step-dot"></div>
Print
</div>
</div>
<div class="panel-actions">
<button class="back-button" id="backButton" hidden>Back</button>
<button class="primary-button" id="panelAction">Review selection</button>
</div>
<p class="panel-note">
You can also use the kiosk screen directly. Drag the scene to orbit,
scroll to zoom, and press keys 1–4 to choose a destination.
</p>
</aside>
<div class="scene-hint" aria-hidden="true">
<span class="mouse-icon"></span>
Drag to orbit · Scroll to zoom · Click the screen
</div>
<div class="sr-only" id="liveRegion" aria-live="assertive"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Shared destination data. Every view uses this same object, so the
// highlighted button, summary card, panel, and printed ticket cannot drift.
// -------------------------------------------------------------------------
const destinations = [
{
name: "Alpine Pass",
route: "Alpine Loop",
depart: "09:20",
platform: "A",
price: "$28",
code: "ALP",
color: "#f26b4d",
detail: "Mountain rail"
},
{
name: "Harbor City",
route: "Coast Line",
depart: "09:40",
platform: "C",
price: "$36",
code: "HBR",
color: "#2d9cdb",
detail: "Coastal express"
},
{
name: "Sunset Mesa",
route: "Desert Spur",
depart: "10:05",
platform: "B",
price: "$31",
code: "MSM",
color: "#f2b134",
detail: "Desert railway"
},
{
name: "Aurora Bay",
route: "North Express",
depart: "10:25",
platform: "D",
price: "$42",
code: "AUR",
color: "#7b61ff",
detail: "Northern line"
}
];
let selectedIndex = 0;
let state = "selection";
let printProgress = 0;
let printStart = 0;
let transitionStart = performance.now();
let hoverRegionId = null;
let screenRegions = [];
let lastPrintDraw = 0;
const selected = () => destinations[selectedIndex];
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8e2);
scene.fog = new THREE.Fog(0xdbe8e2, 13, 31);
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D ticket kiosk. Use the side panel or keys 1 through 4 to select a destination."
);
document.getElementById("scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.15, 1.65, 0);
const cameraGoal = {
theta: 0.47,
phi: 1.16,
radius: 8.3
};
const cameraCurrent = {
theta: cameraGoal.theta,
phi: cameraGoal.phi,
radius: cameraGoal.radius
};
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x8e9f87, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5df, 3.1);
sun.position.set(-5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dc9df, 0.75);
fill.position.set(7, 4, -5);
scene.add(fill);
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
}
function addBox(parent, size, position, color, extra = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material(color, extra)
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
position,
color
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material(color)
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Low-poly environment
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
material(0xcfdbd0)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const platform = addCylinder(
scene,
3.45,
3.65,
0.18,
8,
[-0.7, 0.02, 0.1],
0xe9e3d6
);
platform.receiveShadow = true;
addCylinder(
scene,
2.95,
3.05,
0.035,
8,
[-0.7, 0.13, 0.1],
0xf4eee2
);
// Inlaid platform stripes.
for (let i = 0; i < 7; i++) {
const tile = addBox(
scene,
[0.12, 0.015, 2.35],
[-2.45 + i * 0.55, 0.155, -0.2],
i % 3 === 0 ? 0xb8d7ce : 0xd8d1c3
);
tile.rotation.y = -0.04;
}
// Faceted mountains.
const mountainMaterialA = material(0xaabeb1);
const mountainMaterialB = material(0x91aa9f);
const mountainMaterialC = material(0xc1d0c2);
const mountainSpecs = [
[-6.2, 1.8, -8.2, 3.1, 4.7, mountainMaterialA],
[-1.2, 1.5, -10.5, 4.0, 5.4, mountainMaterialB],
[4.5, 1.9, -9.0, 3.5, 5.1, mountainMaterialC]
];
for (const [x, y, z, radius, height, mat] of mountainSpecs) {
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5),
mat
);
mountain.position.set(x, y, z);
mountain.rotation.y = Math.PI / 5;
mountain.castShadow = true;
mountain.receiveShadow = true;
scene.add(mountain);
}
// Low-poly clouds.
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
const cloudMaterial = material(0xf7f3e9);
const pieces = [
[-0.65, 0, 0, 0.56],
[0, 0.2, 0, 0.75],
[0.7, 0, 0, 0.52],
[0.15, -0.12, 0.12, 0.63]
];
for (const [px, py, pz, radius] of pieces) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 1),
cloudMaterial
);
puff.position.set(px, py, pz);
cloud.add(puff);
}
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
}
addCloud(-4.6, 6.4, -9.4, 1.05);
addCloud(4.0, 5.6, -11.2, 0.82);
// Trees.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.15, 1.05, 5),
material(0x866d55)
);
trunk.position.y = 0.52;
trunk.castShadow = true;
tree.add(trunk);
const leafMaterial = material(0x5f8b75);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.7, 1.7, 6),
leafMaterial
);
lower.position.y = 1.55;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.5, 1.35, 6),
material(0x769c82)
);
upper.position.y = 2.25;
upper.castShadow = true;
tree.add(upper);
tree.position.set(x, 0.12, z);
tree.scale.setScalar(scale);
scene.add(tree);
}
addTree(3.25, -1.95, 1.05);
addTree(3.95, -2.7, 0.72);
addTree(-4.0, -2.4, 0.65);
// Small faceted rocks.
const rockGeometry = new THREE.DodecahedronGeometry(0.38, 0);
[
[2.4, 0.25, 1.5, 0.8],
[1.85, 0.15, 1.75, 0.45],
[-3.9, 0.2, 1.2, 0.55]
].forEach(([x, y, z, scale]) => {
const rock = new THREE.Mesh(rockGeometry, material(0xa7b3aa));
rock.position.set(x, y, z);
rock.scale.set(scale, scale * 0.65, scale);
rock.rotation.set(0.4, x, 0.2);
rock.castShadow = true;
scene.add(rock);
});
// -------------------------------------------------------------------------
// Kiosk
// -------------------------------------------------------------------------
const kiosk = new THREE.Group();
kiosk.position.set(-1.25, 0.14, 0.05);
kiosk.rotation.y = -0.08;
scene.add(kiosk);
addCylinder(kiosk, 1.25, 1.4, 0.24, 8, [0, 0.12, 0], 0x173740);
addBox(kiosk, [1.9, 0.42, 1.38], [0, 0.39, 0], 0xe8e1d3);
addBox(kiosk, [2.75, 3.2, 1.25], [0, 2.06, 0], 0xf3ecdf);
addBox(kiosk, [2.96, 0.22, 1.43], [0, 3.76, 0], 0x173740);
addBox(kiosk, [2.48, 0.09, 1.31], [0, 3.59, 0], 0x36535a);
// Dark side panels and lower service door.
addBox(kiosk, [0.11, 2.72, 0.93], [-1.43, 1.98, -0.02], 0x2a4850);
addBox(kiosk, [0.11, 2.72, 0.93], [1.43, 1.98, -0.02], 0x2a4850);
addBox(kiosk, [1.65, 0.68, 0.07], [0, 0.83, 0.64], 0x29464d);
addBox(kiosk, [1.76, 0.12, 0.09], [0, 1.28, 0.68], 0x102a32);
addBox(kiosk, [1.96, 0.08, 0.09], [0, 1.38, 0.67], 0xb8c2bc);
// Screen frame.
addBox(
kiosk,
[2.78, 1.84, 0.18],
[0, 2.48, 0.69],
0x102a32,
{ roughness: 0.5 }
);
// Dynamic accent bar below the screen.
const beaconMaterial = material(selected().color, {
emissive: selected().color,
emissiveIntensity: 0.16
});
const beacon = addBox(
kiosk,
[1.45, 0.055, 0.055],
[0, 1.46, 0.69],
selected().color,
{ emissive: selected().color, emissiveIntensity: 0.18 }
);
beacon.material = beaconMaterial;
// Physical status lamp.
const lampMaterial = material(selected().color, {
emissive: selected().color,
emissiveIntensity: 0.8
});
const lamp = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.085, 1),
lampMaterial
);
lamp.position.set(0.68, 0.9, 0.69);
kiosk.add(lamp);
// -------------------------------------------------------------------------
// Screen canvas and textures
// -------------------------------------------------------------------------
const screenCanvas = document.createElement("canvas");
screenCanvas.width = 1024;
screenCanvas.height = 640;
const screenContext = screenCanvas.getContext("2d");
const screenTexture = new THREE.CanvasTexture(screenCanvas);
screenTexture.colorSpace = THREE.SRGBColorSpace;
screenTexture.minFilter = THREE.LinearFilter;
screenTexture.magFilter = THREE.LinearFilter;
const screenMaterial = new THREE.MeshStandardMaterial({
map: screenTexture,
emissive: 0xffffff,
emissiveMap: screenTexture,
emissiveIntensity: 0.28,
roughness: 0.35,
metalness: 0
});
const screenMesh = new THREE.Mesh(
new THREE.PlaneGeometry(2.56, 1.6),
screenMaterial
);
screenMesh.position.set(0, 2.48, 0.787);
kiosk.add(screenMesh);
const ticketCanvas = document.createElement("canvas");
ticketCanvas.width = 900;
ticketCanvas.height = 480;
const ticketContext = ticketCanvas.getContext("2d");
const ticketTexture = new THREE.CanvasTexture(ticketCanvas);
ticketTexture.colorSpace = THREE.SRGBColorSpace;
ticketTexture.minFilter = THREE.LinearFilter;
ticketTexture.magFilter = THREE.LinearFilter;
const ticketPivot = new THREE.Group();
ticketPivot.position.set(0, 1.22, 0.86);
ticketPivot.visible = false;
kiosk.add(ticketPivot);
const ticketMesh = new THREE.Mesh(
new THREE.PlaneGeometry(2.04, 1.088),
new THREE.MeshStandardMaterial({
map: ticketTexture,
roughness: 0.93,
side: THREE.DoubleSide
})
);
ticketMesh.position.y = -0.544;
ticketMesh.castShadow = true;
ticketPivot.add(ticketMesh);
// A small plaque above the printer.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 512;
plaqueCanvas.height = 128;
const plaqueContext = plaqueCanvas.getContext("2d");
plaqueContext.fillStyle = "#dce4de";
plaqueContext.fillRect(0, 0, 512, 128);
plaqueContext.fillStyle = "#173740";
plaqueContext.font = "800 35px system-ui";
plaqueContext.textAlign = "center";
plaqueContext.fillText("TICKETS ↓", 256, 78);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(0.76, 0.19),
new THREE.MeshBasicMaterial({ map: plaqueTexture })
);
plaque.position.set(-0.72, 1.53, 0.637);
kiosk.add(plaque);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function fillRound(ctx, x, y, width, height, radius, fill) {
roundedRect(ctx, x, y, width, height, radius);
ctx.fillStyle = fill;
ctx.fill();
}
function strokeRound(ctx, x, y, width, height, radius, stroke, lineWidth = 2) {
roundedRect(ctx, x, y, width, height, radius);
ctx.strokeStyle = stroke;
ctx.lineWidth = lineWidth;
ctx.stroke();
}
function drawText(
ctx,
text,
x,
y,
size = 24,
weight = 700,
color = "#ffffff",
align = "left"
) {
ctx.fillStyle = color;
ctx.font = `${weight} ${size}px system-ui, -apple-system, sans-serif`;
ctx.textAlign = align;
ctx.textBaseline = "alphabetic";
ctx.fillText(text, x, y);
}
function addRegion(id, x, y, width, height) {
screenRegions.push({ id, x, y, width, height });
}
function drawScreenBase(stepNumber, label) {
screenContext.fillStyle = "#102a32";
screenContext.fillRect(0, 0, 1024, 640);
// Subtle low-poly screen pattern.
screenContext.save();
screenContext.globalAlpha = 0.055;
screenContext.fillStyle = "#b9d5cf";
screenContext.beginPath();
screenContext.moveTo(790, 0);
screenContext.lineTo(1024, 0);
screenContext.lineTo(1024, 215);
screenContext.closePath();
screenContext.fill();
screenContext.beginPath();
screenContext.moveTo(930, 0);
screenContext.lineTo(1024, 0);
screenContext.lineTo(1024, 330);
screenContext.closePath();
screenContext.fill();
screenContext.restore();
fillRound(screenContext, 48, 35, 28, 28, 8, selected().color);
drawText(screenContext, "N", 62, 56, 17, 850, "#102a32", "center");
drawText(screenContext, "NORTHLINE", 88, 55, 19, 850, "#eef6f2");
drawText(screenContext, "SELF SERVICE", 205, 55, 12, 750, "#8ea7a7");
drawText(
screenContext,
`${String(stepNumber).padStart(2, "0")} ${label}`,
972,
55,
13,
800,
"#9db2b1",
"right"
);
screenContext.strokeStyle = "rgba(220,239,233,.12)";
screenContext.lineWidth = 1;
screenContext.beginPath();
screenContext.moveTo(48, 82);
screenContext.lineTo(976, 82);
screenContext.stroke();
}
function drawDestinationCard(destination, index, x, y) {
const isSelected = index === selectedIndex;
const isHovered = hoverRegionId === `destination-${index}`;
const width = 454;
const height = 136;
fillRound(
screenContext,
x,
y,
width,
height,
17,
isSelected ? destination.color : "#193841"
);
if (!isSelected) {
strokeRound(
screenContext,
x,
y,
width,
height,
17,
isHovered ? "#7f999b" : "#2b4c53",
isHovered ? 2 : 1
);
}
const ink = isSelected ? "#102a32" : "#eef6f2";
const secondary = isSelected
? "rgba(16,42,50,.68)"
: "#9eb2b1";
fillRound(
screenContext,
x + 20,
y + 19,
32,
32,
9,
isSelected ? "rgba(16,42,50,.16)" : destination.color
);
drawText(
screenContext,
isSelected ? "✓" : String(index + 1),
x + 36,
y + 42,
18,
850,
isSelected ? "#102a32" : "#102a32",
"center"
);
drawText(
screenContext,
destination.name,
x + 66,
y + 47,
27,
800,
ink
);
drawText(
screenContext,
`${destination.detail} · Platform ${destination.platform}`,
x + 66,
y + 75,
16,
650,
secondary
);
drawText(
screenContext,
`${destination.depart} ${destination.price}`,
x + 66,
y + 109,
16,
800,
ink
);
if (isSelected) {
fillRound(
screenContext,
x + width - 94,
y + 20,
72,
28,
9,
"rgba(16,42,50,.15)"
);
drawText(
screenContext,
"SELECTED",
x + width - 58,
y + 39,
11,
850,
"#102a32",
"center"
);
}
addRegion(`destination-${index}`, x, y, width, height);
}
function drawSelectionScreen() {
drawScreenBase(1, "SELECT");
drawText(screenContext, "Where to?", 48, 132, 48, 850);
destinations.forEach((destination, index) => {
const x = index % 2 === 0 ? 48 : 522;
const y = index < 2 ? 160 : 316;
drawDestinationCard(destination, index, x, y);
});
fillRound(screenContext, 48, 496, 928, 86, 16, selected().color);
drawText(
screenContext,
"REVIEW SELECTION",
512,
549,
22,
850,
"#102a32",
"center"
);
drawText(
screenContext,
"→",
924,
550,
32,
800,
"#102a32",
"center"
);
addRegion("continue", 48, 496, 928, 86);
}
function drawConfirmationScreen() {
const destination = selected();
drawScreenBase(2, "CONFIRM");
drawText(screenContext, "Check your trip", 48, 132, 46, 850);
fillRound(screenContext, 48, 158, 594, 312, 19, destination.color);
drawText(
screenContext,
"DESTINATION",
78,
201,
14,
850,
"rgba(16,42,50,.65)"
);
drawText(
screenContext,
destination.name,
78,
260,
48,
850,
"#102a32"
);
drawText(
screenContext,
`${destination.route} · One-way`,
78,
296,
19,
700,
"rgba(16,42,50,.72)"
);
screenContext.strokeStyle = "rgba(16,42,50,.22)";
screenContext.beginPath();
screenContext.moveTo(78, 328);
screenContext.lineTo(612, 328);
screenContext.stroke();
drawText(
screenContext,
"TICKET CODE",
78,
367,
12,
850,
"rgba(16,42,50,.62)"
);
drawText(
screenContext,
destination.code,
78,
405,
29,
850,
"#102a32"
);
drawText(
screenContext,
"ROUTE",
390,
367,
12,
850,
"rgba(16,42,50,.62)"
);
drawText(
screenContext,
"Central → Coast",
390,
405,
22,
800,
"#102a32"
);
fillRound(screenContext, 666, 158, 310, 312, 19, "#193841");
drawText(screenContext, "DEPARTS", 694, 201, 13, 850, "#8fa7a6");
drawText(screenContext, destination.depart, 694, 251, 43, 850);
drawText(screenContext, "PLATFORM", 694, 303, 13, 850, "#8fa7a6");
drawText(screenContext, destination.platform, 694, 351, 38, 850);
drawText(screenContext, "FARE", 694, 401, 13, 850, "#8fa7a6");
drawText(screenContext, destination.price, 936, 405, 27, 850, "#ffffff", "right");
fillRound(screenContext, 48, 496, 270, 86, 16, "#193841");
drawText(
screenContext,
"EDIT SELECTION",
183,
549,
18,
850,
"#ffffff",
"center"
);
fillRound(screenContext, 340, 496, 636, 86, 16, destination.color);
drawText(
screenContext,
"CONFIRM & PRINT",
658,
549,
22,
850,
"#102a32",
"center"
);
addRegion("edit", 48, 496, 270, 86);
addRegion("confirm", 340, 496, 636, 86);
}
function drawPrintingScreen() {
const destination = selected();
drawScreenBase(3, "PRINT");
drawText(screenContext, "Printing your ticket", 48, 132, 44, 850);
fillRound(screenContext, 48, 158, 514, 312, 19, destination.color);
drawText(
screenContext,
"YOUR DESTINATION",
78,
201,
13,
850,
"rgba(16,42,50,.65)"
);
drawText(
screenContext,
destination.name,
78,
259,
44,
850,
"#102a32"
);
drawText(
screenContext,
`${destination.route} · ${destination.depart}`,
78,
296,
18,
700,
"rgba(16,42,50,.72)"
);
drawText(
screenContext,
"PLATFORM",
78,
365,
12,
850,
"rgba(16,42,50,.62)"
);
drawText(
screenContext,
destination.platform,
78,
409,
38,
850,
"#102a32"
);
drawText(
screenContext,
"FARE",
255,
365,
12,
850,
"rgba(16,42,50,.62)"
);
drawText(
screenContext,
destination.price,
255,
409,
38,
850,
"#102a32"
);
fillRound(screenContext, 586, 158, 390, 312, 19, "#193841");
drawText(
screenContext,
"PLEASE WAIT",
781,
203,
13,
850,
"#91a8a7",
"center"
);
const centerX = 781;
const centerY = 281;
const radius = 68;
screenContext.beginPath();
screenContext.arc(
centerX,
centerY,
radius,
Math.PI / 2,
Math.PI * 1.5
);
screenContext.strokeStyle = "#294a51";
screenContext.lineWidth = 13;
screenContext.stroke();
screenContext.beginPath();
screenContext.arc(
centerX,
centerY,
radius,
Math.PI * 1.5,
Math.PI * 1.5 + Math.PI * 2 * printProgress
);
screenContext.strokeStyle = destination.color;
screenContext.lineWidth = 13;
screenContext.lineCap = "round";
screenContext.stroke();
drawText(
screenContext,
`${Math.round(printProgress * 100)}%`,
centerX,
centerY + 12,
31,
850,
"#ffffff",
"center"
);
drawText(
screenContext,
"Collect your ticket below",
781,
394,
17,
700,
"#91a8a7",
"center"
);
drawText(
screenContext,
"Your destination is printed on the ticket.",
512,
538,
18,
700,
"#9fb3b1",
"center"
);
}
function drawCompleteScreen() {
const destination = selected();
drawScreenBase(3, "READY");
drawText(screenContext, "Ticket ready", 48, 132, 47, 850);
fillRound(screenContext, 48, 158, 574, 312, 19, destination.color);
drawText(
screenContext,
"DESTINATION",
78,
201,
13,
850,
"rgba(16,42,50,.65)"
);
drawText(
screenContext,
destination.name,
78,
260,
47,
850,
"#102a32"
);
drawText(
screenContext,
`${destination.depart} · Platform ${destination.platform}`,
78,
299,
19,
700,
"rgba(16,42,50,.72)"
);
drawText(
screenContext,
"Your ticket has been printed.",
78,
393,
20,
800,
"#102a32"
);
drawText(
screenContext,
"Please collect it from the slot.",
78,
424,
17,
650,
"rgba(16,42,50,.72)"
);
fillRound(screenContext, 646, 158, 330, 312, 19, "#193841");
drawText(
screenContext,
"TICKET",
811,
213,
13,
850,
"#91a8a7",
"center"
);
drawText(
screenContext,
destination.code,
811,
279,
45,
850,
destination.color,
"center"
);
drawText(
screenContext,
destination.price,
811,
335,
27,
800,
"#ffffff",
"center"
);
drawText(
screenContext,
"ONE WAY",
811,
405,
14,
850,
"#91a8a7",
"center"
);
fillRound(screenContext, 48, 496, 928, 86, 16, "#193841");
drawText(
screenContext,
"START ANOTHER TICKET",
512,
549,
20,
850,
"#ffffff",
"center"
);
addRegion("new-ticket", 48, 496, 928, 86);
}
function drawScreen() {
screenRegions = [];
screenContext.clearRect(0, 0, 1024, 640);
if (state === "selection") drawSelectionScreen();
if (state === "confirmation") drawConfirmationScreen();
if (state === "printing") drawPrintingScreen();
if (state === "complete") drawCompleteScreen();
screenTexture.needsUpdate = true;
}
function drawTicketTexture() {
const destination = selected();
const ctx = ticketContext;
ctx.fillStyle = "#fffdf6";
ctx.fillRect(0, 0, 900, 480);
// Shared destination color.
ctx.fillStyle = destination.color;
ctx.fillRect(0, 0, 32, 480);
ctx.fillStyle = "#173740";
ctx.font = "850 27px system-ui";
ctx.textAlign = "left";
ctx.fillText("NORTHLINE TRANSIT", 65, 58);
ctx.fillStyle = "#718586";
ctx.font = "750 16px system-ui";
ctx.fillText("ONE WAY · TODAY", 835, 55);
ctx.strokeStyle = "#dce1da";
ctx.beginPath();
ctx.moveTo(64, 83);
ctx.lineTo(838, 83);
ctx.stroke();
ctx.fillStyle = "#748687";
ctx.font = "800 15px system-ui";
ctx.fillText("DESTINATION", 65, 125);
ctx.fillStyle = "#102a32";
ctx.font = "850 48px system-ui";
ctx.fillText(destination.name, 65, 183);
ctx.fillStyle = "#6e8182";
ctx.font = "700 20px system-ui";
ctx.fillText(`${destination.route} · Central Station`, 65, 220);
ctx.fillStyle = "#173740";
ctx.font = "800 17px system-ui";
ctx.fillText("FROM", 65, 285);
ctx.fillText("DEPARTS", 270, 285);
ctx.fillText("PLATFORM", 475, 285);
ctx.fillText("FARE", 660, 285);
ctx.font = "850 24px system-ui";
ctx.fillText("Central", 65, 320);
ctx.fillText(destination.depart, 270, 320);
ctx.fillText(destination.platform, 475, 320);
ctx.fillText(destination.price, 660, 320);
ctx.strokeStyle = "#dce1da";
ctx.beginPath();
ctx.moveTo(64, 357);
ctx.lineTo(838, 357);
ctx.stroke();
ctx.fillStyle = "#748687";
ctx.font = "750 14px system-ui";
ctx.fillText("TICKET CODE", 65, 397);
ctx.fillText("VALID UNTIL", 265, 397);
ctx.fillStyle = "#102a32";
ctx.font = "850 18px system-ui";
ctx.fillText(`${destination.code}-${selectedIndex + 1}7`, 65, 428);
ctx.fillText("TODAY · 23:59", 265, 428);
// Deterministic block-style ticket code.
const qrX = 720;
const qrY = 378;
const qrSize = 13;
const pattern = [
1, 1, 1, 0, 1, 0, 1, 1, 1,
1, 0, 1, 0, 0, 1, 1, 0, 1,
1, 1, 1, 0, 1, 1, 1, 1, 1,
0, 0, 1, 1, 0, 1, 0, 0, 0,
1, 0, 1, 0, 1, 1, 1, 0, 1,
1, 1, 1, 1, 0, 0, 1, 0, 1,
1, 0, 1, 1, 1, 0, 1, 1, 1,
1, 1, 0, 0, 1, 0, 1, 0, 1,
1, 1, 1, 1, 1, 0, 1, 1, 1
];
for (let row = 0; row < 9; row++) {
for (let col = 0; col < 9; col++) {
if (pattern[row * 9 + col]) {
ctx.fillStyle = "#102a32";
ctx.fillRect(
qrX + col * qrSize,
qrY + row * qrSize,
qrSize - 1,
qrSize - 1
);
}
}
}
ticketTexture.needsUpdate = true;
}
drawTicketTexture();
// -------------------------------------------------------------------------
// Accessible HTML controls and state management
// -------------------------------------------------------------------------
const destinationGrid = document.getElementById("destinationGrid");
const panel = document.getElementById("panel");
const panelTitle = document.getElementById("panelTitle");
const panelIntro = document.getElementById("panelIntro");
const stateLabel = document.getElementById("stateLabel");
const routeMeta = document.getElementById("routeMeta");
const routeName = document.getElementById("routeName");
const routeSubtitle = document.getElementById("routeSubtitle");
const departTime = document.getElementById("departTime");
const platformValue = document.getElementById("platform");
const price = document.getElementById("price");
const panelAction = document.getElementById("panelAction");
const backButton = document.getElementById("backButton");
const progressFill = document.getElementById("progressFill");
const topStatus = document.getElementById("topStatus");
const liveRegion = document.getElementById("liveRegion");
destinations.forEach((destination, index) => {
const button = document.createElement("button");
button.className = "destination-button";
button.type = "button";
button.style.setProperty("--destination-color", destination.color);
button.innerHTML = `
<strong>${destination.name}</strong>
<span>${destination.code} · ${destination.platform}</span>
`;
button.addEventListener("click", () => {
if (state === "printing") return;
if (state !== "selection") goToState("selection");
selectDestination(index);
});
destinationGrid.appendChild(button);
});
function selectDestination(index) {
selectedIndex = index;
hoverRegionId = null;
drawTicketTexture();
beaconMaterial.color.set(selected().color);
beaconMaterial.emissive.set(selected().color);
updatePanel();
drawScreen();
announce(`${selected().name} selected.`);
}
function updatePanel() {
const destination = selected();
document.documentElement.style.setProperty("--accent", destination.color);
routeMeta.textContent = `Central Station → ${destination.route}`;
routeName.textContent = destination.name;
routeSubtitle.textContent = `${destination.detail} · One-way ticket`;
departTime.textContent = destination.depart;
platformValue.textContent = destination.platform;
price.textContent = destination.price;
const destinationButtons = [
...destinationGrid.querySelectorAll(".destination-button")
];
destinationButtons.forEach((button, index) => {
button.classList.toggle("active", index === selectedIndex);
button.setAttribute("aria-pressed", String(index === selectedIndex));
button.disabled = state === "printing";
});
const stepOrder = ["selection", "confirmation", "printing"];
const currentStep = state === "complete" ? 2 : stepOrder.indexOf(state);
document.querySelectorAll(".step").forEach((step) => {
const index = stepOrder.indexOf(step.dataset.step);
step.classList.toggle("done", index < currentStep);
step.classList.toggle("current", index === currentStep);
});
if (state === "selection") {
panelTitle.textContent = "Where to next?";
panelIntro.textContent =
"Choose a destination, check the details, then print your ticket.";
stateLabel.textContent = "01 · Selection";
panelAction.textContent = "Review selection";
panelAction.disabled = false;
backButton.hidden = true;
topStatus.textContent = "Choose a destination";
progressFill.style.width = "25%";
}
if (state === "confirmation") {
panelTitle.textContent = "Ready to go?";
panelIntro.textContent =
"Confirm the destination, departure, platform, and fare.";
stateLabel.textContent = "02 · Confirmation";
panelAction.textContent = "Confirm & print";
panelAction.disabled = false;
backButton.hidden = false;
topStatus.textContent = "Review your ticket";
progressFill.style.width = "60%";
}
if (state === "printing") {
panelTitle.textContent = "Making your ticket";
panelIntro.textContent =
"Keep your place while the ticket is printed below the screen.";
stateLabel.textContent = "03 · Printing";
panelAction.textContent = "Printing…";
panelAction.disabled = true;
backButton.hidden = true;
topStatus.textContent = "Printer active";
}
if (state === "complete") {
panelTitle.textContent = "Have a good trip!";
panelIntro.textContent =
"Your ticket is ready. Collect it from the printer slot.";
stateLabel.textContent = "03 · Ticket ready";
panelAction.textContent = "Start another ticket";
panelAction.disabled = false;
backButton.hidden = true;
topStatus.textContent = "Ticket ready";
progressFill.style.width = "100%";
}
panel.classList.remove("pulse");
void panel.offsetWidth;
panel.classList.add("pulse");
}
function goToState(nextState) {
state = nextState;
transitionStart = performance.now();
hoverRegionId = null;
if (state === "selection" || state === "confirmation") {
ticketPivot.visible = false;
ticketPivot.scale.y = 0.02;
printProgress = 0;
}
if (state === "printing") {
printProgress = 0;
printStart = performance.now();
ticketPivot.visible = true;
ticketPivot.scale.y = 0.02;
announce(`Printing a ticket for ${selected().name}.`);
}
if (state === "complete") {
printProgress = 1;
ticketPivot.scale.y = 1;
announce(`Your ${selected().name} ticket is ready.`);
}
updatePanel();
drawScreen();
}
function announce(message) {
liveRegion.textContent = "";
requestAnimationFrame(() => {
liveRegion.textContent = message;
});
}
panelAction.addEventListener("click", () => {
if (state === "selection") goToState("confirmation");
else if (state === "confirmation") goToState("printing");
else if (state === "complete") goToState("selection");
});
backButton.addEventListener("click", () => {
if (state === "confirmation") goToState("selection");
});
// -------------------------------------------------------------------------
// Screen picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function regionAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(screenMesh, false)[0];
if (!hit || !hit.uv) return null;
const x = hit.uv.x * screenCanvas.width;
const y = (1 - hit.uv.y) * screenCanvas.height;
return (
screenRegions.find(
(region) =>
x >= region.x &&
x <= region.x + region.width &&
y >= region.y &&
y <= region.y + region.height
) || null
);
}
function activateRegion(region) {
if (!region) return;
if (region.id.startsWith("destination-")) {
const index = Number(region.id.split("-")[1]);
selectDestination(index);
}
if (region.id === "continue") goToState("confirmation");
if (region.id === "edit") goToState("selection");
if (region.id === "confirm") goToState("printing");
if (region.id === "new-ticket") goToState("selection");
}
// -------------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
const drag = {
active: false,
moved: false,
lastX: 0,
lastY: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
drag.active = true;
drag.moved = false;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (drag.active) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
if (Math.abs(event.clientX - drag.lastX) + Math.abs(event.clientY - drag.lastY) > 2) {
drag.moved = true;
}
cameraGoal.theta -= dx * 0.006;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.005,
0.62,
1.42
);
drag.lastX = event.clientX;
drag.lastY = event.clientY;
return;
}
const region = regionAt(event.clientX, event.clientY);
const nextHoverId = region?.id || null;
renderer.domElement.style.cursor = nextHoverId ? "pointer" : "grab";
if (nextHoverId !== hoverRegionId) {
hoverRegionId = nextHoverId;
if (state !== "printing") drawScreen();
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (drag.active && !drag.moved) {
activateRegion(regionAt(event.clientX, event.clientY));
}
drag.active = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius + event.deltaY * 0.006,
5.4,
12
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
if (["1", "2", "3", "4"].includes(event.key)) {
if (state !== "printing") {
if (state !== "selection") goToState("selection");
selectDestination(Number(event.key) - 1);
}
}
if (event.key === "Enter") {
panelAction.click();
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
// Damped orbit camera.
const damping = 1 - Math.exp(-delta * 9);
cameraCurrent.theta += (cameraGoal.theta - cameraCurrent.theta) * damping;
cameraCurrent.phi += (cameraGoal.phi - cameraCurrent.phi) * damping;
cameraCurrent.radius += (cameraGoal.radius - cameraCurrent.radius) * damping;
const sinPhi = Math.sin(cameraCurrent.phi);
camera.position.set(
cameraTarget.x +
cameraCurrent.radius * sinPhi * Math.sin(cameraCurrent.theta),
cameraTarget.y + cameraCurrent.radius * Math.cos(cameraCurrent.phi),
cameraTarget.z +
cameraCurrent.radius * sinPhi * Math.cos(cameraCurrent.theta)
);
camera.lookAt(cameraTarget);
// Small state-change squash/pulse on the kiosk.
const transitionTime = (now - transitionStart) / 480;
const transitionPulse =
transitionTime >= 0 && transitionTime < 1
? Math.sin(transitionTime * Math.PI) * 0.012
: 0;
kiosk.scale.setScalar(1 + transitionPulse);
if (state === "printing") {
const elapsed = (now - printStart) / 1000;
printProgress = THREE.MathUtils.clamp(elapsed / 3.4, 0, 1);
const eased = easeOutCubic(printProgress);
ticketPivot.scale.y = Math.max(0.02, eased);
ticketPivot.rotation.z =
-0.018 * Math.sin(printProgress * Math.PI) +
Math.sin(now * 0.002) * 0.0015;
progressFill.style.width = `${Math.round(printProgress * 100)}%`;
if (now - lastPrintDraw > 45) {
drawScreen();
lastPrintDraw = now;
}
if (elapsed >= 3.4) {
goToState("complete");
}
}
if (state === "complete") {
ticketPivot.position.y = 1.22 + Math.sin(now * 0.0018) * 0.008;
}
// Status lamp color and intensity.
const stateColor =
state === "printing"
? selected().color
: state === "complete"
? "#42a36f"
: selected().color;
lampMaterial.color.set(stateColor);
lampMaterial.emissive.set(stateColor);
lampMaterial.emissiveIntensity =
state === "printing" ? 0.65 + Math.sin(now * 0.018) * 0.45 : 0.72;
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updatePanel();
drawScreen();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```