Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Park Proposal Meeting" 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: Neighborhood Park Proposal Meeting
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-park-proposal-meeting-x3207
Scene Description Prompt:
Voxel neighbors compare park models and vote on a ballot board, keeping criteria and minority preferences visible. Create standalone HTML with Three.js from cdnjs.
Working Three.js Starter (neighborhood-park-proposal-meeting-x3207):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Parklot — Neighborhood Park Ballot</title>
<style>
:root {
--ink: #183330;
--muted: #667873;
--paper: #f5f2e9;
--panel: #fffdf7;
--line: #d9ded5;
--green: #4f7e5a;
--orange: #dc754e;
--blue: #568ba0;
--teal: #4b9c91;
--gold: #d7a342;
--shadow: 0 16px 40px rgba(27, 54, 47, 0.12);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { overflow: hidden; }
button {
font: inherit;
color: inherit;
cursor: pointer;
}
.app {
min-height: 100%;
display: grid;
grid-template-rows: 72px 1fr;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
background: var(--panel);
border-bottom: 1px solid var(--line);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
width: 16px;
height: 16px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-mark i:nth-child(1) { left: 0; top: 11px; background: #79a66c; }
.brand-mark i:nth-child(2) { left: 11px; top: 0; background: #e18a61; }
.brand-mark i:nth-child(3) { left: 11px; top: 22px; background: #60949b; }
.brand h1 {
margin: 0;
font-size: 20px;
line-height: 1;
letter-spacing: -.5px;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.top-meta {
display: flex;
align-items: center;
gap: 10px;
}
.pill {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 32px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: #f8f7f0;
color: #52635e;
font-size: 12px;
font-weight: 650;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #59a46f;
box-shadow: 0 0 0 4px rgba(89,164,111,.13);
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: 278px minmax(480px, 1fr) 370px;
}
.panel {
min-height: 0;
overflow-y: auto;
padding: 22px 20px;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #cbd2c8 transparent;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 7px;
color: #74827d;
font-size: 10px;
font-weight: 800;
letter-spacing: 1.35px;
text-transform: uppercase;
}
h2 {
margin: 0;
font-size: 20px;
letter-spacing: -.45px;
}
h3 {
margin: 0;
font-size: 13px;
letter-spacing: -.1px;
}
.brief {
margin: 10px 0 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.section {
margin-top: 23px;
padding-top: 20px;
border-top: 1px solid var(--line);
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-note {
color: #8a9690;
font-size: 10px;
font-weight: 700;
}
.criteria-list {
display: grid;
gap: 8px;
}
.criterion {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 11px;
border: 1px solid #e2e5de;
border-radius: 10px;
background: #faf9f3;
}
.criterion-color {
width: 7px;
height: 27px;
border-radius: 8px;
}
.criterion strong {
display: block;
font-size: 12px;
}
.criterion small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10.5px;
}
.weight {
padding: 4px 7px;
border-radius: 6px;
background: #edf0e9;
color: #6c7873;
font-size: 9px;
font-weight: 800;
}
.pulse-card {
padding: 14px;
border-radius: 13px;
background: var(--ink);
color: #fff;
}
.pulse-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.pulse-number {
font-size: 24px;
font-weight: 750;
letter-spacing: -1px;
}
.pulse-label {
color: #b9c9c4;
font-size: 11px;
}
.progress {
height: 6px;
margin: 12px 0 9px;
overflow: hidden;
border-radius: 8px;
background: #39504b;
}
.progress > span {
display: block;
width: 97%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #70ae7c, #d9b85b);
transition: width .35s ease;
}
.avatar-row {
display: flex;
align-items: center;
}
.avatar {
width: 25px;
height: 25px;
margin-right: -5px;
border: 2px solid var(--ink);
border-radius: 50%;
background: #d98462;
}
.avatar:nth-child(2) { background: #7fa3ca; }
.avatar:nth-child(3) { background: #8eb375; }
.avatar:nth-child(4) { background: #d2ae58; }
.avatar:nth-child(5) { background: #a990b2; }
.avatar.more {
display: grid;
place-items: center;
width: 28px;
height: 28px;
margin-left: 7px;
border: 0;
background: #344b46;
color: #d6e1dd;
font-size: 9px;
}
.voice-list {
display: grid;
gap: 9px;
}
.voice {
position: relative;
padding: 11px 12px 11px 14px;
overflow: hidden;
border: 1px solid #e2e5de;
border-radius: 10px;
background: #fbfaf5;
}
.voice::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--voice-color);
}
.voice-top {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
}
.voice-top span:first-child {
color: #7a8782;
font-size: 9px;
font-weight: 850;
letter-spacing: .8px;
text-transform: uppercase;
}
.voice-top span:last-child {
color: #8c9893;
font-size: 9.5px;
}
.voice p {
margin: 0;
font-size: 11.5px;
font-weight: 650;
line-height: 1.4;
}
.voice small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.visibility-note {
display: flex;
gap: 8px;
margin-top: 10px;
padding: 10px;
border-radius: 9px;
background: #edf3e8;
color: #55705a;
font-size: 10px;
line-height: 1.4;
}
.rules {
display: grid;
gap: 8px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.4;
}
.rule {
display: flex;
justify-content: space-between;
gap: 12px;
}
.rule b { color: var(--ink); }
.scene-shell {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dce6df;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.scene-intro {
position: absolute;
z-index: 2;
top: 20px;
left: 22px;
max-width: 295px;
padding: 13px 15px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 13px;
background: rgba(255,253,247,.87);
box-shadow: 0 10px 30px rgba(29,59,51,.1);
backdrop-filter: blur(8px);
pointer-events: none;
}
.scene-intro .eyebrow { margin-bottom: 5px; }
.scene-intro h2 {
font-size: 17px;
}
.scene-intro p {
margin: 5px 0 0;
color: #65756f;
font-size: 10.5px;
line-height: 1.4;
}
.scene-toolbar {
position: absolute;
z-index: 3;
top: 20px;
right: 20px;
display: flex;
gap: 6px;
padding: 5px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 11px;
background: rgba(255,253,247,.9);
box-shadow: 0 10px 30px rgba(29,59,51,.1);
backdrop-filter: blur(8px);
}
.tool-button {
height: 32px;
padding: 0 11px;
border: 0;
border-radius: 7px;
background: transparent;
color: #5d6d67;
font-size: 10.5px;
font-weight: 750;
}
.tool-button:hover,
.tool-button[aria-pressed="true"] {
background: var(--ink);
color: #fff;
}
.scene-bottom {
position: absolute;
z-index: 2;
right: 20px;
bottom: 18px;
left: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
max-width: 390px;
padding: 9px 11px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 9px;
background: rgba(255,253,247,.84);
backdrop-filter: blur(7px);
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
color: #5d6b66;
font-size: 9px;
font-weight: 700;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.camera-hint {
padding: 8px 10px;
border-radius: 8px;
background: rgba(24,51,48,.82);
color: #e9f0ed;
font-size: 9px;
font-weight: 650;
backdrop-filter: blur(6px);
}
.ballot-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.round-tag {
margin-top: 2px;
padding: 5px 8px;
border-radius: 7px;
background: #edf1e9;
color: #697972;
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.ballot-status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 15px 0 13px;
padding: 11px 12px;
border-radius: 10px;
background: #f1f4ec;
}
.ballot-status strong {
display: block;
font-size: 12px;
}
.ballot-status small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.status-number {
font-size: 20px;
font-weight: 800;
letter-spacing: -.8px;
}
.matrix {
overflow: hidden;
border: 1px solid #dce1d8;
border-radius: 12px;
background: #fffef9;
}
.matrix-head,
.matrix-row {
display: grid;
grid-template-columns: 112px repeat(4, minmax(49px, 1fr));
}
.matrix-head {
min-height: 52px;
background: #f3f3ec;
}
.matrix-head > div {
display: flex;
align-items: flex-end;
justify-content: center;
padding: 9px 5px;
border-left: 1px solid #e1e5dd;
color: #72807b;
font-size: 9px;
font-weight: 800;
line-height: 1.15;
text-align: center;
}
.matrix-head > div:first-child {
align-items: center;
justify-content: flex-start;
padding-left: 12px;
border-left: 0;
letter-spacing: .7px;
text-transform: uppercase;
}
.matrix-row {
min-height: 67px;
border-top: 1px solid #e2e6de;
transition: background .18s ease;
}
.matrix-row.selected {
background: #f5f8ef;
box-shadow: inset 3px 0 0 var(--selected-color);
}
.candidate-cell {
display: flex;
flex-direction: column;
justify-content: center;
min-width: 0;
padding: 9px 8px 9px 12px;
border: 0;
background: transparent;
text-align: left;
}
.candidate-title {
display: flex;
align-items: center;
gap: 6px;
font-size: 10.5px;
font-weight: 800;
line-height: 1.2;
}
.candidate-code {
display: inline-grid;
place-items: center;
width: 18px;
height: 18px;
flex: 0 0 auto;
border-radius: 5px;
background: var(--candidate-color);
color: white;
font-size: 9px;
font-weight: 850;
}
.candidate-votes {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.score-cell {
display: grid;
place-items: center;
padding: 0;
border: 0;
border-left: 1px solid #e4e7df;
background: transparent;
}
.score-cell:hover { background: #f0f3eb; }
.pips {
display: flex;
gap: 3px;
}
.pips i {
width: 7px;
height: 7px;
border: 1px solid #c9d0c6;
border-radius: 2px;
background: transparent;
}
.pips i.on {
border-color: var(--score-color);
background: var(--score-color);
}
.matrix-help {
margin: 9px 2px 0;
color: #84908b;
font-size: 9.5px;
line-height: 1.4;
}
.tally-list {
display: grid;
gap: 10px;
margin-top: 20px;
}
.tally-item {
display: grid;
grid-template-columns: 21px 1fr auto;
align-items: center;
gap: 8px;
}
.tally-color {
width: 9px;
height: 9px;
border-radius: 3px;
}
.tally-name {
font-size: 10.5px;
font-weight: 750;
}
.tally-bar {
grid-column: 2 / 4;
height: 5px;
margin-top: -5px;
overflow: hidden;
border-radius: 5px;
background: #e8ebe4;
}
.tally-bar span {
display: block;
height: 100%;
border-radius: inherit;
transition: width .35s ease;
}
.tally-count {
font-size: 10px;
font-weight: 800;
}
.vote-box {
margin-top: 22px;
padding-top: 19px;
border-top: 1px solid var(--line);
}
.current-vote {
min-height: 34px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.current-vote b { color: var(--ink); }
.vote-button {
width: 100%;
min-height: 47px;
padding: 10px 14px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: white;
font-size: 12px;
font-weight: 800;
box-shadow: 0 8px 18px rgba(24,51,48,.15);
transition: transform .15s ease, background .15s ease;
}
.vote-button:hover {
transform: translateY(-1px);
background: #244a43;
}
.vote-button:disabled {
cursor: default;
opacity: .72;
transform: none;
}
.vote-note {
margin: 9px 0 0;
color: #86918c;
font-size: 9.5px;
line-height: 1.45;
text-align: center;
}
@media (max-width: 1120px) {
.workspace { grid-template-columns: 245px minmax(430px, 1fr) 340px; }
.panel { padding: 19px 16px; }
.matrix-head, .matrix-row { grid-template-columns: 105px repeat(4, minmax(46px, 1fr)); }
.scene-intro { max-width: 250px; }
}
@media (max-width: 900px) {
body { overflow: auto; }
.app { grid-template-rows: 64px auto; }
.topbar { padding: 0 15px; }
.top-meta .pill:nth-child(2) { display: none; }
.workspace {
display: flex;
flex-direction: column;
}
.scene-shell {
order: -1;
height: 62vh;
min-height: 480px;
}
.panel {
overflow: visible;
border: 0;
border-top: 1px solid var(--line);
}
.right-panel { border-top: 1px solid var(--line); }
.matrix-head, .matrix-row { grid-template-columns: 140px repeat(4, 1fr); }
}
@media (max-width: 560px) {
.brand p { display: none; }
.top-meta .pill:first-of-type { display: none; }
.scene-intro { top: 12px; left: 12px; max-width: 205px; }
.scene-toolbar { top: 12px; right: 12px; flex-direction: column; }
.tool-button { height: 27px; padding: 0 9px; }
.camera-hint { display: none; }
.matrix-head, .matrix-row { grid-template-columns: 110px repeat(4, minmax(50px, 1fr)); }
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div>
<h1>Parklot</h1>
<p>Riverside Commons · Block 4 neighborhood ballot</p>
</div>
</div>
<div class="top-meta">
<span class="pill"><span class="live-dot"></span> Ballot open</span>
<span class="pill">31 neighbors</span>
<span class="pill">Round 1 of 2</span>
</div>
</header>
<main class="workspace">
<aside class="panel left-panel">
<p class="eyebrow">Decision brief</p>
<h2>One block, three visions.</h2>
<p class="brief">
Compare the park models, score every public criterion, and cast one
neighborhood recommendation.
</p>
<section class="section">
<div class="section-head">
<h3>Scoring criteria</h3>
<span class="section-note">Always visible</span>
</div>
<div class="criteria-list" id="criteria-list"></div>
</section>
<section class="section">
<div class="section-head">
<h3>Community pulse</h3>
<span class="section-note" id="pulse-label">30 of 31 cast</span>
</div>
<div class="pulse-card">
<div class="pulse-top">
<div>
<div class="pulse-number" id="pulse-number">30</div>
<div class="pulse-label">neighbors have reviewed all plans</div>
</div>
<span class="live-dot"></span>
</div>
<div class="progress"><span id="pulse-progress"></span></div>
<div class="avatar-row" aria-label="A sample of participating neighbors">
<span class="avatar"></span>
<span class="avatar"></span>
<span class="avatar"></span>
<span class="avatar"></span>
<span class="avatar"></span>
<span class="avatar more">+26</span>
</div>
</div>
</section>
<section class="section">
<div class="section-head">
<h3>Minority preferences</h3>
<span class="section-note">Not filtered</span>
</div>
<div class="voice-list">
<article class="voice" style="--voice-color:#75a768">
<div class="voice-top"><span>Quiet use</span><span>4 neighbors</span></div>
<p>“Keep a calm corner near the entrance.”</p>
<small>Best served by Meadow Loop's pollinator edge.</small>
</article>
<article class="voice" style="--voice-color:#5d91a6">
<div class="voice-top"><span>Step-free access</span><span>3 neighbors</span></div>
<p>“A smooth route matters more than a shortcut.”</p>
<small>Best served by Rain Garden's continuous boardwalk.</small>
</article>
<article class="voice" style="--voice-color:#dc754e">
<div class="voice-top"><span>Active play</span><span>2 neighbors</span></div>
<p>“Please keep room for a lively play space.”</p>
<small>Best served by Canopy Commons' central play court.</small>
</article>
</div>
<div class="visibility-note">
<span aria-hidden="true">◉</span>
<span>These views remain on the record even when they do not form a majority.</span>
</div>
</section>
<section class="section">
<div class="section-head"><h3>How the result is read</h3></div>
<div class="rules">
<div class="rule"><span>Majority threshold</span><b>16 of 31</b></div>
<div class="rule"><span>If tied</span><b>Second choice breaks tie</b></div>
<div class="rule"><span>Minority views</span><b>Published with result</b></div>
</div>
</section>
</aside>
<section class="scene-shell" aria-label="Interactive three-dimensional park models">
<div id="scene"></div>
<div class="scene-intro">
<p class="eyebrow">Model table · live comparison</p>
<h2>Select a plan to inspect it</h2>
<p>Each colored post shows the neighborhood's score for a criterion.</p>
</div>
<div class="scene-toolbar" aria-label="Camera controls">
<button class="tool-button" id="reset-view" title="Reset camera">Overview</button>
<button class="tool-button" id="top-view" title="View from above">Top</button>
<button class="tool-button" id="auto-rotate" aria-pressed="false" title="Automatically orbit">Orbit</button>
</div>
<div class="scene-bottom">
<div class="legend" aria-label="Criterion color legend">
<span><i style="background:#75a768"></i>Canopy</span>
<span><i style="background:#dc8b56"></i>Play</span>
<span><i style="background:#5d91a6"></i>Access</span>
<span><i style="background:#4b9c91"></i>Water</span>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Click a model</div>
</div>
</section>
<aside class="panel right-panel">
<div class="ballot-heading">
<div>
<p class="eyebrow">Neighborhood ballot</p>
<h2>Score the plans</h2>
</div>
<span class="round-tag">Open</span>
</div>
<div class="ballot-status">
<div>
<strong>Every criterion counts</strong>
<small>Choose 0–4 alignment for each plan.</small>
</div>
<div class="status-number" id="cast-count">30/31</div>
</div>
<div class="matrix" id="matrix"></div>
<p class="matrix-help">Click a score cell to cycle 0–4. Select a candidate name to focus its model.</p>
<section class="tally-list" id="tally-list" aria-label="Current ballot tally"></section>
<section class="vote-box">
<p class="eyebrow">Your recommendation</p>
<div class="current-vote" id="current-vote" aria-live="polite">
No vote cast yet. Select a plan, then confirm below.
</div>
<button class="vote-button" id="vote-button">Back Meadow Loop</button>
<p class="vote-note">You can change your recommendation before the round closes.</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const criteria = [
{
id: "canopy",
short: "Canopy",
label: "Canopy & habitat",
description: "Shade, native habitat, pollinator value",
color: "#75a768",
weight: "2×"
},
{
id: "play",
short: "Play",
label: "Play & gathering",
description: "Active play, seating, community use",
color: "#dc8b56",
weight: "2×"
},
{
id: "access",
short: "Access",
label: "Step-free access",
description: "Continuous accessible routes and surfaces",
color: "#5d91a6",
weight: "1×"
},
{
id: "water",
short: "Water",
label: "Stormwater",
description: "Rain capture, shade, native planting",
color: "#4b9c91",
weight: "1×"
}
];
const candidates = [
{
id: "meadow",
code: "A",
name: "Meadow Loop",
subtitle: "Calm green + pollinator garden",
color: "#6f9f63",
votes: 12
},
{
id: "canopy",
code: "B",
name: "Canopy Commons",
subtitle: "Shaded play + shared tables",
color: "#d87d57",
votes: 10
},
{
id: "rain",
code: "C",
name: "Rain Garden",
subtitle: "Wetland loop + step-free boardwalk",
color: "#4b8f98",
votes: 8
}
];
const defaultScores = {
meadow: { canopy: 3, play: 2, access: 3, water: 2 },
canopy: { canopy: 4, play: 4, access: 2, water: 3 },
rain: { canopy: 2, play: 3, access: 4, water: 4 }
};
const state = {
selected: "meadow",
userVote: null,
scores: structuredClone(defaultScores)
};
try {
const saved = JSON.parse(localStorage.getItem("parklot-ballot") || "null");
if (saved?.userVote && candidates.some(c => c.id === saved.userVote)) {
state.userVote = saved.userVote;
}
if (saved?.scores) {
for (const candidate of candidates) {
for (const criterion of criteria) {
const value = saved.scores?.[candidate.id]?.[criterion.id];
if (Number.isInteger(value) && value >= 0 && value <= 4) {
state.scores[candidate.id][criterion.id] = value;
}
}
}
}
} catch (_) {}
const criteriaList = document.getElementById("criteria-list");
criteriaList.innerHTML = criteria.map(c => `
<div class="criterion">
<span class="criterion-color" style="background:${c.color}"></span>
<div>
<strong>${c.label}</strong>
<small>${c.description}</small>
</div>
<span class="weight">${c.weight}</span>
</div>
`).join("");
const matrix = document.getElementById("matrix");
matrix.innerHTML = `
<div class="matrix-head">
<div>Plan</div>
${criteria.map(c => `<div style="color:${c.color}" title="${c.label}">${c.short}</div>`).join("")}
</div>
${candidates.map(candidate => `
<div class="matrix-row" data-candidate="${candidate.id}">
<button class="candidate-cell" data-select="${candidate.id}" style="--candidate-color:${candidate.color}">
<span class="candidate-title">
<span class="candidate-code">${candidate.code}</span>
${candidate.name}
</span>
<span class="candidate-votes" data-votes="${candidate.id}"></span>
</button>
${criteria.map(criterion => `
<button
class="score-cell"
data-score-candidate="${candidate.id}"
data-score-criterion="${criterion.id}"
style="--score-color:${criterion.color}"
aria-label="${candidate.name}, ${criterion.label} score">
<span class="pips">
${[0,1,2,3].map(i => `<i></i>`).join("")}
</span>
</button>
`).join("")}
</div>
`).join("")}
`;
const tallyList = document.getElementById("tally-list");
tallyList.innerHTML = candidates.map(candidate => `
<div class="tally-item">
<span class="tally-color" style="background:${candidate.color}"></span>
<span class="tally-name">${candidate.name}</span>
<span class="tally-count" data-tally="${candidate.id}"></span>
<span class="tally-bar"><span data-bar="${candidate.id}" style="background:${candidate.color}"></span></span>
</div>
`).join("");
const sceneElement = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce6df");
scene.fog = new THREE.Fog("#dce6df", 25, 47);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(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.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "3D park model viewer. Drag to orbit and scroll to zoom.");
sceneElement.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight("#fff9e8", "#6e8e7d", 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0d2", 3.0);
sun.position.set(8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d8dc", 0.7);
fill.position.set(-10, 8, -8);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshLambertMaterial({ color }));
}
return materialCache.get(color);
}
function box(parent, w, h, d, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function voxelTree(parent, x, z, scale = 1, crown = "#6d9b5f") {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, .28, 1.1, .28, 0, .55, 0, "#84674b");
box(group, 1.05, .7, 1.05, 0, 1.35, 0, crown);
box(group, .7, .62, .7, -.22, 1.82, .05, "#7daa68");
box(group, .62, .52, .62, .28, 1.75, -.15, "#5f8e58");
return group;
}
function voxelPerson(parent, x, z, color, phase = 0) {
const group = new THREE.Group();
group.position.set(x, .48, z);
parent.add(group);
box(group, .18, .34, .2, -.13, .17, 0, "#334d50");
box(group, .18, .34, .2, .13, .17, 0, "#334d50");
box(group, .52, .58, .34, 0, .63, 0, color);
box(group, .15, .48, .18, -.34, .61, 0, color);
box(group, .15, .48, .18, .34, .61, 0, color);
box(group, .42, .42, .4, 0, 1.12, 0, "#d9ad83");
box(group, .46, .16, .42, 0, 1.34, -.02, "#54443b");
group.userData.phase = phase;
group.userData.baseY = .48;
people.push(group);
return group;
}
function bench(parent, x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, .48, z);
group.rotation.y = rotation;
parent.add(group);
box(group, 1.1, .12, .34, 0, .4, 0, "#9b704e");
box(group, 1.1, .45, .1, 0, .67, -.16, "#a87951");
box(group, .1, .4, .3, -.42, .2, 0, "#56625a");
box(group, .1, .4, .3, .42, .2, 0, "#56625a");
return group;
}
const ground = box(scene, 27, .45, 19, 0, -.3, -.6, "#cbd7c8", false);
ground.receiveShadow = true;
const grid = new THREE.GridHelper(26, 26, "#a8bbb0", "#b7c7bc");
grid.position.y = -.065;
grid.material.transparent = true;
grid.material.opacity = .28;
scene.add(grid);
box(scene, 25, .08, 2.2, 0, -.02, -6.25, "#aebbb2", false);
box(scene, 2.2, .08, 15.8, -11.3, -.01, -.3, "#b5c0b7", false);
box(scene, 2.2, .08, 15.8, 11.3, -.01, -.3, "#b5c0b7", false);
// Distant neighborhood blocks.
for (let i = 0; i < 6; i++) {
const x = -10 + i * 4;
const h = 1.1 + (i % 3) * .35;
box(scene, 2.1, h, 1.4, x, h / 2 - .05, -7.6, i % 2 ? "#b8c8bd" : "#c4cfc4", false);
}
const candidateGroups = {};
const people = [];
const labels = {};
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(candidate) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(0, 3.2, -.05);
sprite.scale.set(3.45, .81, 1);
sprite.userData.canvas = canvas;
sprite.userData.texture = texture;
candidateGroups[candidate.id].add(sprite);
labels[candidate.id] = sprite;
updateLabel(candidate.id);
}
function updateLabel(id) {
const candidate = candidates.find(c => c.id === id);
const sprite = labels[id];
if (!sprite) return;
const canvas = sprite.userData.canvas;
const ctx = canvas.getContext("2d");
const count = getCounts()[id];
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(20,45,40,.22)";
ctx.shadowBlur = 14;
ctx.shadowOffsetY = 6;
roundedRect(ctx, 8, 8, 624, 132, 22);
ctx.fillStyle = "rgba(255,253,247,.97)";
ctx.fill();
ctx.shadowColor = "transparent";
roundedRect(ctx, 26, 30, 72, 72, 14);
ctx.fillStyle = candidate.color;
ctx.fill();
ctx.fillStyle = "#fff";
ctx.font = "800 30px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(candidate.code, 62, 67);
ctx.textAlign = "left";
ctx.fillStyle = "#183330";
ctx.font = "800 31px system-ui";
ctx.fillText(candidate.name, 120, 55);
ctx.fillStyle = "#74827d";
ctx.font = "500 20px system-ui";
ctx.fillText(candidate.subtitle, 120, 91);
ctx.textAlign = "right";
ctx.fillStyle = "#183330";
ctx.font = "800 29px system-ui";
ctx.fillText(`${count} votes`, 604, 57);
ctx.fillStyle = "#74827d";
ctx.font = "600 18px system-ui";
ctx.fillText(id === state.selected ? "SELECTED PLAN" : "CLICK TO INSPECT", 604, 91);
sprite.userData.texture.needsUpdate = true;
}
function addScorePosts(group) {
const bars = [];
criteria.forEach((criterion, index) => {
const x = -1.23 + index * .82;
box(group, .53, .12, .36, x, .61, 2.05, "#e8e2cf");
const bar = box(group, .28, .6, .27, x, .9, 2.05, criterion.color);
bars.push(bar);
});
group.userData.scoreBars = bars;
}
function createCandidate(candidate, x) {
const group = new THREE.Group();
group.position.set(x, 0, .55);
group.userData.candidateId = candidate.id;
scene.add(group);
candidateGroups[candidate.id] = group;
box(group, 4.55, .42, 4.35, 0, .22, 0, "#b9a98b");
box(group, 4.22, .16, 4.02, 0, .48, 0, candidate.id === "rain" ? "#83a978" : "#8eb173");
box(group, .15, .16, 4.02, -2.06, .48, 0, "#e7dfc9");
box(group, .15, .16, 4.02, 2.06, .48, 0, "#e7dfc9");
box(group, 4.22, .16, .15, 0, .48, -1.96, "#e7dfc9");
box(group, 4.22, .16, .15, 0, .48, 1.96, "#e7dfc9");
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(4.58, .44, 4.38)),
new THREE.LineBasicMaterial({ color: "#f7d16f", transparent: true, opacity: .95 })
);
edges.position.y = .23;
edges.visible = false;
group.add(edges);
group.userData.selectionEdges = edges;
addScorePosts(group);
group.traverse(object => {
object.userData.candidateId = candidate.id;
});
return group;
}
const meadow = createCandidate(candidates[0], -4.55);
const canopy = createCandidate(candidates[1], 0);
const rain = createCandidate(candidates[2], 4.55);
// Meadow Loop: meadow, winding path, pond and pollinator planting.
for (let x = -1.6; x <= 1.7; x += .42) {
box(meadow, .43, .07, .42, x, .61, 1.35, "#d8c596", false);
}
for (let z = -1.5; z <= 1.4; z += .42) {
box(meadow, .43, .07, .42, 1.35, .61, z, "#d8c596", false);
}
box(meadow, 1.2, .08, 1.05, -.95, .61, -.65, "#62a4b0", false);
box(meadow, .65, .08, 1.05, -.35, .61, -.65, "#70b3ba", false);
box(meadow, .38, .08, .55, -.95, .65, -.65, "#8bc7c5", false);
voxelTree(meadow, 1.35, -1.15, .9, "#618e55");
voxelTree(meadow, -1.55, -1.15, .72, "#719d5d");
voxelTree(meadow, 1.6, .15, .62, "#719d5d");
[
[-1.6,.4,"#e3bd55"], [-1.15,.5,"#d97d77"], [-.65,.75,"#e9c657"],
[.2,.45,"#d98179"], [.75,-.05,"#e4bb56"], [-.05,-1.25,"#d87975"]
].forEach(([px,pz,color]) => {
box(meadow, .16, .22, .16, px, .76, pz, color);
box(meadow, .11, .18, .11, px, .63, pz, "#6e9959", false);
});
bench(meadow, -.55, 1.15, 0);
bench(meadow, -.2, -1.35, Math.PI);
voxelPerson(meadow, -1.8, 1.55, "#d87b61", .4);
voxelPerson(meadow, .55, 1.55, "#6f9db9", 1.5);
voxelPerson(meadow, 1.8, .85, "#c8a654", 2.3);
// Canopy Commons: dense trees, play court and shared tables.
voxelTree(canopy, -1.45, -1.25, 1.03, "#537e50");
voxelTree(canopy, -.1, -1.35, 1.08, "#5c8954");
voxelTree(canopy, 1.45, -1.2, .95, "#527b4d");
voxelTree(canopy, -1.55, .85, .84, "#608e56");
voxelTree(canopy, 1.55, .85, .83, "#608e56");
box(canopy, 2.2, .08, 1.55, 0, .61, .25, "#d98b5d", false);
box(canopy, 1.5, .09, 1.05, .45, .66, .3, "#e9a269", false);
box(canopy, .75, .62, .75, -.72, .96, .32, "#e2b85e");
box(canopy, 1.05, .18, .45, -.45, 1.3, .32, "#d66f56");
box(canopy, .25, .75, .25, -.05, 1.0, .32, "#668d70");
box(canopy, .9, .12, .9, 1.15, 1.04, -.2, "#b67a54");
box(canopy, .12, .48, .12, .85, .77, -.2, "#6a6758");
box(canopy, .12, .48, .12, 1.45, .77, -.2, "#6a6758");
bench(canopy, -.75, 1.38, 0);
bench(canopy, .65, 1.38, 0);
voxelPerson(canopy, -1.85, 1.45, "#6d9eb4", .8);
voxelPerson(canopy, .05, 1.55, "#d27a66", 2.1);
voxelPerson(canopy, 1.85, 1.45, "#779c6c", 3.0);
// Rain Garden: blue wetland, planted cells and continuous boardwalk.
box(rain, 2.45, .1, 1.6, .2, .61, -.25, "#5f9fa2", false);
box(rain, 1.65, .11, .75, -.55, .65, -.35, "#79b4ae", false);
box(rain, .7, .12, .45, .75, .68, -.15, "#9cc9bb", false);
for (let z = -1.45; z <= 1.45; z += .38) {
box(rain, .42, .11, .38, -.1, .69, z, "#c7b28c");
}
box(rain, 2.75, .11, .42, .25, .69, 1.35, "#c7b28c");
const planterColors = ["#688f58", "#7ea66a", "#5e9270", "#88a968"];
for (let i = 0; i < 4; i++) {
const px = -1.65 + i * .72;
box(rain, .52, .24, .5, px, .72, .85, "#a87e5e");
box(rain, .42, .28, .4, px, .95, .85, planterColors[i]);
}
voxelTree(rain, -1.55, -1.4, .78, "#5b8855");
voxelTree(rain, 1.55, -1.35, .72, "#628f57");
bench(rain, -.85, 1.4, 0);
bench(rain, .55, 1.4, 0);
voxelPerson(rain, -1.8, 1.45, "#c19b55", 1.0);
voxelPerson(rain, .05, 1.55, "#7996b6", 2.6);
voxelPerson(rain, 1.75, 1.45, "#bd7464", 4.0);
// Three-dimensional neighborhood ballot board.
box(scene, 11.8, 4.6, .28, 0, 3.85, -5.45, "#47645d");
box(scene, .22, 3.1, .22, -4.8, 1.15, -5.42, "#4e675f");
box(scene, .22, 3.1, .22, 4.8, 1.15, -5.42, "#4e675f");
box(scene, 10.6, .18, .48, 0, 1.55, -5.42, "#4e675f");
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1200;
boardCanvas.height = 560;
const boardTexture = new THREE.CanvasTexture(boardCanvas);
boardTexture.colorSpace = THREE.SRGBColorSpace;
boardTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const board = new THREE.Mesh(
new THREE.PlaneGeometry(11.25, 4.15),
new THREE.MeshBasicMaterial({ map: boardTexture })
);
board.position.set(0, 3.85, -5.28);
scene.add(board);
function updateBoard() {
const ctx = boardCanvas.getContext("2d");
const counts = getCounts();
const total = 31;
ctx.clearRect(0, 0, 1200, 560);
ctx.fillStyle = "#173a35";
ctx.fillRect(0, 0, 1200, 560);
ctx.fillStyle = "#f5f0df";
ctx.font = "800 39px system-ui";
ctx.fillText("NEIGHBORHOOD BALLOT", 44, 62);
ctx.fillStyle = "#9eb7ae";
ctx.font = "600 19px system-ui";
ctx.fillText("LIVE MODEL COMPARISON · RIVERSIDE COMMONS", 45, 99);
roundedRect(ctx, 930, 30, 220, 55, 12);
ctx.fillStyle = "#2a5048";
ctx.fill();
ctx.fillStyle = "#d7e6df";
ctx.font = "700 18px system-ui";
ctx.textAlign = "center";
ctx.fillText("MAJORITY: 16 / 31", 1040, 64);
ctx.textAlign = "left";
criteria.forEach((criterion, i) => {
const x = 535 + i * 160;
ctx.fillStyle = criterion.color;
ctx.fillRect(x, 125, 12, 12);
ctx.fillStyle = "#b7c8c2";
ctx.font = "700 15px system-ui";
ctx.fillText(criterion.short.toUpperCase(), x + 22, 137);
});
candidates.forEach((candidate, index) => {
const y = 170 + index * 112;
ctx.fillStyle = index % 2 ? "#1d423b" : "#20463f";
roundedRect(ctx, 34, y, 1132, 92, 13);
ctx.fill();
roundedRect(ctx, 54, y + 19, 49, 49, 10);
ctx.fillStyle = candidate.color;
ctx.fill();
ctx.fillStyle = "#fff";
ctx.font = "800 22px system-ui";
ctx.textAlign = "center";
ctx.fillText(candidate.code, 78, y + 51);
ctx.textAlign = "left";
ctx.fillStyle = "#f6f1e4";
ctx.font = "800 23px system-ui";
ctx.fillText(candidate.name, 125, y + 37);
ctx.fillStyle = "#9fb5ae";
ctx.font = "500 15px system-ui";
ctx.fillText(candidate.subtitle, 125, y + 64);
const barX = 535;
const barWidth = 510;
const ratio = counts[candidate.id] / total;
ctx.fillStyle = "#31534c";
roundedRect(ctx, barX, y + 31, barWidth, 22, 8);
ctx.fill();
ctx.fillStyle = candidate.color;
roundedRect(ctx, barX, y + 31, Math.max(12, barWidth * ratio), 22, 8);
ctx.fill();
ctx.fillStyle = "#f6f1e4";
ctx.font = "800 24px system-ui";
ctx.textAlign = "right";
ctx.fillText(`${counts[candidate.id]}`, 1136, y + 51);
ctx.textAlign = "left";
criteria.forEach((criterion, i) => {
const score = state.scores[candidate.id][criterion.id];
const x = 546 + i * 160;
for (let s = 0; s < 4; s++) {
ctx.fillStyle = s < score ? criterion.color : "#416058";
roundedRect(ctx, x + s * 19, y + 66, 12, 8, 2);
ctx.fill();
}
});
});
ctx.fillStyle = "#829f96";
ctx.font = "500 15px system-ui";
ctx.fillText("COLORED POSTS = CRITERION SCORES FULL BARS = NEIGHBORHOOD TALLY ALL MINORITY VIEWS REMAIN ON RECORD", 43, 531);
boardTexture.needsUpdate = true;
}
// A few contextual trees around the model table.
[
[-9.6,-2.8,.9], [9.5,-3.3,.85], [-9.7,2.4,.7], [9.7,2.5,.75]
].forEach(([x,z,s], i) => voxelTree(scene, x, z, s, i % 2 ? "#668e61" : "#739c69"));
// Camera controls are implemented directly without addons.
const desired = {
theta: .43,
phi: 1.03,
radius: 18.7,
target: new THREE.Vector3(0, 1.05, -.05)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
camera.position.set(7.5, 9.5, 15.4);
camera.lookAt(current.target);
let dragging = false;
let dragMoved = false;
let previousPointer = { x: 0, y: 0 };
let autoRotate = false;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragMoved = false;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
desired.theta -= dx * .006;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * .004, .22, 1.35);
});
renderer.domElement.addEventListener("pointerup", event => {
if (dragging && !dragMoved) selectFromPointer(event);
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(desired.radius + event.deltaY * .012, 9, 27);
}, { passive: false });
renderer.domElement.addEventListener("keydown", event => {
const amount = .08;
if (event.key === "ArrowLeft") desired.theta += amount;
if (event.key === "ArrowRight") desired.theta -= amount;
if (event.key === "ArrowUp") desired.phi = Math.max(.22, desired.phi - amount);
if (event.key === "ArrowDown") desired.phi = Math.min(1.35, desired.phi + amount);
if (event.key === "+" || event.key === "=") desired.radius = Math.max(9, desired.radius - 1);
if (event.key === "-") desired.radius = Math.min(27, desired.radius + 1);
});
function selectFromPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(Object.values(candidateGroups), true);
for (const hit of hits) {
if (hit.object.userData.candidateId) {
selectCandidate(hit.object.userData.candidateId, true);
break;
}
}
}
function selectCandidate(id, focus = true) {
state.selected = id;
updateSelection();
if (focus) {
desired.target.set(candidateGroups[id].position.x, 1.05, .45);
desired.radius = 13.6;
desired.phi = 1.02;
}
updateUI();
}
function updateSelection() {
candidates.forEach(candidate => {
const group = candidateGroups[candidate.id];
group.userData.selectionEdges.visible = candidate.id === state.selected;
});
}
function getCounts() {
const counts = Object.fromEntries(candidates.map(c => [c.id, c.votes]));
if (state.userVote) counts[state.userVote]++;
return counts;
}
function updateScoreBars() {
candidates.forEach(candidate => {
const group = candidateGroups[candidate.id];
criteria.forEach((criterion, index) => {
const score = state.scores[candidate.id][criterion.id];
const bar = group.userData.scoreBars[index];
const height = .18 + score * .21;
bar.scale.y = height / .6;
bar.position.y = .68 + height / 2;
});
});
}
function updateUI() {
const counts = getCounts();
const cast = state.userVote ? 31 : 30;
document.getElementById("cast-count").textContent = `${cast}/31`;
document.getElementById("pulse-label").textContent = `${cast} of 31 cast`;
document.getElementById("pulse-number").textContent = cast;
document.getElementById("pulse-progress").style.width = `${(cast / 31) * 100}%`;
document.querySelectorAll(".matrix-row").forEach(row => {
const id = row.dataset.candidate;
row.classList.toggle("selected", id === state.selected);
row.style.setProperty("--selected-color", candidates.find(c => c.id === id).color);
});
document.querySelectorAll("[data-votes]").forEach(element => {
element.textContent = `${counts[element.dataset.votes]} neighborhood votes`;
});
document.querySelectorAll(".score-cell").forEach(cell => {
const id = cell.dataset.scoreCandidate;
const criterionId = cell.dataset.scoreCriterion;
const score = state.scores[id][criterionId];
const criterion = criteria.find(c => c.id === criterionId);
cell.title = `${criterion.label}: ${score}/4 — click to change`;
cell.setAttribute("aria-label", `${candidates.find(c => c.id === id).name}, ${criterion.label}, ${score} out of 4`);
cell.querySelectorAll(".pips i").forEach((pip, i) => {
pip.classList.toggle("on", i < score);
});
});
const maxVotes = Math.max(...Object.values(counts));
candidates.forEach(candidate => {
document.querySelector(`[data-tally="${candidate.id}"]`).textContent = `${counts[candidate.id]} votes`;
document.querySelector(`[data-bar="${candidate.id}"]`).style.width = `${(counts[candidate.id] / maxVotes) * 100}%`;
updateLabel(candidate.id);
});
const selected = candidates.find(c => c.id === state.selected);
const voteButton = document.getElementById("vote-button");
voteButton.textContent = `Back ${selected.name}`;
const currentVote = document.getElementById("current-vote");
if (state.userVote) {
const voted = candidates.find(c => c.id === state.userVote);
currentVote.innerHTML = `Your current recommendation is <b>${voted.name}</b>. A new choice replaces it without changing the other 30 ballots.`;
} else {
currentVote.innerHTML = `No vote cast yet. Select a plan, then confirm below.`;
}
updateScoreBars();
updateBoard();
}
matrix.addEventListener("click", event => {
const scoreCell = event.target.closest(".score-cell");
if (scoreCell) {
const id = scoreCell.dataset.scoreCandidate;
const criterionId = scoreCell.dataset.scoreCriterion;
state.selected = id;
state.scores[id][criterionId] = (state.scores[id][criterionId] + 1) % 5;
updateSelection();
updateUI();
saveState();
return;
}
const selectButton = event.target.closest("[data-select]");
if (selectButton) selectCandidate(selectButton.dataset.select, true);
});
document.getElementById("vote-button").addEventListener("click", () => {
state.userVote = state.selected;
saveState();
updateUI();
const button = document.getElementById("vote-button");
button.animate(
[
{ transform: "scale(1)" },
{ transform: "scale(.97)" },
{ transform: "scale(1)" }
],
{ duration: 240, easing: "ease-out" }
);
});
function saveState() {
try {
localStorage.setItem("parklot-ballot", JSON.stringify({
userVote: state.userVote,
scores: state.scores
}));
} catch (_) {}
}
document.getElementById("reset-view").addEventListener("click", () => {
desired.theta = .43;
desired.phi = 1.03;
desired.radius = 18.7;
desired.target.set(0, 1.05, -.05);
});
document.getElementById("top-view").addEventListener("click", () => {
desired.theta = 0;
desired.phi = .2;
desired.radius = 18;
desired.target.set(0, .7, -.15);
});
document.getElementById("auto-rotate").addEventListener("click", event => {
autoRotate = !autoRotate;
event.currentTarget.setAttribute("aria-pressed", String(autoRotate));
});
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);
candidates.forEach(makeLabel);
updateSelection();
updateUI();
resize();
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), .05);
const elapsed = clock.elapsedTime;
if (autoRotate && !dragging) desired.theta += dt * .16;
const smoothing = 1 - Math.pow(.001, dt);
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, smoothing);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, smoothing);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, smoothing);
current.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
people.forEach(person => {
person.position.y = person.userData.baseY +
Math.sin(elapsed * 1.7 + person.userData.phase) * .018;
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```