Prompt specification
Build or customize the Three.js 3D scene "Classroom Ranked Choice Demonstrator" 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: Classroom Ranked Choice Demonstrator
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/classroom-ranked-choice-demonstrator-x3206
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: classroom ranked choice demonstrator. Show a fictional class choosing among three trip destinations with fixed ranked preferences. Compare plurality and a clearly defined ranked procedure using the same ballots. Return one self-contained HTML file.
Working Three.js Starter (classroom-ranked-choice-demonstrator-x3206):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rank & Decide — Classroom Trip Vote</title>
<style>
:root {
--ink: #173632;
--ink-soft: #38524e;
--muted: #70807c;
--paper: #f4f1e9;
--card: rgba(255, 255, 252, 0.94);
--line: #dce2db;
--alpine: #1b9d8f;
--coast: #f07a61;
--city: #e3a73b;
--blue: #4967a8;
--teal: #2b9c91;
--purple: #8a67b0;
--amber: #e09b36;
--shadow: 0 14px 38px rgba(35, 55, 50, 0.10);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button { font: inherit; }
.topbar {
height: 68px;
padding: 0 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
border-bottom: 1px solid rgba(23, 54, 50, 0.12);
background: rgba(249, 247, 240, 0.94);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
color: var(--ink);
text-decoration: none;
font-size: 14px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.brand-mark {
width: 35px;
height: 35px;
display: grid;
place-items: center;
border-radius: 11px;
color: #fff;
background: var(--ink);
box-shadow: 0 5px 14px rgba(23, 54, 50, 0.2);
font-size: 18px;
font-weight: 900;
}
.lesson-meta {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 13px;
font-weight: 650;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #43ad72;
box-shadow: 0 0 0 4px rgba(67, 173, 114, 0.13);
}
.replay-button {
border: 1px solid rgba(23, 54, 50, 0.18);
border-radius: 11px;
padding: 9px 13px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition: background .2s ease, transform .2s ease;
}
.replay-button:hover {
background: #fff;
transform: translateY(-1px);
}
.workspace {
height: calc(100vh - 68px);
padding: 14px;
display: grid;
grid-template-columns: minmax(0, 1fr) 414px;
gap: 14px;
}
.stage-panel {
position: relative;
min-width: 0;
overflow: hidden;
border-radius: 24px;
background: #e8e4d9;
box-shadow: var(--shadow);
isolation: isolate;
}
#scene,
#scene canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
outline: none;
}
.stage-vignette {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(239, 236, 226, .76) 0%, rgba(239, 236, 226, 0) 25%),
linear-gradient(0deg, rgba(18, 43, 39, .18), transparent 29%);
}
.stage-head {
position: absolute;
top: 25px;
left: 28px;
z-index: 6;
max-width: 570px;
pointer-events: none;
}
.eyebrow {
display: block;
color: var(--coast);
font-size: 11px;
line-height: 1;
font-weight: 900;
letter-spacing: .15em;
text-transform: uppercase;
}
.stage-head h1 {
margin: 9px 0 7px;
font-size: clamp(28px, 3.3vw, 48px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.stage-head p {
margin: 0;
color: var(--ink-soft);
font-size: 14px;
font-weight: 570;
}
.winner-flag {
position: absolute;
z-index: 7;
top: 26px;
right: 27px;
max-width: 245px;
padding: 12px 14px;
border: 1px solid rgba(255,255,255,.75);
border-radius: 14px;
background: rgba(255,255,252,.87);
box-shadow: 0 10px 28px rgba(28, 52, 48, .13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.winner-flag small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.winner-flag strong {
display: block;
margin-top: 4px;
font-size: 15px;
}
.stage-bottom {
position: absolute;
left: 24px;
right: 24px;
bottom: 22px;
z-index: 10;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.method-switch {
display: flex;
padding: 5px;
gap: 4px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 15px;
background: rgba(255,255,252,.88);
box-shadow: 0 12px 28px rgba(27, 51, 47, .17);
backdrop-filter: blur(13px);
pointer-events: auto;
}
.method-switch button {
border: 0;
border-radius: 11px;
padding: 11px 15px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 820;
transition: color .2s ease, background .2s ease, box-shadow .2s ease;
}
.method-switch button.active {
color: #fff;
background: var(--ink);
box-shadow: 0 4px 10px rgba(23, 54, 50, .22);
}
.camera-controls {
display: flex;
padding: 5px;
gap: 3px;
border: 1px solid rgba(255,255,255,.7);
border-radius: 13px;
background: rgba(255,255,252,.88);
box-shadow: 0 10px 24px rgba(27, 51, 47, .13);
backdrop-filter: blur(13px);
pointer-events: auto;
}
.camera-controls button {
width: 34px;
height: 34px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 17px;
font-weight: 850;
}
.camera-controls button:hover { background: #edf0ea; }
.stage-help {
position: absolute;
z-index: 7;
left: 27px;
bottom: 86px;
color: rgba(23, 54, 50, .68);
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
#worldLabels {
position: absolute;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
transition: opacity .16s linear;
}
.destination-label {
display: flex;
align-items: center;
gap: 9px;
min-width: 148px;
padding: 8px 11px 8px 8px;
border: 1px solid rgba(255,255,255,.65);
border-radius: 12px;
color: #fff;
background: rgba(20, 47, 43, .9);
box-shadow: 0 8px 20px rgba(23, 54, 50, .18);
backdrop-filter: blur(8px);
}
.destination-label .world-rank {
width: 27px;
height: 27px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 8px;
background: var(--c);
color: #fff;
font-size: 11px;
font-weight: 900;
}
.destination-label strong {
display: block;
font-size: 12px;
line-height: 1.1;
}
.destination-label small {
display: block;
margin-top: 3px;
color: rgba(255,255,255,.68);
font-size: 9px;
font-weight: 650;
}
.gauge-label {
padding: 4px 8px;
border-radius: 8px;
color: #fff;
background: var(--c);
box-shadow: 0 5px 14px rgba(23, 54, 50, .18);
font-size: 11px;
font-weight: 900;
}
.ballot-world {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 8px;
border: 1px solid rgba(255,255,255,.78);
border-radius: 999px;
color: var(--ink);
background: rgba(255,255,252,.86);
box-shadow: 0 5px 14px rgba(23, 54, 50, .10);
font-size: 9px;
font-weight: 850;
letter-spacing: .02em;
}
.ballot-world i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--c);
}
.loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #e8e4d9;
font-size: 12px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
transition: opacity .4s ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.insight-panel {
min-width: 0;
overflow-y: auto;
padding-right: 2px;
scrollbar-width: thin;
scrollbar-color: #bcc7c0 transparent;
}
.panel-card {
margin-bottom: 12px;
padding: 18px;
border: 1px solid rgba(23, 54, 50, .10);
border-radius: 19px;
background: var(--card);
box-shadow: 0 8px 24px rgba(35, 55, 50, .065);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
line-height: 1.1;
letter-spacing: .04em;
text-transform: uppercase;
}
.section-heading .section-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.compare-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.result-card {
position: relative;
min-width: 0;
padding: 13px;
border: 1px solid var(--line);
border-radius: 14px;
color: var(--ink);
background: #f8f8f3;
text-align: left;
cursor: pointer;
transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.result-card:hover {
transform: translateY(-2px);
border-color: #aebcb5;
}
.result-card.active {
border-color: var(--method-color);
box-shadow: inset 0 0 0 1px var(--method-color);
background: #fff;
}
.result-card .method-mini {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: .09em;
text-transform: uppercase;
}
.result-card .method-mini::after {
content: "";
width: 7px;
height: 7px;
border: 2px solid #bcc5bf;
border-radius: 50%;
}
.result-card.active .method-mini::after {
border-color: var(--method-color);
background: var(--method-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--method-color) 18%, transparent);
}
.result-card .winner-name {
margin-top: 15px;
font-size: 17px;
line-height: 1.05;
letter-spacing: -.025em;
font-weight: 850;
}
.result-card .winner-note {
margin-top: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
font-weight: 620;
}
.split-callout {
margin-top: 10px;
padding: 10px 12px;
border-radius: 11px;
color: #7d493e;
background: #fff0e9;
font-size: 11px;
line-height: 1.35;
font-weight: 760;
text-align: center;
}
.split-callout strong { color: #6a382f; }
.score-table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.score-table th {
padding: 0 0 8px;
color: var(--muted);
font-size: 9px;
line-height: 1.2;
font-weight: 850;
text-align: right;
text-transform: uppercase;
letter-spacing: .04em;
}
.score-table th:first-child { text-align: left; }
.score-table th.active { color: var(--ink); }
.score-table td {
padding: 11px 0;
border-top: 1px solid #e7ebe5;
text-align: right;
vertical-align: middle;
}
.score-table td:first-child {
text-align: left;
font-size: 11px;
font-weight: 800;
}
.dest-name {
display: flex;
align-items: center;
gap: 7px;
}
.dest-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
}
.score-cell {
opacity: .48;
transition: opacity .2s ease;
}
.score-cell.active { opacity: 1; }
.score-cell strong {
display: block;
font-size: 14px;
line-height: 1;
}
.score-cell small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
}
.mini-track {
width: 76px;
height: 4px;
margin-top: 6px;
margin-left: auto;
overflow: hidden;
border-radius: 10px;
background: #e5e9e3;
}
.mini-track span {
display: block;
width: var(--w);
height: 100%;
border-radius: inherit;
background: var(--c);
}
.method-note {
border-left: 3px solid var(--coast);
padding: 2px 0 2px 13px;
}
.method-note h3 {
margin: 0 0 6px;
font-size: 14px;
}
.method-note p {
margin: 0;
color: var(--ink-soft);
font-size: 11px;
line-height: 1.55;
}
.method-note .formula {
display: inline-block;
margin-top: 10px;
padding: 6px 9px;
border-radius: 8px;
color: var(--ink);
background: #edf0e9;
font-size: 10px;
font-weight: 850;
letter-spacing: .03em;
}
.locked-badge {
display: inline-flex;
align-items: center;
gap: 5px;
color: #54736c;
font-size: 9px;
font-weight: 850;
text-transform: uppercase;
letter-spacing: .07em;
}
.locked-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: #64a18e;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.ballot-table {
width: 100%;
border-collapse: collapse;
}
.ballot-table th {
padding: 0 0 7px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
text-align: center;
text-transform: uppercase;
letter-spacing: .07em;
}
.ballot-table th:first-child { text-align: left; }
.ballot-table td {
padding: 8px 4px;
border-top: 1px solid #e8ebe6;
text-align: center;
font-size: 9px;
font-weight: 850;
}
.ballot-table td:first-child {
text-align: left;
white-space: nowrap;
}
.student-count {
display: flex;
align-items: center;
gap: 7px;
}
.student-count i {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--c);
}
.rank-chip {
display: inline-grid;
place-items: center;
width: 26px;
height: 24px;
border-radius: 7px;
color: var(--ink);
background: #eef0eb;
font-size: 9px;
font-weight: 900;
}
.rank-chip.first {
color: #fff;
background: var(--ink);
}
.panel-note {
margin: 12px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.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: 1100px) {
.workspace { grid-template-columns: minmax(0, 1fr) 370px; }
.winner-flag { max-width: 205px; }
.stage-head { max-width: 470px; }
}
@media (max-width: 880px) {
body { overflow: auto; }
.workspace {
height: auto;
grid-template-columns: 1fr;
padding: 10px;
}
.stage-panel {
height: 68vh;
min-height: 590px;
}
.insight-panel {
overflow: visible;
padding-right: 0;
}
.lesson-meta { display: none; }
}
@media (max-width: 560px) {
.topbar { padding: 0 13px; }
.brand { font-size: 12px; }
.replay-button { padding: 8px 10px; font-size: 10px; }
.workspace { padding: 7px; gap: 9px; }
.stage-panel {
height: 650px;
min-height: 650px;
border-radius: 19px;
}
.stage-head { top: 20px; left: 18px; right: 18px; }
.stage-head h1 { font-size: 31px; }
.stage-head p { font-size: 12px; }
.winner-flag {
top: auto;
left: 18px;
right: 18px;
bottom: 78px;
max-width: none;
padding: 9px 12px;
}
.winner-flag strong { display: inline; margin-left: 6px; font-size: 12px; }
.winner-flag small { display: inline; }
.stage-bottom {
left: 12px;
right: 12px;
bottom: 14px;
gap: 8px;
}
.method-switch { flex: 1; }
.method-switch button { flex: 1; padding: 10px 8px; font-size: 10px; }
.camera-controls button { width: 29px; }
.stage-help { display: none; }
.destination-label { min-width: 122px; padding: 6px 8px 6px 6px; }
.destination-label .world-rank { width: 23px; height: 23px; }
.destination-label strong { font-size: 10px; }
.destination-label small { font-size: 8px; }
.ballot-world { font-size: 8px; }
.panel-card { padding: 15px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
scroll-behavior: auto !important;
transition-duration: .01ms !important;
animation-duration: .01ms !important;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true">≋</span>
<span>Rank & Decide</span>
</div>
<div class="lesson-meta">
<span class="status-dot" aria-hidden="true"></span>
Social studies · Interactive classroom model
</div>
<button class="replay-button" id="replayButton" type="button">↻ Replay count</button>
</header>
<main class="workspace">
<section class="stage-panel" aria-label="Interactive 3D classroom voting model">
<div id="scene"></div>
<div class="stage-vignette"></div>
<div id="worldLabels" aria-hidden="true"></div>
<div class="stage-head">
<span class="eyebrow">Classroom simulation · 30 fixed ballots</span>
<h1>Where should Class 7B go next?</h1>
<p>Three destinations. One set of rankings. Two counting rules.</p>
</div>
<div class="winner-flag" id="winnerFlag" aria-live="polite">
<small>Plurality winner</small>
<strong>Alpine Trails</strong>
</div>
<div class="stage-help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="stage-bottom">
<div class="method-switch" role="tablist" aria-label="Counting method">
<button
type="button"
role="tab"
data-set-method="plurality"
class="active"
aria-selected="true"
>Plurality</button>
<button
type="button"
role="tab"
data-set-method="borda"
aria-selected="false"
>Borda count</button>
</div>
<div class="camera-controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetCamera" type="button" aria-label="Reset camera">⌂</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
</div>
</div>
<div class="loading" id="loading">Building the classroom…</div>
</section>
<aside class="insight-panel" aria-label="Voting analysis">
<section class="panel-card">
<div class="section-heading">
<h2>The result</h2>
<span class="section-kicker">Select either outcome to explore</span>
</div>
<div class="compare-grid">
<button
class="result-card active"
id="pluralityCard"
type="button"
data-set-method="plurality"
style="--method-color: var(--alpine)"
aria-pressed="true"
>
<span class="method-mini">Plurality</span>
<span class="winner-name">Alpine Trails</span>
<span class="winner-note">15 of 30 first-place votes</span>
</button>
<button
class="result-card"
id="bordaCard"
type="button"
data-set-method="borda"
style="--method-color: var(--coast)"
aria-pressed="false"
>
<span class="method-mini">Borda count</span>
<span class="winner-name">Sunset Coast</span>
<span class="winner-note">72 of 90 possible points</span>
</button>
</div>
<div class="split-callout">
<strong>Different winner, same ballots.</strong> The counting rule changes the trip.
</div>
</section>
<section class="panel-card">
<div class="section-heading">
<h2>Scorecard</h2>
<span class="section-kicker">Relative to each maximum</span>
</div>
<table class="score-table">
<thead>
<tr>
<th>Destination</th>
<th class="active" data-cell-method="plurality">Plurality<br>votes</th>
<th data-cell-method="borda">Borda<br>points</th>
</tr>
</thead>
<tbody id="scoreRows"></tbody>
</table>
</section>
<section class="panel-card">
<div class="method-note" id="methodNote">
<h3 id="methodTitle">Plurality</h3>
<p id="methodDescription"></p>
<span class="formula" id="methodFormula"></span>
</div>
</section>
<section class="panel-card">
<div class="section-heading">
<h2>Fixed ballot profiles</h2>
<span class="locked-badge">Locked</span>
</div>
<table class="ballot-table">
<thead>
<tr>
<th>Students</th>
<th>1st</th>
<th>2nd</th>
<th>3rd</th>
</tr>
</thead>
<tbody id="ballotRows"></tbody>
</table>
<p class="panel-note">
A = Alpine Trails · B = Sunset Coast · C = City Central.
These four profiles account for all 30 students. Switching methods never changes a ballot.
</p>
</section>
</aside>
</main>
<div class="sr-only" id="liveRegion" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const destinations = {
alpine: {
name: "Alpine Trails",
short: "ALP",
color: 0x1b9d8f,
css: "#1b9d8f",
x: -6
},
coast: {
name: "Sunset Coast",
short: "CST",
color: 0xf07a61,
css: "#f07a61",
x: 0
},
city: {
name: "City Central",
short: "CTY",
color: 0xe3a73b,
css: "#e3a73b",
x: 6
}
};
const ballotProfiles = [
{ count: 15, order: ["alpine", "coast", "city"], color: "#4967a8" },
{ count: 8, order: ["coast", "city", "alpine"], color: "#2b9c91" },
{ count: 4, order: ["coast", "alpine", "city"], color: "#8a67b0" },
{ count: 3, order: ["city", "coast", "alpine"], color: "#e09b36" }
];
const methods = {
plurality: {
label: "Plurality",
values: { alpine: 15, coast: 12, city: 3 },
max: 30,
unit: "votes",
winner: "alpine",
formula: "1 point to the 1st choice only",
description:
"Only each ballot’s first-place choice receives a vote. The destination with the most first-place votes wins. There is no tie in this class."
},
borda: {
label: "Borda count",
values: { alpine: 64, coast: 72, city: 44 },
max: 90,
unit: "points",
winner: "coast",
formula: "3 points for 1st + 2 points for 2nd + 1 point for 3rd",
description:
"Every ballot awards 3 points to its first choice, 2 points to its second, and 1 point to its third. The destination with the most total points wins. There is no tie."
}
};
const sceneElement = document.getElementById("scene");
const labelsElement = document.getElementById("worldLabels");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e4d9);
scene.fog = new THREE.Fog(0xe8e4d9, 25, 45);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Three-dimensional classroom with three trip destinations and thirty students");
renderer.domElement.setAttribute("tabindex", "0");
sceneElement.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.35, -0.65);
const cameraSpherical = new THREE.Spherical(21, 1.12, 0.40);
let velocityTheta = 0;
let velocityPhi = 0;
function updateCamera() {
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x718078, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(6, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xffc9b8, 0.75);
fillLight.position.set(-9, 7, 2);
scene.add(fillLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function makeMesh(geometry, material, parent, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Classroom shell.
const floorMaterial = standardMaterial(0xd9d5c9);
const floor = makeMesh(new THREE.PlaneGeometry(24, 20), floorMaterial, scene, 0, -0.015, 0);
floor.rotation.x = -Math.PI / 2;
const rugMaterial = standardMaterial(0xbfd0c5, { transparent: true, opacity: 0.64 });
const rug = makeMesh(new THREE.BoxGeometry(15.8, 0.035, 7.0), rugMaterial, scene, 0.8, 0.006, 3.25);
rug.receiveShadow = true;
const grid = new THREE.GridHelper(22, 22, 0xaeb6ae, 0xc5c4b9);
grid.position.y = 0.015;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
const wallMaterial = standardMaterial(0xe1dfd5);
makeMesh(new THREE.BoxGeometry(22, 7.5, 0.32), wallMaterial, scene, 0, 3.75, -7.85);
const baseboardMaterial = standardMaterial(0xb7c3b9);
makeMesh(new THREE.BoxGeometry(22, 0.25, 0.28), baseboardMaterial, scene, 0, 0.125, -7.64);
const wallSideMaterial = standardMaterial(0xd6dbd2);
makeMesh(new THREE.BoxGeometry(0.28, 7.5, 12), wallSideMaterial, scene, -10.7, 3.75, -1.8);
makeMesh(new THREE.BoxGeometry(0.28, 7.5, 12), wallSideMaterial, scene, 10.7, 3.75, -1.8);
// Classroom display board.
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1600;
boardCanvas.height = 620;
const boardContext = boardCanvas.getContext("2d");
const boardTexture = new THREE.CanvasTexture(boardCanvas);
boardTexture.colorSpace = THREE.SRGBColorSpace;
boardTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const boardFrame = makeMesh(
new THREE.BoxGeometry(13.8, 4.55, 0.20),
standardMaterial(0x193a35),
scene,
0,
3.68,
-7.60
);
const board = makeMesh(
new THREE.PlaneGeometry(13.25, 4.02),
new THREE.MeshBasicMaterial({ map: boardTexture }),
scene,
0,
3.68,
-7.485
);
board.castShadow = false;
const trayMaterial = standardMaterial(0xaeb9ae);
makeMesh(new THREE.BoxGeometry(4.2, 0.12, 0.40), trayMaterial, scene, 0, 1.58, -7.35);
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function drawBoard(methodKey) {
const method = methods[methodKey];
const ctx = boardContext;
ctx.clearRect(0, 0, 1600, 620);
ctx.fillStyle = "#173a35";
ctx.fillRect(0, 0, 1600, 620);
ctx.fillStyle = "#f4a58e";
ctx.font = "800 25px system-ui";
ctx.fillText("CLASS 7B / TRIP COMMITTEE", 80, 72);
ctx.fillStyle = "#ffffff";
ctx.font = "800 58px system-ui";
ctx.fillText("One set of 30 ballots.", 80, 155);
ctx.fillStyle = "#9fb6ad";
ctx.font = "600 28px system-ui";
ctx.fillText("Change the counting rule—not the votes.", 82, 202);
roundedRect(ctx, 1110, 55, 390, 78, 18);
ctx.fillStyle = methodKey === "plurality" ? "#1b9d8f" : "#f07a61";
ctx.fill();
ctx.fillStyle = "#ffffff";
ctx.font = "800 22px system-ui";
ctx.fillText(`CURRENT VIEW · ${method.label.toUpperCase()}`, 1138, 104);
const cardY = 275;
const cardW = 430;
const gap = 55;
const startX = 80;
Object.entries(destinations).forEach(([key, destination], index) => {
const x = startX + index * (cardW + gap);
roundedRect(ctx, x, cardY, cardW, 235, 24);
ctx.fillStyle = "rgba(255,255,255,0.075)";
ctx.fill();
ctx.fillStyle = destination.css;
ctx.beginPath();
ctx.arc(x + 55, cardY + 63, 25, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#ffffff";
ctx.font = "800 30px system-ui";
ctx.fillText(destination.name, x + 98, cardY + 73);
ctx.fillStyle = "#ffffff";
ctx.font = "850 68px system-ui";
ctx.fillText(String(method.values[key]), x + 38, cardY + 174);
ctx.fillStyle = "#a9bdb5";
ctx.font = "650 22px system-ui";
ctx.fillText(method.unit.toUpperCase(), x + 38, cardY + 210);
});
boardTexture.needsUpdate = true;
}
// Destination models.
const stationData = [];
function addDestinationBase(group, color) {
const podium = makeMesh(
new THREE.CylinderGeometry(1.78, 1.88, 0.28, 48),
standardMaterial(0xc9c9bc),
group,
0,
0.14,
0
);
podium.receiveShadow = true;
const ring = makeMesh(
new THREE.TorusGeometry(2.02, 0.055, 10, 64),
new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.08 }),
group,
0,
0.31,
0
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = false;
return ring;
}
function buildAlpine(group) {
const terrainMaterial = standardMaterial(0x6d8d69);
makeMesh(new THREE.CylinderGeometry(1.53, 1.58, 0.20, 36), terrainMaterial, group, 0, 0.38, 0);
const rockMaterial = standardMaterial(0x69777b);
const snowMaterial = standardMaterial(0xf4f6ef);
const darkRockMaterial = standardMaterial(0x536368);
makeMesh(new THREE.ConeGeometry(1.12, 2.15, 6), rockMaterial, group, -0.22, 1.48, -0.12);
makeMesh(new THREE.ConeGeometry(0.48, 0.76, 6), snowMaterial, group, -0.22, 2.27, -0.12);
makeMesh(new THREE.ConeGeometry(0.70, 1.45, 6), darkRockMaterial, group, 0.67, 1.03, 0.23);
makeMesh(new THREE.ConeGeometry(0.30, 0.47, 6), snowMaterial, group, 0.67, 1.55, 0.23);
const trunkMaterial = standardMaterial(0x785740);
const treeMaterial = standardMaterial(0x315f49);
makeMesh(new THREE.CylinderGeometry(0.06, 0.08, 0.48, 8), trunkMaterial, group, -0.98, 0.70, 0.63);
makeMesh(new THREE.ConeGeometry(0.32, 0.78, 8), treeMaterial, group, -0.98, 1.10, 0.63);
const lodgeMaterial = standardMaterial(0xe6d7b7);
const roofMaterial = standardMaterial(0xba604e);
makeMesh(new THREE.BoxGeometry(0.58, 0.48, 0.48), lodgeMaterial, group, 0.83, 0.72, -0.73);
const roof = makeMesh(new THREE.ConeGeometry(0.48, 0.32, 4), roofMaterial, group, 0.83, 1.12, -0.73);
roof.rotation.y = Math.PI / 4;
}
function buildCoast(group) {
const waterMaterial = standardMaterial(0x55b8bd, { roughness: 0.38 });
const sandMaterial = standardMaterial(0xe8c982);
const trunkMaterial = standardMaterial(0x9a6946);
const leafMaterial = standardMaterial(0x397957);
makeMesh(new THREE.CylinderGeometry(1.53, 1.58, 0.22, 40), waterMaterial, group, 0, 0.39, 0);
makeMesh(new THREE.CylinderGeometry(1.12, 1.22, 0.25, 36), sandMaterial, group, 0.04, 0.49, 0.03);
const surf = makeMesh(
new THREE.TorusGeometry(1.28, 0.035, 8, 56),
standardMaterial(0xf6f1dc),
group,
0.04,
0.53,
0.03
);
surf.rotation.x = Math.PI / 2;
const palm = new THREE.Group();
palm.position.set(0.12, 0.60, 0.02);
palm.rotation.z = -0.12;
group.add(palm);
makeMesh(new THREE.CylinderGeometry(0.10, 0.17, 1.85, 9), trunkMaterial, palm, 0, 0.92, 0);
for (let i = 0; i < 6; i++) {
const leaf = makeMesh(
new THREE.SphereGeometry(0.55, 10, 6),
leafMaterial,
palm,
0,
1.82,
0
);
leaf.scale.set(1.18, 0.09, 0.34);
leaf.rotation.y = (i / 6) * Math.PI * 2;
leaf.rotation.z = i % 2 === 0 ? -0.18 : 0.18;
leaf.position.x = Math.sin((i / 6) * Math.PI * 2) * 0.50;
leaf.position.z = Math.cos((i / 6) * Math.PI * 2) * 0.50;
}
const sunMaterial = standardMaterial(0xffd16c, {
emissive: 0xffa928,
emissiveIntensity: 0.32
});
makeMesh(new THREE.SphereGeometry(0.23, 18, 12), sunMaterial, group, 0.78, 2.50, -0.42);
}
function buildCity(group) {
const roadMaterial = standardMaterial(0x515c5b);
makeMesh(new THREE.CylinderGeometry(1.58, 1.63, 0.22, 40), standardMaterial(0xa9afa8), group, 0, 0.39, 0);
const road = makeMesh(new THREE.BoxGeometry(2.85, 0.035, 0.42), roadMaterial, group, 0, 0.52, 0.15);
road.rotation.y = -0.12;
const buildingColors = [0xe4ddd0, 0x73888a, 0xc6a987, 0x6e7e8e];
const buildingData = [
{ x: -0.74, z: -0.36, w: 0.68, h: 1.62, d: 0.64 },
{ x: 0.02, z: 0.12, w: 0.76, h: 2.30, d: 0.68 },
{ x: 0.79, z: -0.22, w: 0.61, h: 1.30, d: 0.60 }
];
buildingData.forEach((building, index) => {
const material = standardMaterial(buildingColors[index]);
makeMesh(
new THREE.BoxGeometry(building.w, building.h, building.d),
material,
group,
building.x,
0.54 + building.h / 2,
building.z
);
const roof = makeMesh(
new THREE.BoxGeometry(building.w + 0.07, 0.08, building.d + 0.07),
standardMaterial(0x4f6060),
group,
building.x,
0.57 + building.h,
building.z
);
roof.castShadow = true;
const windowMaterial = standardMaterial(0xf6d88d, {
emissive: 0xe9ad4d,
emissiveIntensity: 0.28
});
for (let row = 0; row < Math.max(1, Math.floor(building.h / 0.48)); row++) {
const window = makeMesh(
new THREE.BoxGeometry(0.11, 0.14, 0.018),
windowMaterial,
group,
building.x,
0.78 + row * 0.42,
building.z + building.d / 2 + 0.012
);
window.castShadow = false;
}
});
makeMesh(new THREE.CylinderGeometry(0.025, 0.025, 0.50, 8), standardMaterial(0x475858), group, 0.02, 2.95, 0.12);
}
function createGauge(group, color) {
const gaugeGroup = new THREE.Group();
gaugeGroup.position.set(2.05, 0, 0.25);
group.add(gaugeGroup);
const base = makeMesh(
new THREE.CylinderGeometry(0.55, 0.60, 0.16, 24),
standardMaterial(0xbfc5bb),
gaugeGroup,
0,
0.16,
0
);
base.receiveShadow = true;
const track = makeMesh(
new THREE.CylinderGeometry(0.37, 0.37, 3.2, 24),
new THREE.MeshStandardMaterial({
color,
transparent: true,
opacity: 0.13,
roughness: 0.5,
depthWrite: false
}),
gaugeGroup,
0,
1.86,
0
);
track.castShadow = false;
const fillMaterial = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.10,
roughness: 0.55
});
const fill = makeMesh(
new THREE.CylinderGeometry(0.34, 0.34, 1, 24),
fillMaterial,
gaugeGroup,
0,
0.30,
0
);
fill.scale.y = 0.02;
const top = makeMesh(
new THREE.SphereGeometry(0.37, 18, 12),
fillMaterial,
gaugeGroup,
0,
0.32,
0
);
return {
group: gaugeGroup,
fill,
top,
height: 0.02,
targetHeight: 0.02
};
}
function createStation(key, buildModel) {
const destination = destinations[key];
const group = new THREE.Group();
group.position.set(destination.x, 0, -2.35);
scene.add(group);
const ring = addDestinationBase(group, destination.color);
buildModel(group);
const gauge = createGauge(group, destination.color);
const data = { key, group, ring, gauge, destination };
stationData.push(data);
return data;
}
createStation("alpine", buildAlpine);
createStation("coast", buildCoast);
createStation("city", buildCity);
// Thirty miniature students, grouped into four fixed ballot profiles.
const studentGroups = [];
const bodyGeometry = new THREE.CylinderGeometry(0.15, 0.18, 0.42, 8);
const headGeometry = new THREE.SphereGeometry(0.15, 12, 8);
const deskGeometry = new THREE.BoxGeometry(0.66, 0.07, 0.36);
const deskLegGeometry = new THREE.CylinderGeometry(0.035, 0.045, 0.56, 6);
const cardGeometry = new THREE.BoxGeometry(0.18, 0.24, 0.025);
const deskMaterial = standardMaterial(0xd4b78f);
const legMaterial = standardMaterial(0x74817d);
const skinMaterials = [
standardMaterial(0xe5b18b),
standardMaterial(0xb97952),
standardMaterial(0x8d5b42),
standardMaterial(0xf0c7a2)
];
const profileLayouts = [
{ x: -3.8, z: 2.35, cols: 5 },
{ x: 1.35, z: 2.55, cols: 4 },
{ x: 5.25, z: 2.75, cols: 2 },
{ x: -0.15, z: 4.72, cols: 3 }
];
function addStudent(x, z, profile, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const profileMaterial = standardMaterial(new THREE.Color(profile.color));
const body = makeMesh(bodyGeometry, profileMaterial, group, 0, 0.36, 0);
body.castShadow = true;
makeMesh(headGeometry, skinMaterials[index % skinMaterials.length], group, 0, 0.72, 0);
makeMesh(deskGeometry, deskMaterial, group, 0, 0.60, 0.24);
makeMesh(deskLegGeometry, legMaterial, group, 0, 0.29, 0.24);
const card = makeMesh(cardGeometry, profileMaterial, group, 0.14, 0.79, 0.205);
card.rotation.x = -0.17;
group.userData.phase = index * 0.37;
studentGroups.push(group);
}
ballotProfiles.forEach((profile, profileIndex) => {
const layout = profileLayouts[profileIndex];
const rows = Math.ceil(profile.count / layout.cols);
const width = layout.cols * 0.93 + 0.35;
const depth = rows * 0.88 + 0.40;
const matMaterial = standardMaterial(new THREE.Color(profile.color), {
transparent: true,
opacity: 0.17
});
const mat = makeMesh(
new THREE.BoxGeometry(width, 0.025, depth),
matMaterial,
scene,
layout.x,
0.04,
layout.z
);
mat.castShadow = false;
let studentIndex = 0;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < layout.cols; col++) {
if (studentIndex >= profile.count) break;
const x = layout.x + (col - (layout.cols - 1) / 2) * 0.93;
const z = layout.z + (row - (rows - 1) / 2) * 0.88;
addStudent(x, z, profile, studentIndex + profileIndex * 7);
studentIndex++;
}
}
});
// World-space HTML labels, projected manually without addons.
const labelEntries = [];
Object.entries(destinations).forEach(([key, destination], index) => {
const label = document.createElement("div");
label.className = "world-label destination-label";
label.style.setProperty("--c", destination.css);
label.innerHTML = `
<span class="world-rank">${index + 1}</span>
<div><strong>${destination.name}</strong><small></small></div>
`;
labelsElement.appendChild(label);
labelEntries.push({
element: label,
anchor: new THREE.Vector3(destination.x, 3.62, -2.35),
kind: "destination",
key
});
const gaugeLabel = document.createElement("div");
gaugeLabel.className = "world-label gauge-label";
gaugeLabel.style.setProperty("--c", destination.css);
labelsElement.appendChild(gaugeLabel);
labelEntries.push({
element: gaugeLabel,
anchor: new THREE.Vector3(destination.x + 2.05, 0.4, -2.10),
kind: "gauge",
key,
station: stationData[index]
});
});
const profileAnchors = [
new THREE.Vector3(-3.8, 1.28, 3.85),
new THREE.Vector3(1.35, 1.28, 3.55),
new THREE.Vector3(5.25, 1.28, 3.55),
new THREE.Vector3(-0.15, 1.25, 5.30)
];
ballotProfiles.forEach((profile, index) => {
const label = document.createElement("div");
label.className = "world-label ballot-world";
label.style.setProperty("--c", profile.color);
const ranks = profile.order.map(key => destinations[key].short).join(" > ");
label.innerHTML = `<i></i><span>${profile.count} · ${ranks}</span>`;
labelsElement.appendChild(label);
labelEntries.push({
element: label,
anchor: profileAnchors[index],
kind: "profile"
});
});
function projectLabel(entry) {
const projected = entry.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
entry.element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * sceneElement.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * sceneElement.clientHeight;
entry.element.style.left = `${x}px`;
entry.element.style.top = `${y}px`;
}
// Build side-panel tables from the same source data used by the scene.
const scoreRows = document.getElementById("scoreRows");
Object.entries(destinations).forEach(([key, destination]) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>
<span class="dest-name">
<span class="dest-dot" style="background:${destination.css}"></span>
${destination.name}
</span>
</td>
<td class="score-cell active" data-cell-method="plurality">
<strong>${methods.plurality.values[key]}</strong>
<small>${Math.round(methods.plurality.values[key] / methods.plurality.max * 100)}% of 30</small>
<div class="mini-track" style="--c:${destination.css};--w:${methods.plurality.values[key] / methods.plurality.max * 100}%"><span></span></div>
</td>
<td class="score-cell" data-cell-method="borda">
<strong>${methods.borda.values[key]}</strong>
<small>${Math.round(methods.borda.values[key] / methods.borda.max * 100)}% of 90</small>
<div class="mini-track" style="--c:${destination.css};--w:${methods.borda.values[key] / methods.borda.max * 100}%"><span></span></div>
</td>
`;
scoreRows.appendChild(row);
});
const ballotRows = document.getElementById("ballotRows");
ballotProfiles.forEach(profile => {
const row = document.createElement("tr");
row.innerHTML = `
<td>
<span class="student-count"><i style="--c:${profile.color}"></i>${profile.count}</span>
</td>
${profile.order.map((key, index) => `
<td><span class="rank-chip ${index === 0 ? "first" : ""}">${destinations[key].short}</span></td>
`).join("")}
`;
ballotRows.appendChild(row);
});
let currentMethod = "plurality";
let pulse = 0;
function updateWorldLabels() {
const method = methods[currentMethod];
labelEntries.forEach(entry => {
if (entry.kind === "destination") {
const value = method.values[entry.key];
const percent = Math.round(value / method.max * 100);
entry.element.querySelector("small").textContent =
`${value} ${method.unit} · ${percent}% of max`;
}
if (entry.kind === "gauge") {
const value = method.values[entry.key];
entry.element.textContent = `${value} ${method.unit}`;
entry.anchor.set(
entry.station.group.position.x + 2.05,
0.42 + entry.station.gauge.height,
entry.station.group.position.z + 0.25
);
}
});
}
function setMethod(methodKey, announce = true) {
if (!methods[methodKey]) return;
currentMethod = methodKey;
const method = methods[methodKey];
document.querySelectorAll("[data-set-method]").forEach(button => {
const active = button.dataset.setMethod === methodKey;
button.classList.toggle("active", active);
if (button.getAttribute("role") === "tab") {
button.setAttribute("aria-selected", String(active));
} else {
button.setAttribute("aria-pressed", String(active));
}
});
document.querySelectorAll("[data-cell-method]").forEach(cell => {
cell.classList.toggle("active", cell.dataset.cellMethod === methodKey);
});
document.getElementById("methodTitle").textContent = method.label;
document.getElementById("methodDescription").textContent = method.description;
document.getElementById("methodFormula").textContent = method.formula;
const winnerFlag = document.getElementById("winnerFlag");
winnerFlag.innerHTML = `
<small>${method.label} winner</small>
<strong>${destinations[method.winner].name}</strong>
`;
stationData.forEach(station => {
const normalized = method.values[station.key] / method.max;
station.gauge.targetHeight = Math.max(0.06, normalized * 3.05);
station.ring.userData.targetOpacity =
station.key === method.winner ? 0.92 : 0.08;
});
drawBoard(methodKey);
updateWorldLabels();
pulse = reducedMotion ? 0 : 1;
if (announce) {
document.getElementById("liveRegion").textContent =
`${method.label}. ${destinations[method.winner].name} wins with ${method.values[method.winner]} ${method.unit}.`;
}
}
document.querySelectorAll("[data-set-method]").forEach(button => {
button.addEventListener("click", () => setMethod(button.dataset.setMethod));
});
document.getElementById("replayButton").addEventListener("click", () => {
stationData.forEach(station => {
station.gauge.height = 0.02;
station.gauge.fill.scale.y = 0.02;
});
setMethod(currentMethod);
});
// Direct camera controls: pointer drag, wheel zoom, and buttons.
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraSpherical.theta -= dx * 0.005;
cameraSpherical.phi -= dy * 0.004;
cameraSpherical.phi = THREE.MathUtils.clamp(cameraSpherical.phi, 0.58, 1.42);
velocityTheta = -dx * 0.0025;
velocityPhi = -dy * 0.0018;
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraSpherical.radius *= Math.exp(event.deltaY * 0.001);
cameraSpherical.radius = THREE.MathUtils.clamp(cameraSpherical.radius, 11, 31);
}, { passive: false });
function resetCamera() {
cameraSpherical.set(21, 1.12, 0.40);
velocityTheta = 0;
velocityPhi = 0;
}
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("resetCamera").addEventListener("click", resetCamera);
document.getElementById("zoomIn").addEventListener("click", () => {
cameraSpherical.radius = THREE.MathUtils.clamp(cameraSpherical.radius - 1.4, 11, 31);
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraSpherical.radius = THREE.MathUtils.clamp(cameraSpherical.radius + 1.4, 11, 31);
});
function resize() {
const width = sceneElement.clientWidth;
const height = sceneElement.clientHeight;
if (!width || !height) return;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(sceneElement);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!dragging) {
cameraSpherical.theta += velocityTheta;
cameraSpherical.phi += velocityPhi;
velocityTheta *= Math.pow(0.08, dt);
velocityPhi *= Math.pow(0.08, dt);
}
cameraSpherical.phi = THREE.MathUtils.clamp(cameraSpherical.phi, 0.58, 1.42);
cameraSpherical.radius = THREE.MathUtils.clamp(cameraSpherical.radius, 11, 31);
updateCamera();
const easing = reducedMotion ? 1 : 1 - Math.exp(-dt * 6);
stationData.forEach(station => {
station.gauge.height +=
(station.gauge.targetHeight - station.gauge.height) * easing;
station.gauge.fill.scale.y = Math.max(0.02, station.gauge.height);
station.gauge.fill.position.y = 0.29 + station.gauge.height / 2;
station.gauge.top.position.y = 0.31 + station.gauge.height;
const targetOpacity = station.ring.userData.targetOpacity ?? 0.08;
station.ring.material.opacity +=
(targetOpacity - station.ring.material.opacity) * easing;
const ringScale = 1 + Math.sin(performance.now() * 0.0025 + station.group.position.x) * 0.012;
station.ring.scale.setScalar(ringScale);
});
if (pulse > 0) {
pulse = Math.max(0, pulse - dt * 1.25);
const offset = Math.sin(pulse * Math.PI) * 0.11;
studentGroups.forEach((group, index) => {
group.position.y = offset * (0.8 + 0.2 * Math.sin(index));
});
} else {
studentGroups.forEach(group => { group.position.y = 0; });
}
scene.updateMatrixWorld();
updateWorldLabels();
renderer.render(scene, camera);
}
setMethod("plurality", false);
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```