Prompt specification
Build or customize the Three.js 3D scene "Ceremony-order coordination 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: Ceremony-order coordination puzzle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ceremony-order-coordination-puzzle-x3872
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a graduation ceremony and recipient order. Create a fictional recognition event with a program sequence and misplaced certificates; users match recipients and restore order before each participant reaches the presentation point. Low-poly.
Working Three.js Starter (ceremony-order-coordination-puzzle-x3872):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Order of Honours — Interactive Graduation Ceremony</title>
<style>
:root {
--ink: #10252d;
--deep: #071b23;
--panel: rgba(9, 32, 41, 0.91);
--panel-light: rgba(18, 50, 59, 0.88);
--line: rgba(255, 255, 255, 0.12);
--cream: #fff4d7;
--muted: #a9c1c5;
--gold: #efba55;
--mint: #64d8c2;
--coral: #ff816f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--deep);
color: var(--cream);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 35%, rgba(2, 13, 18, 0.45) 100%),
linear-gradient(180deg, rgba(3, 15, 21, 0.38), transparent 25%, transparent 75%, rgba(3, 15, 21, 0.4));
}
.topbar {
position: fixed;
z-index: 10;
top: 16px;
left: 18px;
right: 18px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
gap: 16px;
}
.brand,
.top-actions,
.stats {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
padding: 10px 14px 10px 10px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(6, 26, 34, 0.77);
backdrop-filter: blur(14px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
color: var(--deep);
background: var(--gold);
border-radius: 12px 12px 12px 4px;
font-weight: 900;
letter-spacing: -0.06em;
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.04em;
}
.brand small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.stats {
display: flex;
align-items: center;
gap: 6px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(6, 26, 34, 0.79);
backdrop-filter: blur(14px);
}
.stat {
min-width: 86px;
padding: 7px 10px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
}
.stat span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 2px;
color: var(--cream);
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.icon-button {
height: 42px;
padding: 0 13px;
color: var(--cream);
background: rgba(6, 26, 34, 0.84);
border: 1px solid var(--line);
border-radius: 12px;
cursor: pointer;
transition: 160ms ease;
}
.icon-button:hover {
border-color: rgba(239, 186, 85, 0.6);
background: rgba(239, 186, 85, 0.12);
}
.panel {
position: fixed;
z-index: 9;
top: 92px;
bottom: 18px;
width: 310px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}
#programPanel {
left: 18px;
}
#certificatePanel {
right: 18px;
width: 340px;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 18px 18px 13px;
border-bottom: 1px solid var(--line);
}
.panel-head h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-head span {
color: var(--muted);
font-size: 10px;
}
.program-list {
padding: 10px;
}
.program-row {
position: relative;
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
min-height: 66px;
margin: 6px 0;
padding: 10px;
border: 1px solid transparent;
border-radius: 13px;
cursor: pointer;
transition: 160ms ease;
}
.program-row:hover {
background: rgba(255, 255, 255, 0.045);
}
.program-row.current {
background: rgba(239, 186, 85, 0.1);
border-color: rgba(239, 186, 85, 0.42);
}
.program-row.selected {
background: rgba(100, 216, 194, 0.11);
border-color: rgba(100, 216, 194, 0.55);
}
.program-row.assigned {
opacity: 0.62;
}
.program-number {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
.current .program-number {
color: var(--deep);
background: var(--gold);
border-color: var(--gold);
}
.participant-name {
display: block;
font-size: 13px;
font-weight: 750;
}
.participant-award {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.row-status {
display: flex;
align-items: center;
gap: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.row-status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #60777d;
}
.current .row-status::before {
background: var(--gold);
box-shadow: 0 0 12px var(--gold);
}
.assigned .row-status::before {
background: var(--mint);
}
.timer-box {
position: absolute;
left: 10px;
right: 10px;
bottom: 10px;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.045);
}
.timer-top {
display: flex;
align-items: baseline;
justify-content: space-between;
}
.timer-top span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#countdown {
color: var(--cream);
font-size: 18px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.progress-track {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
#progressFill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--gold), var(--coral));
transition: width 100ms linear;
}
.certificate-list {
max-height: calc(100vh - 225px);
overflow: auto;
padding: 11px;
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
.certificate-card {
position: relative;
width: 100%;
min-height: 104px;
margin: 8px 0;
padding: 13px 13px 12px 16px;
overflow: hidden;
color: var(--ink);
text-align: left;
background:
radial-gradient(circle at 100% 0%, rgba(239, 186, 85, 0.26), transparent 32%),
#f4e7c6;
border: 1px solid rgba(255, 255, 255, 0.32);
border-radius: 14px;
box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
cursor: pointer;
transition: 160ms ease;
}
.certificate-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 5px;
background: var(--certificate-color, var(--gold));
}
.certificate-card:hover {
transform: translateY(-2px);
box-shadow: 0 15px 28px rgba(0, 0, 0, 0.2);
}
.certificate-card.selected {
outline: 3px solid var(--mint);
outline-offset: 2px;
transform: translateY(-2px);
}
.certificate-card.assigned {
cursor: default;
opacity: 0.55;
filter: saturate(0.55);
}
.certificate-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.certificate-code {
color: #6e6455;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.misplaced-tag {
padding: 3px 6px;
color: #843f35;
background: rgba(255, 129, 111, 0.18);
border-radius: 99px;
font-size: 7px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.certificate-card.assigned .misplaced-tag {
color: #286b60;
background: rgba(100, 216, 194, 0.22);
}
.certificate-award {
margin-top: 8px;
font-family: Georgia, serif;
font-size: 16px;
font-weight: 800;
}
.certificate-recipient {
margin-top: 5px;
color: #5d564a;
font-size: 10px;
}
.certificate-recipient strong {
color: var(--ink);
}
.certificate-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
padding-top: 8px;
border-top: 1px solid rgba(52, 45, 35, 0.12);
color: #756a58;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.seal {
position: absolute;
right: 12px;
bottom: 10px;
width: 26px;
height: 26px;
display: grid;
place-items: center;
color: var(--cream);
background: var(--certificate-color, var(--gold));
border: 2px dotted rgba(255, 255, 255, 0.56);
border-radius: 50%;
font-size: 9px;
font-weight: 900;
}
.instructions {
position: absolute;
left: 10px;
right: 10px;
bottom: 10px;
padding: 11px 12px;
color: var(--muted);
background: var(--panel-light);
border: 1px solid var(--line);
border-radius: 14px;
font-size: 9px;
line-height: 1.55;
}
.instructions strong {
color: var(--cream);
}
.key {
display: inline-grid;
min-width: 18px;
height: 18px;
margin-right: 5px;
place-items: center;
color: var(--deep);
background: var(--gold);
border-radius: 5px;
font-weight: 900;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 27px;
max-width: min(480px, calc(100vw - 40px));
padding: 12px 17px;
color: var(--cream);
background: rgba(8, 30, 38, 0.94);
border: 1px solid var(--line);
border-radius: 13px;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
font-size: 12px;
font-weight: 700;
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, 12px);
transition: 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.success {
border-color: rgba(100, 216, 194, 0.65);
background: rgba(17, 65, 62, 0.96);
}
#toast.error {
border-color: rgba(255, 129, 111, 0.68);
background: rgba(77, 37, 37, 0.97);
}
.scene-help {
position: fixed;
z-index: 8;
left: 50%;
bottom: 16px;
padding: 8px 12px;
color: rgba(255, 244, 215, 0.75);
background: rgba(5, 21, 28, 0.58);
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 99px;
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
.modal {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(3, 14, 19, 0.58);
backdrop-filter: blur(9px);
transition: 220ms ease;
}
.modal.hidden {
visibility: hidden;
opacity: 0;
pointer-events: none;
}
.modal-card {
width: min(540px, 100%);
padding: 34px;
text-align: center;
background:
radial-gradient(circle at 50% 0%, rgba(239, 186, 85, 0.15), transparent 35%),
#0a2731;
border: 1px solid rgba(239, 186, 85, 0.36);
border-radius: 24px;
box-shadow: 0 35px 100px rgba(0, 0, 0, 0.5);
}
.eyebrow {
color: var(--gold);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.modal-card h1 {
margin: 10px 0 12px;
font-family: Georgia, serif;
font-size: clamp(30px, 6vw, 47px);
line-height: 1;
}
.modal-card > p {
margin: 0 auto;
max-width: 420px;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.rules {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
margin: 24px 0;
}
.rule {
padding: 13px 8px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.rule b {
display: block;
margin-bottom: 4px;
color: var(--cream);
font-size: 11px;
}
.primary-button {
min-width: 190px;
padding: 13px 22px;
color: var(--deep);
background: var(--gold);
border: 0;
border-radius: 12px;
box-shadow: 0 10px 24px rgba(239, 186, 85, 0.18);
cursor: pointer;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 160ms ease;
}
.primary-button:hover {
transform: translateY(-2px);
background: #ffd47b;
}
.completion-stats {
display: flex;
justify-content: center;
gap: 12px;
margin: 25px 0;
}
.completion-stat {
min-width: 130px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.04);
}
.completion-stat span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.completion-stat strong {
display: block;
margin-top: 4px;
font-size: 24px;
}
@media (max-width: 1000px) {
.panel {
width: 270px;
}
#certificatePanel {
width: 290px;
}
.brand small {
display: none;
}
.stat {
min-width: 68px;
}
}
@media (max-width: 760px) {
.topbar {
top: 8px;
left: 8px;
right: 8px;
}
.brand {
padding: 7px;
}
.brand-copy,
#viewBtn,
.stat.score-stat {
display: none;
}
.brand-mark {
width: 38px;
height: 38px;
}
.stats {
padding: 4px;
}
.stat {
min-width: 58px;
padding: 5px 8px;
}
.panel {
top: auto;
bottom: 8px;
width: calc(50% - 12px);
max-height: 43vh;
border-radius: 15px;
}
#programPanel {
left: 8px;
}
#certificatePanel {
right: 8px;
}
.panel-head {
padding: 12px;
}
.program-list {
max-height: calc(43vh - 120px);
overflow: auto;
}
.program-row {
min-height: 56px;
}
.timer-box {
padding: 8px 10px;
}
.certificate-list {
max-height: calc(43vh - 72px);
}
.certificate-card {
min-height: 91px;
}
.instructions,
.scene-help {
display: none;
}
#toast {
bottom: 45vh;
}
.rules {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark">OH</div>
<div class="brand-copy">
<strong>The Order of Honours</strong>
<small>Northstar University · Recognition Assembly</small>
</div>
</div>
<div class="top-actions">
<div class="stats">
<div class="stat">
<span>Order</span>
<strong id="orderStat">0 / 5</strong>
</div>
<div class="stat score-stat">
<span>Score</span>
<strong id="scoreStat">1000</strong>
</div>
<div class="stat">
<span>Approaching</span>
<strong id="activeStat">—</strong>
</div>
</div>
<button id="viewBtn" class="icon-button" title="Reset camera view">Reset view</button>
<button id="resetBtn" class="icon-button">Restart</button>
</div>
</header>
<aside id="programPanel" class="panel">
<div class="panel-head">
<h2>Live Program</h2>
<span>Presentation order</span>
</div>
<div id="programList" class="program-list"></div>
<div class="timer-box">
<div class="timer-top">
<span id="timerLabel">Time to presentation</span>
<strong id="countdown">00:22</strong>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
</div>
</aside>
<aside id="certificatePanel" class="panel">
<div class="panel-head">
<h2>Misplaced Certificates</h2>
<span id="certificateCount">5 unassigned</span>
</div>
<div id="certificateList" class="certificate-list"></div>
<div class="instructions">
<span class="key">1</span>Select a certificate.<br />
<span class="key">2</span>Select its named recipient in the program or in the scene.<br />
The highlighted recipient must be next in the live program.
</div>
</aside>
<div id="toast" role="status" aria-live="polite"></div>
<div class="scene-help">Drag to orbit · Scroll to zoom · Click a graduate · R resets the camera</div>
<div id="introOverlay" class="modal">
<div class="modal-card">
<div class="eyebrow">A Fictional Recognition Event</div>
<h1>The Order of Honours</h1>
<p>
The certificates have arrived out of order. Restore the presentation sequence before
each graduate reaches the podium.
</p>
<div class="rules">
<div class="rule"><b>1 · Choose</b>Select a certificate from the shuffled tray.</div>
<div class="rule"><b>2 · Match</b>Click its named recipient in the program or scene.</div>
<div class="rule"><b>3 · Present</b>The live recipient must be next in the program.</div>
</div>
<button id="beginBtn" class="primary-button">Begin ceremony</button>
</div>
</div>
<div id="completionOverlay" class="modal hidden">
<div class="modal-card">
<div class="eyebrow">Ceremony Complete</div>
<h1>Order Restored</h1>
<p>Every graduate received the right certificate at the right moment.</p>
<div class="completion-stats">
<div class="completion-stat">
<span>Final score</span>
<strong id="completionScore">1000</strong>
</div>
<div class="completion-stat">
<span>Corrections</span>
<strong id="completionErrors">0</strong>
</div>
</div>
<button id="againBtn" class="primary-button">Run another ceremony</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const programList = document.querySelector("#programList");
const certificateList = document.querySelector("#certificateList");
const toastElement = document.querySelector("#toast");
const introOverlay = document.querySelector("#introOverlay");
const completionOverlay = document.querySelector("#completionOverlay");
const program = [
{
name: "Maya Chen",
award: "Academic Excellence",
color: 0xefba55,
initials: "MC",
skin: 0xd9a06c
},
{
name: "Idris Bell",
award: "Creative Arts",
color: 0xff816f,
initials: "IB",
skin: 0x7d4d32
},
{
name: "Sofia Reyes",
award: "Community Impact",
color: 0x64d8c2,
initials: "SR",
skin: 0xc98457
},
{
name: "Theo Park",
award: "Innovation Prize",
color: 0x9f91ff,
initials: "TP",
skin: 0xe3b38f
},
{
name: "Amara Okafor",
award: "Leadership Medal",
color: 0xf28bc2,
initials: "AO",
skin: 0x8a5638
}
];
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b2631);
scene.fog = new THREE.Fog(0x0b2631, 17, 35);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const world = new THREE.Group();
scene.add(world);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
flatShading: true,
...options
});
}
function addMesh(geometry, material, x, y, z, parent = world) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, options = {}) {
const {
width = 512,
height = 100,
background = "rgba(8, 28, 35, 0.88)",
foreground = "#fff4d7",
border = "rgba(255,255,255,0.18)",
font = "700 31px system-ui",
scale = [2.8, 0.55, 1]
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, width - 4, height - 4);
ctx.fillStyle = foreground;
ctx.font = font;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
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(...scale);
sprite.renderOrder = 8;
return sprite;
}
const materials = {
ground: standardMaterial(0x173f43),
grass: standardMaterial(0x28564d),
navy: standardMaterial(0x102b40),
navyLight: standardMaterial(0x1d4358),
gold: standardMaterial(0xdca94c, { metalness: 0.18, roughness: 0.5 }),
cream: standardMaterial(0xf1dfb6),
wood: standardMaterial(0x744a35),
black: standardMaterial(0x14202a),
white: standardMaterial(0xe8eee4),
skin: standardMaterial(0xc98d65)
};
// Lighting
scene.add(new THREE.HemisphereLight(0xc7ecff, 0x304135, 1.65));
const keyLight = new THREE.DirectionalLight(0xffe5b6, 3.1);
keyLight.position.set(7, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x62d9d0, 1.25);
rimLight.position.set(-8, 6, -7);
scene.add(rimLight);
const podiumLight = new THREE.PointLight(0xffb75c, 10, 11, 2);
podiumLight.position.set(-0.5, 3, -2.5);
scene.add(podiumLight);
// Ground and ceremonial setting
const ground = addMesh(
new THREE.PlaneGeometry(60, 60),
materials.ground,
0,
-0.07,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const lawn = addMesh(
new THREE.CircleGeometry(10, 16),
materials.grass,
-6.5,
-0.045,
-2.5
);
lawn.rotation.x = -Math.PI / 2;
lawn.scale.set(1.2, 1, 0.8);
lawn.castShadow = false;
// Carpet
addMesh(
new THREE.BoxGeometry(2.35, 0.08, 10.8),
standardMaterial(0x8f3342),
1.05,
0.005,
2.05
);
for (const x of [-0.16, 2.26]) {
addMesh(
new THREE.BoxGeometry(0.075, 0.095, 10.8),
materials.gold,
x,
0.015,
2.05
);
}
// Stage
addMesh(new THREE.BoxGeometry(9.2, 0.65, 5.1), materials.navy, -1, 0.325, -4.45);
addMesh(new THREE.BoxGeometry(9.35, 0.12, 5.25), materials.navyLight, -1, 0.69, -4.45);
addMesh(new THREE.BoxGeometry(8.9, 0.42, 0.13), materials.gold, -1, 0.39, -1.92);
// Backdrop
addMesh(new THREE.BoxGeometry(8.7, 2.05, 0.18), materials.navy, -1, 2.34, -6.85);
addMesh(new THREE.BoxGeometry(8.95, 0.1, 0.24), materials.gold, -1, 3.39, -6.8);
const banner = makeLabel("ORDER OF RECOGNITION", {
width: 1024,
height: 160,
background: "rgba(13, 43, 55, 0.96)",
foreground: "#f8e6b7",
border: "rgba(239,186,85,0.72)",
font: "800 55px Georgia",
scale: [7.65, 1.2, 1]
});
banner.position.set(-1, 2.36, -6.68);
world.add(banner);
const northstarLabel = makeLabel("NORTHSTAR UNIVERSITY", {
width: 640,
height: 90,
background: "rgba(7, 27, 35, 0.88)",
foreground: "#8ee3d4",
border: "rgba(100,216,194,0.42)",
font: "800 31px system-ui",
scale: [3.6, 0.51, 1]
});
northstarLabel.position.set(-1, 4.04, -6.65);
world.add(northstarLabel);
// Podium
const podium = new THREE.Group();
world.add(podium);
podium.position.set(-0.75, 0.75, -3.55);
addMesh(
new THREE.BoxGeometry(1.15, 1.55, 0.88),
materials.wood,
0,
0.78,
0,
podium
);
addMesh(
new THREE.BoxGeometry(1.35, 0.13, 1.03),
materials.gold,
0,
1.6,
0,
podium
);
const podiumLabel = makeLabel("PRESENTATION POINT", {
width: 640,
height: 110,
background: "rgba(116, 74, 53, 0.96)",
foreground: "#f8e6b7",
border: "rgba(239,186,85,0.65)",
font: "800 34px system-ui",
scale: [1.65, 0.34, 1]
});
podiumLabel.position.set(0, 0.92, 0.48);
podium.add(podiumLabel);
// Microphone
addMesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.85, 6),
materials.black,
0.25,
2.02,
-0.15,
podium
).rotation.z = -0.22;
addMesh(
new THREE.SphereGeometry(0.09, 8, 6),
materials.black,
0.35,
2.41,
-0.15,
podium
);
// Stage columns and bunting
for (const x of [-5.2, 3.2]) {
addMesh(
new THREE.CylinderGeometry(0.11, 0.16, 3.8, 8),
materials.gold,
x,
2.6,
-6.55
);
}
const buntingColors = [0xefba55, 0x64d8c2, 0xff816f, 0xf28bc2, 0x9f91ff];
for (let i = 0; i < 12; i++) {
const x = -4.8 + i * 0.69;
const y = 3.2 - Math.sin((i / 11) * Math.PI) * 0.23;
const flag = addMesh(
new THREE.ConeGeometry(0.21, 0.38, 3),
standardMaterial(buntingColors[i % buntingColors.length]),
x,
y,
-6.37
);
flag.rotation.z = Math.PI;
}
// Low-poly trees
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
world.add(tree);
addMesh(
new THREE.CylinderGeometry(0.16, 0.24, 1.35, 6),
materials.wood,
0,
0.67,
0,
tree
);
const foliage = standardMaterial(0x356657);
addMesh(new THREE.ConeGeometry(0.9, 1.65, 7), foliage, 0, 1.65, 0, tree);
addMesh(new THREE.ConeGeometry(0.68, 1.35, 7), foliage, 0, 2.35, 0, tree);
addMesh(new THREE.ConeGeometry(0.42, 1.1, 7), foliage, 0, 3.02, 0, tree);
}
makeTree(-8.3, -4.8, 1.25);
makeTree(-7.2, -6.2, 0.9);
makeTree(8.1, -5.2, 1.15);
makeTree(8.8, 2.8, 0.82);
makeTree(-9.3, 4.6, 0.9);
// Simple audience figures
function makeSeatedPerson(x, z, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
addMesh(new THREE.BoxGeometry(0.65, 0.12, 0.65), materials.navy, 0, 0.38, 0, group);
addMesh(new THREE.BoxGeometry(0.65, 0.7, 0.12), materials.navy, 0, 0.73, -0.28, group);
addMesh(new THREE.CylinderGeometry(0.23, 0.31, 0.58, 6), standardMaterial(color), 0, 0.76, 0.03, group);
addMesh(new THREE.DodecahedronGeometry(0.24, 0), materials.skin, 0, 1.25, 0.03, group);
}
const audienceColors = [0x36566a, 0x78495b, 0x3f6f69, 0x625681, 0x805f3f];
for (let row = 0; row < 2; row++) {
for (let i = 0; i < 4; i++) {
makeSeatedPerson(
-7.1 + i * 1.15,
3.7 - row * 1.25,
audienceColors[(i + row) % audienceColors.length],
-0.55
);
}
}
// Official standing behind the podium
const official = new THREE.Group();
official.position.set(-0.95, 0.76, -5.25);
world.add(official);
addMesh(new THREE.CylinderGeometry(0.26, 0.38, 0.9, 6), materials.navy, 0, 0.75, 0, official);
addMesh(new THREE.DodecahedronGeometry(0.25, 0), materials.skin, 0, 1.46, 0, official);
addMesh(new THREE.CylinderGeometry(0.27, 0.27, 0.08, 8), materials.black, 0, 1.69, 0, official);
// Certificate table and physical misplaced stack
addMesh(new THREE.BoxGeometry(2.05, 0.16, 1.25), materials.wood, 6.65, 1.25, 5.6);
for (const x of [5.85, 7.45]) {
addMesh(new THREE.BoxGeometry(0.12, 1.2, 0.12), materials.wood, x, 0.6, 5.6);
}
for (let i = 0; i < 5; i++) {
const sheet = addMesh(
new THREE.BoxGeometry(0.9, 0.055, 0.62),
materials.cream,
6.35 + (i % 2) * 0.28,
1.38 + i * 0.065,
5.55 + (i % 3) * 0.08
);
sheet.rotation.y = (i - 2) * 0.08;
addMesh(
new THREE.BoxGeometry(0.12, 0.065, 0.64),
standardMaterial(buntingColors[i]),
6.35 + (i % 2) * 0.28,
1.39 + i * 0.065,
5.55 + (i % 3) * 0.08
);
}
// Recipient construction
function makeParticipant(data, index) {
const group = new THREE.Group();
world.add(group);
const accent = standardMaterial(data.color);
const darkAccent = standardMaterial(new THREE.Color(data.color).multiplyScalar(0.66));
const skin = standardMaterial(data.skin);
const white = standardMaterial(0xf4efe0);
addMesh(new THREE.CylinderGeometry(0.26, 0.39, 0.87, 6), accent, 0, 0.94, 0, group);
addMesh(new THREE.CylinderGeometry(0.29, 0.29, 0.11, 6), darkAccent, 0, 1.39, 0, group);
addMesh(new THREE.DodecahedronGeometry(0.25, 0), skin, 0, 1.68, 0, group);
addMesh(new THREE.BoxGeometry(0.61, 0.08, 0.61), materials.black, 0, 1.91, 0, group);
addMesh(new THREE.CylinderGeometry(0.29, 0.29, 0.075, 8), materials.black, 0, 1.86, 0, group);
const tassel = addMesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.32, 6),
materials.gold,
0.27,
1.7,
0.18,
group
);
tassel.rotation.z = 0.12;
addMesh(new THREE.CylinderGeometry(0.095, 0.11, 0.48, 6), materials.black, -0.16, 0.28, 0, group);
addMesh(new THREE.CylinderGeometry(0.095, 0.11, 0.48, 6), materials.black, 0.16, 0.28, 0, group);
addMesh(new THREE.CylinderGeometry(0.09, 0.09, 0.62, 6), accent, -0.39, 0.98, 0.04, group);
addMesh(new THREE.CylinderGeometry(0.09, 0.09, 0.62, 6), accent, 0.39, 0.98, 0.04, group);
addMesh(new THREE.CylinderGeometry(0.11, 0.11, 0.055, 10), materials.gold, 0, 1.23, 0.31, group);
addMesh(new THREE.BoxGeometry(0.06, 0.28, 0.04), white, 0, 1.01, 0.33, group);
const certificate = addMesh(
new THREE.BoxGeometry(0.48, 0.055, 0.34),
materials.cream,
0.43,
0.77,
0.15,
group
);
certificate.rotation.z = -0.18;
certificate.visible = false;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.035, 6, 30),
new THREE.MeshBasicMaterial({
color: data.color,
transparent: true,
opacity: 0.88,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.045;
group.add(ring);
const hitArea = new THREE.Mesh(
new THREE.SphereGeometry(0.7, 8, 6),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hitArea.position.y = 1.2;
group.add(hitArea);
const nameLabel = makeLabel(data.name, {
width: 520,
height: 90,
background: "rgba(8, 28, 35, 0.88)",
foreground: "#fff4d7",
border: "rgba(255,255,255,0.2)",
font: "800 31px system-ui",
scale: [2.35, 0.41, 1]
});
nameLabel.position.set(0, 2.34, 0);
group.add(nameLabel);
group.traverse((object) => {
object.userData.participantIndex = index;
});
const start = new THREE.Vector3(4.4 + index * 0.48, 0, 4.6 - index * 1.15);
const path = new THREE.CatmullRomCurve3([
start.clone(),
new THREE.Vector3(start.x - 0.18, 0, start.z - 1.35),
new THREE.Vector3(3.35 - index * 0.18, 0, 1.05 - index * 0.28),
new THREE.Vector3(1.75, 0, -0.55),
new THREE.Vector3(0.65, 0, -2.18)
]);
group.position.copy(start);
return {
...data,
index,
group,
ring,
certificate,
path,
assigned: false,
status: "queued",
tween: null
};
}
const participants = program.map(makeParticipant);
const participantGroups = participants.map((p) => p.group);
// Confetti
const confettiGeometry = new THREE.BoxGeometry(0.09, 0.045, 0.15);
const confetti = [];
function burstConfetti(position, mainColor) {
const colors = [mainColor, 0xefba55, 0x64d8c2, 0xfff4d7, 0xf28bc2];
for (let i = 0; i < 42; i++) {
const material = standardMaterial(colors[i % colors.length], {
roughness: 0.5,
metalness: 0.08
});
const piece = new THREE.Mesh(confettiGeometry, material);
piece.position.copy(position);
piece.position.y += 1.5 + Math.random() * 0.8;
piece.rotation.set(Math.random() * 3, Math.random() * 3, Math.random() * 3);
scene.add(piece);
confetti.push({
mesh: piece,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 4.5,
2.5 + Math.random() * 4,
(Math.random() - 0.5) * 4.5
),
spin: new THREE.Vector3(
Math.random() * 7,
Math.random() * 7,
Math.random() * 7
),
life: 2.8
});
}
}
function updateConfetti(dt) {
for (let i = confetti.length - 1; i >= 0; i--) {
const item = confetti[i];
item.life -= dt;
if (item.life <= 0) {
scene.remove(item.mesh);
item.mesh.material.dispose();
confetti.splice(i, 1);
continue;
}
item.velocity.y -= 6.5 * dt;
item.mesh.position.addScaledVector(item.velocity, dt);
item.mesh.rotation.x += item.spin.x * dt;
item.mesh.rotation.y += item.spin.y * dt;
item.mesh.rotation.z += item.spin.z * dt;
}
}
// Custom orbit controls — no add-ons.
const cameraTarget = new THREE.Vector3(0, 1.15, -0.55);
let desiredYaw = 0.67;
let desiredPitch = 0.72;
let desiredRadius = window.innerWidth < 760 ? 19.5 : 16.2;
let currentYaw = desiredYaw;
let currentPitch = desiredPitch;
let currentRadius = desiredRadius;
function resetCamera() {
desiredYaw = 0.67;
desiredPitch = 0.72;
desiredRadius = window.innerWidth < 760 ? 19.5 : 16.2;
}
function updateCamera(dt) {
currentYaw = THREE.MathUtils.lerp(currentYaw, desiredYaw, 1 - Math.exp(-7 * dt));
currentPitch = THREE.MathUtils.lerp(currentPitch, desiredPitch, 1 - Math.exp(-7 * dt));
currentRadius = THREE.MathUtils.lerp(currentRadius, desiredRadius, 1 - Math.exp(-7 * dt));
camera.position.set(
cameraTarget.x + currentRadius * Math.sin(currentPitch) * Math.sin(currentYaw),
cameraTarget.y + currentRadius * Math.cos(currentPitch),
cameraTarget.z + currentRadius * Math.sin(currentPitch) * Math.cos(currentYaw)
);
camera.lookAt(cameraTarget);
}
const pointer = {
down: false,
x: 0,
y: 0,
lastX: 0,
lastY: 0,
moved: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.x = pointer.lastX = event.clientX;
pointer.y = pointer.lastY = event.clientY;
pointer.moved = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.down) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.moved += Math.abs(dx) + Math.abs(dy);
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(desiredPitch + dy * 0.005, 0.38, 1.23);
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointer.down = false;
if (pointer.moved < 6) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(participantGroups, true);
if (hits.length) {
const index = hits[0].object.userData.participantIndex;
if (Number.isInteger(index)) chooseRecipient(index);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.012,
10,
25
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key === "Escape") {
selectedRecipient = null;
selectedCertificateId = null;
updateVisualState();
}
});
// Game state
const PRESENTATION_DURATION = 22;
let certificates = [];
let currentIndex = 0;
let progress = 0;
let score = 1000;
let errors = 0;
let gameState = "intro";
let successTimer = 0;
let selectedCertificateId = null;
let selectedRecipient = null;
let toastTimer = null;
function shuffle(items) {
const array = [...items];
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function showToast(message, type = "info") {
clearTimeout(toastTimer);
toastElement.textContent = message;
toastElement.className = `show ${type}`;
toastTimer = setTimeout(() => {
toastElement.className = "";
}, 2900);
}
function statusFor(index) {
if (participants[index].assigned) return "Presented";
if (index !== currentIndex) return "Queued";
if (gameState === "waiting") return "At podium";
if (gameState === "intro") return "Next";
if (gameState === "success") return "Presented";
return "Approaching";
}
function renderProgram() {
programList.innerHTML = participants
.map((participant, index) => {
const current = index === currentIndex && !participant.assigned;
const selected = index === selectedRecipient;
const status = statusFor(index);
return `
<div
class="program-row ${current ? "current" : ""} ${selected ? "selected" : ""} ${
participant.assigned ? "assigned" : ""
}"
data-index="${index}"
role="button"
tabindex="0"
aria-label="${participant.name}, ${participant.award}, ${status}"
>
<div class="program-number">${participant.assigned ? "✓" : index + 1}</div>
<div>
<span class="participant-name">${participant.name}</span>
<span class="participant-award">${participant.award}</span>
</div>
<div class="row-status">${status}</div>
</div>
`;
})
.join("");
}
function renderCertificates() {
certificateList.innerHTML = certificates
.map((certificate) => {
const recipient = program[certificate.recipientIndex];
const selected = certificate.id === selectedCertificateId;
return `
<div
class="certificate-card ${selected ? "selected" : ""} ${
certificate.assigned ? "assigned" : ""
}"
data-id="${certificate.id}"
draggable="${certificate.assigned ? "false" : "true"}"
style="--certificate-color: #${new THREE.Color(
recipient.color
).getHexString()}"
role="button"
tabindex="0"
>
<div class="certificate-top">
<span class="certificate-code">Certificate ${certificate.code}</span>
<span class="misplaced-tag">${certificate.assigned ? "Presented" : "Misplaced"}</span>
</div>
<div class="certificate-award">${recipient.award}</div>
<div class="certificate-recipient">Prepared for <strong>${recipient.name}</strong></div>
<div class="certificate-footer">
<span>${certificate.assigned ? "Order restored" : "Awaiting match"}</span>
<span>Northstar U.</span>
</div>
<div class="seal">${recipient.initials}</div>
</div>
`;
})
.join("");
const unassigned = certificates.filter((certificate) => !certificate.assigned).length;
document.querySelector("#certificateCount").textContent =
`${unassigned} unassigned`;
}
function updateVisualState() {
renderProgram();
renderCertificates();
participants.forEach((participant, index) => {
participant.ring.visible =
index === currentIndex || index === selectedRecipient;
participant.ring.material.opacity =
index === selectedRecipient ? 1 : 0.58 + Math.sin(performance.now() * 0.005) * 0.18;
});
}
function chooseCertificate(id) {
if (gameState === "intro" || gameState === "complete") return;
const certificate = certificates.find((item) => item.id === id);
if (!certificate || certificate.assigned) return;
selectedCertificateId = id;
selectedRecipient = null;
updateVisualState();
showToast(
`${program[certificate.recipientIndex].name}'s certificate selected. Now choose that recipient.`
);
}
function registerError(message) {
errors += 1;
score = Math.max(0, score - 50);
progress = Math.max(0, progress - 3 / PRESENTATION_DURATION);
selectedRecipient = null;
updateVisualState();
showToast(message, "error");
}
function chooseRecipient(index) {
if (!["playing", "waiting"].includes(gameState)) return;
const participant = participants[index];
if (!participant || participant.assigned) {
showToast("That graduate has already been presented.", "error");
return;
}
selectedRecipient = index;
updateVisualState();
if (!selectedCertificateId) {
showToast(`${participant.name} selected. Choose a certificate first.`);
return;
}
const certificate = certificates.find(
(item) => item.id === selectedCertificateId
);
if (!certificate || certificate.assigned) {
selectedCertificateId = null;
updateVisualState();
return;
}
if (certificate.recipientIndex !== index) {
registerError(
`That certificate belongs to ${program[certificate.recipientIndex].name}, not ${participant.name}.`
);
return;
}
if (index !== currentIndex) {
const difference = index - currentIndex;
registerError(
difference > 0
? `${participant.name} is ${difference} place${difference === 1 ? "" : "s"} later. Present ${
participants[currentIndex].name
} first.`
: `${participant.name} has already been presented.`
);
return;
}
completeAssignment(index, certificate);
}
function completeAssignment(index, certificate) {
const participant = participants[index];
participant.assigned = true;
participant.status = "awarded";
certificate.assigned = true;
participant.certificate.visible = true;
const remaining = Math.max(0, PRESENTATION_DURATION * (1 - progress));
score += Math.round(remaining * 3);
gameState = "success";
successTimer = 1.5;
const end = new THREE.Vector3(-3.25 + index * 1.15, 0.76, -4.0);
const start = participant.group.position.clone();
const control = start.clone().lerp(end, 0.5);
control.y += 1.8;
participant.tween = {
time: 0,
duration: 1.45,
curve: new THREE.QuadraticBezierCurve3(start, control, end)
};
burstConfetti(participant.group.position.clone(), participant.color);
showToast(
`Correct — ${participant.name} receives the ${participant.award}.`,
"success"
);
updateVisualState();
}
function updateTweens(dt) {
participants.forEach((participant) => {
if (!participant.tween) return;
participant.tween.time += dt;
const t = Math.min(1, participant.tween.time / participant.tween.duration);
participant.group.position.copy(participant.tween.curve.getPoint(t));
participant.group.rotation.y = THREE.MathUtils.lerp(
participant.group.rotation.y,
Math.PI,
dt * 2.6
);
if (t >= 1) participant.tween = null;
});
}
function resetGame(showIntro = true) {
currentIndex = 0;
progress = 0;
score = 1000;
errors = 0;
successTimer = 0;
selectedCertificateId = null;
selectedRecipient = null;
gameState = "intro";
certificates = shuffle(
program.map((participant, index) => ({
id: `certificate-${index}`,
code: `N${String(41 + index * 7)}`,
recipientIndex: index,
assigned: false
}))
);
participants.forEach((participant, index) => {
participant.assigned = false;
participant.status = "queued";
participant.tween = null;
participant.certificate.visible = false;
participant.group.position.copy(participant.path.getPoint(0));
participant.group.rotation.set(0, -0.15, 0);
participant.ring.visible = index === 0;
});
completionOverlay.classList.add("hidden");
if (showIntro) introOverlay.classList.remove("hidden");
else introOverlay.classList.add("hidden");
updateVisualState();
updateHUD();
}
function beginCeremony() {
if (gameState !== "intro") return;
gameState = "playing";
participants[0].status = "walking";
introOverlay.classList.add("hidden");
showToast(
`${participants[0].name} is approaching. Match the ${participants[0].award} certificate.`
);
updateVisualState();
}
function finishCeremony() {
gameState = "complete";
document.querySelector("#completionScore").textContent = score;
document.querySelector("#completionErrors").textContent = errors;
completionOverlay.classList.remove("hidden");
}
function updateHUD() {
const participant = participants[currentIndex];
const assignedCount = participants.filter((item) => item.assigned).length;
const remaining = participant
? Math.max(0, Math.ceil(PRESENTATION_DURATION * (1 - progress)))
: 0;
document.querySelector("#orderStat").textContent = `${assignedCount} / ${participants.length}`;
document.querySelector("#scoreStat").textContent = score;
document.querySelector("#activeStat").textContent = participant
? participant.name.split(" ")[0]
: "Done";
const minutes = Math.floor(remaining / 60);
const seconds = String(remaining % 60).padStart(2, "0");
document.querySelector("#countdown").textContent =
gameState === "success"
? "✓"
: gameState === "complete"
? "DONE"
: gameState === "waiting"
? "HOLD"
: `${minutes}:${seconds}`;
document.querySelector("#timerLabel").textContent =
gameState === "waiting"
? "Presentation line held"
: gameState === "success"
? "Award confirmed"
: gameState === "intro"
? "Ceremony begins shortly"
: "Time to presentation";
document.querySelector("#progressFill").style.width = `${Math.min(100, progress * 100)}%`;
}
// DOM event delegation
programList.addEventListener("click", (event) => {
const row = event.target.closest(".program-row");
if (row) chooseRecipient(Number(row.dataset.index));
});
programList.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const row = event.target.closest(".program-row");
if (row) {
event.preventDefault();
chooseRecipient(Number(row.dataset.index));
}
});
certificateList.addEventListener("click", (event) => {
const card = event.target.closest(".certificate-card");
if (card) chooseCertificate(card.dataset.id);
});
certificateList.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const card = event.target.closest(".certificate-card");
if (card) {
event.preventDefault();
chooseCertificate(card.dataset.id);
}
});
certificateList.addEventListener("dragstart", (event) => {
const card = event.target.closest(".certificate-card");
if (!card) return;
selectedCertificateId = card.dataset.id;
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", card.dataset.id);
updateVisualState();
});
programList.addEventListener("dragover", (event) => {
if (event.target.closest(".program-row")) {
event.preventDefault();
event.dataTransfer.dropEffect = "move";
}
});
programList.addEventListener("drop", (event) => {
const row = event.target.closest(".program-row");
if (!row) return;
event.preventDefault();
const id = event.dataTransfer.getData("text/plain");
if (id) {
selectedCertificateId = id;
chooseRecipient(Number(row.dataset.index));
}
});
document.querySelector("#beginBtn").addEventListener("click", beginCeremony);
document.querySelector("#resetBtn").addEventListener("click", () => resetGame(true));
document.querySelector("#againBtn").addEventListener("click", () => resetGame(false));
document.querySelector("#viewBtn").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resetGame(true);
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(dt);
updateTweens(dt);
updateConfetti(dt);
if (gameState === "playing" && participants[currentIndex]) {
const participant = participants[currentIndex];
progress = Math.min(1, progress + dt / PRESENTATION_DURATION);
const point = participant.path.getPointAt(progress);
const tangent = participant.path.getTangentAt(Math.min(0.999, progress));
participant.group.position.copy(point);
participant.group.position.y = Math.abs(Math.sin(elapsed * 9 + participant.index)) * 0.035;
participant.group.rotation.y = Math.atan2(tangent.x, tangent.z);
if (progress >= 1) {
participant.status = "waiting";
gameState = "waiting";
showToast(
"The presentation line is held. Assign the current certificate to continue.",
"error"
);
updateVisualState();
}
}
if (gameState === "success") {
successTimer -= dt;
if (successTimer <= 0) {
if (currentIndex >= participants.length - 1) {
finishCeremony();
} else {
currentIndex += 1;
progress = 0;
gameState = "playing";
participants[currentIndex].status = "walking";
showToast(
`${participants[currentIndex].name} is approaching. Restore the next certificate.`
);
updateVisualState();
}
}
}
participants.forEach((participant, index) => {
if (index === currentIndex && gameState === "playing") return;
participant.ring.material.opacity =
index === selectedRecipient
? 1
: 0.58 + Math.sin(elapsed * 4 + index) * 0.16;
});
podiumLight.intensity = 9.5 + Math.sin(elapsed * 2.2) * 1.2;
updateHUD();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```