Prompt specification
Build or customize the Three.js 3D scene "Common Shelter Funding Simulation" 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: Common Shelter Funding Simulation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/common-shelter-funding-simulation-x3188
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: common shelter funding simulation. Create a fictional community shelter with transparent contribution and benefit rules. Let players compare voluntary and agreed shared funding over repeatable rounds without moralizing individual outcomes. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (common-shelter-funding-simulation-x3188):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#173c42" />
<title>Cedar Commons — Shelter Funding Sandbox</title>
<style>
:root {
--ink: #173c42;
--ink-soft: #44636a;
--paper: #f6f3e9;
--panel: #fffdf7;
--line: #d8ded7;
--teal: #247d78;
--teal-light: #d9ece7;
--orange: #e47b4d;
--green: #6d9f72;
--blue: #5284ad;
--purple: #8973a8;
--heat: #e98255;
--food: #6ca16f;
--care: #5688b2;
--beds: #8a73aa;
--shadow: 0 18px 50px rgba(22, 54, 59, 0.13);
--radius: 16px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(36, 125, 120, 0.32);
outline-offset: 2px;
}
.app {
min-height: 100dvh;
}
.topbar {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
color: #f8f4e8;
background: var(--ink);
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.brand {
display: flex;
align-items: center;
min-width: 0;
gap: 13px;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
flex: 0 0 auto;
}
.brand-mark i {
display: block;
border-radius: 2px;
background: #f0c26d;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: #71b5aa;
}
.brand-mark i:nth-child(5) {
background: #e98255;
}
.brand-mark i:nth-child(9) {
background: transparent;
}
.brand-copy {
min-width: 0;
}
.brand-copy h1 {
margin: 0;
font-size: clamp(1rem, 2vw, 1.28rem);
line-height: 1.15;
letter-spacing: 0.01em;
}
.brand-copy p {
margin: 4px 0 0;
color: #b9ceca;
font-size: 0.79rem;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
}
.seed-badge,
.top-reset {
min-height: 36px;
border-radius: 10px;
font-size: 0.77rem;
font-weight: 700;
}
.seed-badge {
padding: 8px 11px;
color: #cce0db;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.13);
}
.top-reset {
padding: 8px 12px;
color: #173c42;
background: #f0c26d;
border: 0;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
.top-reset:hover {
transform: translateY(-1px);
background: #f5cc7e;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 460px;
height: calc(100dvh - 76px);
}
.scene-panel {
position: relative;
min-width: 0;
overflow: hidden;
background: #dce9e5;
border-right: 1px solid #cbd8d3;
}
#sceneHost,
#voxelScene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#voxelScene {
display: block;
touch-action: none;
cursor: grab;
}
#voxelScene.dragging {
cursor: grabbing;
}
.scene-hud {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
z-index: 4;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.live-pill,
.event-pill {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border-radius: 10px;
background: rgba(255, 253, 247, 0.9);
border: 1px solid rgba(23, 60, 66, 0.13);
box-shadow: 0 8px 24px rgba(23, 60, 66, 0.09);
backdrop-filter: blur(9px);
font-size: 0.75rem;
font-weight: 750;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(36, 125, 120, 0.14);
}
.event-pill {
color: var(--ink-soft);
font-weight: 650;
text-align: right;
}
.building-card {
position: absolute;
z-index: 3;
width: 194px;
padding: 11px 12px 10px;
pointer-events: none;
border-radius: 12px;
background: rgba(255, 253, 247, 0.94);
border: 1px solid rgba(23, 60, 66, 0.14);
box-shadow: 0 12px 30px rgba(23, 60, 66, 0.12);
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.building-card h3 {
margin: 0;
font-size: 0.78rem;
letter-spacing: 0.02em;
}
.building-score {
display: flex;
align-items: baseline;
gap: 5px;
margin: 5px 0 7px;
}
.building-score strong {
font-size: 1.22rem;
line-height: 1;
}
.building-score span {
color: var(--ink-soft);
font-size: 0.69rem;
}
.building-mini {
display: grid;
gap: 4px;
}
.mini-line {
display: grid;
grid-template-columns: 35px 1fr 30px;
align-items: center;
gap: 5px;
font-size: 0.61rem;
color: var(--ink-soft);
}
.mini-track {
height: 4px;
overflow: hidden;
border-radius: 99px;
background: #e2e4dd;
}
.mini-fill {
height: 100%;
border-radius: inherit;
transition: width 280ms ease;
}
.scene-legend {
position: absolute;
z-index: 4;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
max-width: min(520px, calc(100% - 150px));
padding: 10px 12px;
border-radius: 11px;
color: var(--ink-soft);
background: rgba(255, 253, 247, 0.86);
border: 1px solid rgba(23, 60, 66, 0.12);
backdrop-filter: blur(9px);
font-size: 0.68rem;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.view-controls {
position: absolute;
z-index: 5;
right: 18px;
bottom: 18px;
display: flex;
gap: 6px;
}
.view-controls button {
width: 35px;
height: 35px;
border: 1px solid rgba(23, 60, 66, 0.16);
border-radius: 9px;
background: rgba(255, 253, 247, 0.92);
cursor: pointer;
box-shadow: 0 7px 18px rgba(23, 60, 66, 0.08);
font-weight: 800;
}
.view-controls button:hover {
background: #fff;
}
.drag-hint {
position: absolute;
right: 18px;
bottom: 61px;
z-index: 4;
color: rgba(23, 60, 66, 0.62);
font-size: 0.65rem;
pointer-events: none;
}
.control-panel {
min-width: 0;
overflow: hidden;
background: var(--panel);
}
.tabs {
height: 61px;
display: grid;
grid-template-columns: repeat(3, 1fr);
padding: 8px 10px 0;
background: var(--panel);
border-bottom: 1px solid var(--line);
}
.tab-button {
position: relative;
border: 0;
border-radius: 10px 10px 0 0;
color: #728287;
background: transparent;
cursor: pointer;
font-size: 0.79rem;
font-weight: 750;
}
.tab-button::after {
content: "";
position: absolute;
right: 12px;
bottom: -1px;
left: 12px;
height: 3px;
border-radius: 3px 3px 0 0;
background: transparent;
}
.tab-button.active {
color: var(--ink);
background: #f3f1e9;
}
.tab-button.active::after {
background: var(--teal);
}
.panel-scroll {
height: calc(100% - 61px);
overflow-y: auto;
padding: 20px;
scrollbar-width: thin;
scrollbar-color: #bccac5 transparent;
}
.tab-page[hidden] {
display: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 0.66rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
h2,
h3,
p {
margin-top: 0;
}
.section-title {
margin: 0;
font-size: 1.34rem;
line-height: 1.2;
}
.section-intro {
margin: 7px 0 16px;
color: var(--ink-soft);
font-size: 0.79rem;
line-height: 1.55;
}
.round-card {
position: relative;
overflow: hidden;
padding: 16px;
border-radius: var(--radius);
color: #f9f6eb;
background: var(--ink);
box-shadow: var(--shadow);
}
.round-card::after {
content: "";
position: absolute;
top: -34px;
right: -24px;
width: 120px;
height: 120px;
border: 18px solid rgba(240, 194, 109, 0.12);
transform: rotate(18deg);
}
.round-top {
position: relative;
z-index: 1;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 14px;
}
.round-number {
margin: 0 0 4px;
color: #9ec3bd;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.round-card h3 {
margin: 0;
font-size: 1.07rem;
}
.round-card p {
max-width: 280px;
margin: 6px 0 0;
color: #c6d7d3;
font-size: 0.74rem;
line-height: 1.5;
}
.round-count {
flex: 0 0 auto;
padding: 7px 9px;
border-radius: 9px;
color: #f4d38f;
background: rgba(255, 255, 255, 0.09);
font-size: 0.73rem;
font-weight: 800;
}
.round-dots {
position: relative;
z-index: 1;
display: flex;
gap: 5px;
margin-top: 15px;
}
.round-dot {
flex: 1;
height: 5px;
border-radius: 99px;
background: rgba(255, 255, 255, 0.14);
}
.round-dot.current {
background: #f0c26d;
}
.round-dot.done {
background: #71b5aa;
}
.subheading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin: 20px 0 9px;
}
.subheading h3 {
margin: 0;
font-size: 0.88rem;
}
.subheading span {
color: var(--ink-soft);
font-size: 0.68rem;
}
.needs-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.need-chip {
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fff;
}
.need-chip .need-name {
display: flex;
align-items: center;
gap: 5px;
color: var(--ink-soft);
font-size: 0.64rem;
font-weight: 700;
}
.need-chip .need-dot {
width: 7px;
height: 7px;
border-radius: 2px;
}
.need-chip strong {
display: block;
margin-top: 5px;
font-size: 1.05rem;
}
.need-chip small {
color: #8a989a;
font-size: 0.59rem;
}
.contribution-box {
padding: 15px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: #fff;
}
.contribution-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
margin-bottom: 13px;
}
.contribution-head h3 {
margin: 0;
font-size: 0.9rem;
}
.contribution-head p {
margin: 4px 0 0;
color: var(--ink-soft);
font-size: 0.69rem;
line-height: 1.4;
}
.voluntary-total {
flex: 0 0 auto;
text-align: right;
}
.voluntary-total strong {
display: block;
font-size: 1.08rem;
}
.voluntary-total span {
color: var(--ink-soft);
font-size: 0.62rem;
}
.contribution-row {
display: grid;
grid-template-columns: 106px minmax(0, 1fr) 39px;
align-items: center;
gap: 10px;
padding: 9px 0;
border-top: 1px solid #edf0eb;
}
.contribution-row:first-child {
border-top: 0;
}
.household-label {
min-width: 0;
}
.household-label strong {
display: block;
overflow: hidden;
text-overflow: ellipsis;
font-size: 0.75rem;
white-space: nowrap;
}
.household-label small {
display: block;
margin-top: 2px;
color: #849194;
font-size: 0.6rem;
}
.range-wrap {
position: relative;
height: 22px;
display: flex;
align-items: center;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 0;
border-radius: 99px;
appearance: none;
background:
linear-gradient(
to right,
var(--teal) 0 var(--fill, 25%),
#e5e7df var(--fill, 25%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fff;
border-radius: 4px;
appearance: none;
background: var(--teal);
box-shadow: 0 1px 5px rgba(23, 60, 66, 0.32);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fff;
border-radius: 4px;
background: var(--teal);
box-shadow: 0 1px 5px rgba(23, 60, 66, 0.32);
}
.slider-value {
text-align: right;
font-size: 0.73rem;
font-weight: 800;
}
.schedule-note {
margin: 12px 0 0;
padding: 10px 11px;
border-radius: 10px;
color: var(--ink-soft);
background: #f3f5ef;
font-size: 0.67rem;
line-height: 1.45;
}
.schedule-note strong {
color: var(--ink);
}
.outcomes {
display: grid;
gap: 11px;
}
.result-card {
padding: 15px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: #fff;
}
.result-card.voluntary {
border-top: 4px solid var(--orange);
}
.result-card.shared {
border-top: 4px solid var(--teal);
}
.result-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}
.result-heading h3 {
margin: 0;
font-size: 0.87rem;
}
.policy-tag {
padding: 5px 7px;
border-radius: 7px;
color: var(--ink-soft);
background: #f1f3ed;
font-size: 0.6rem;
font-weight: 800;
}
.result-main {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
align-items: end;
margin: 14px 0 12px;
}
.result-number {
display: flex;
align-items: baseline;
gap: 6px;
}
.result-number strong {
font-size: 1.75rem;
line-height: 1;
}
.result-number span {
color: var(--ink-soft);
font-size: 0.69rem;
}
.coverage-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: var(--ink-soft);
font-size: 0.64rem;
}
.coverage-label strong {
color: var(--ink);
}
.coverage-track {
height: 8px;
overflow: hidden;
border-radius: 99px;
background: #e7e8e1;
}
.coverage-fill {
height: 100%;
border-radius: inherit;
transition: width 280ms ease;
}
.result-meta {
display: flex;
gap: 13px;
margin-bottom: 12px;
color: var(--ink-soft);
font-size: 0.64rem;
}
.result-meta strong {
color: var(--ink);
}
.service-results {
display: grid;
gap: 7px;
}
.service-result {
display: grid;
grid-template-columns: 47px 1fr 35px;
align-items: center;
gap: 7px;
font-size: 0.64rem;
}
.service-result > span:first-child {
color: var(--ink-soft);
font-weight: 700;
}
.service-result > span:last-child {
text-align: right;
font-weight: 800;
}
.service-track {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: #ecece6;
}
.service-fill {
height: 100%;
border-radius: inherit;
transition: width 280ms ease;
}
.actions {
position: sticky;
bottom: -20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin: 20px -20px -20px;
padding: 13px 20px 20px;
background: linear-gradient(to top, var(--panel) 78%, rgba(255, 253, 247, 0));
}
.primary-button,
.secondary-button {
min-height: 43px;
padding: 10px 12px;
border-radius: 10px;
cursor: pointer;
font-size: 0.76rem;
font-weight: 800;
transition: transform 150ms ease, opacity 150ms ease;
}
.primary-button {
color: #fff;
background: var(--teal);
border: 1px solid var(--teal);
box-shadow: 0 8px 20px rgba(36, 125, 120, 0.2);
}
.secondary-button {
color: var(--ink);
background: #fff;
border: 1px solid var(--line);
}
.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
transform: translateY(-1px);
}
.primary-button:disabled {
cursor: default;
opacity: 0.55;
box-shadow: none;
}
.actions .secondary-button[hidden] {
display: none;
}
.rule-block {
margin-bottom: 13px;
padding: 15px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: #fff;
}
.rule-block h3 {
margin: 0 0 7px;
font-size: 0.87rem;
}
.rule-block p,
.rule-block li {
color: var(--ink-soft);
font-size: 0.72rem;
line-height: 1.55;
}
.rule-block p:last-child {
margin-bottom: 0;
}
.rule-block ul {
margin: 7px 0 0;
padding-left: 18px;
}
.formula {
display: block;
margin: 10px 0;
padding: 10px 11px;
overflow-x: auto;
border-radius: 9px;
color: var(--ink);
background: #f1f3ed;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.68rem;
line-height: 1.5;
}
.schedule-table {
width: 100%;
border-collapse: collapse;
font-size: 0.69rem;
}
.schedule-table th,
.schedule-table td {
padding: 8px 7px;
border-bottom: 1px solid #e8ebe5;
text-align: left;
}
.schedule-table th {
color: var(--ink-soft);
font-size: 0.61rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.schedule-table td:last-child {
text-align: right;
font-weight: 800;
}
.neutral-note {
padding: 12px;
border-radius: 10px;
color: #355b5d;
background: var(--teal-light);
font-size: 0.7rem;
line-height: 1.5;
}
.comparison-summary {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 9px;
margin-bottom: 14px;
}
.summary-card {
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fff;
}
.summary-card span {
display: block;
color: var(--ink-soft);
font-size: 0.63rem;
}
.summary-card strong {
display: block;
margin-top: 4px;
font-size: 1.12rem;
}
.comparison-table-wrap {
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 12px;
background: #fff;
}
.comparison-table {
width: 100%;
min-width: 560px;
border-collapse: collapse;
font-size: 0.68rem;
}
.comparison-table th,
.comparison-table td {
padding: 10px 8px;
border-bottom: 1px solid #e8ebe5;
text-align: right;
}
.comparison-table th {
color: var(--ink-soft);
background: #f5f5ef;
font-size: 0.59rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.comparison-table th:first-child,
.comparison-table td:first-child,
.comparison-table th:nth-child(2),
.comparison-table td:nth-child(2) {
text-align: left;
}
.comparison-table tr:last-child td {
border-bottom: 0;
}
.table-bar {
display: inline-block;
width: 48px;
height: 5px;
margin-right: 5px;
overflow: hidden;
vertical-align: middle;
border-radius: 99px;
background: #e8e9e3;
}
.table-bar i {
display: block;
height: 100%;
border-radius: inherit;
}
.delta-positive {
color: #28756e;
font-weight: 800;
}
.delta-negative {
color: #9b6549;
font-weight: 800;
}
.delta-zero {
color: var(--ink-soft);
font-weight: 800;
}
.empty-state {
padding: 22px 16px;
text-align: center;
color: var(--ink-soft);
font-size: 0.73rem;
line-height: 1.5;
}
.complete-banner {
margin-bottom: 12px;
padding: 12px;
border-radius: 10px;
color: #255f5c;
background: #dceee8;
font-size: 0.7rem;
line-height: 1.5;
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
padding: 11px 15px;
border-radius: 10px;
color: #fff;
background: rgba(23, 60, 66, 0.94);
box-shadow: var(--shadow);
transform: translate(-50%, 18px);
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
font-size: 0.75rem;
font-weight: 700;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1080px) {
.layout {
grid-template-columns: minmax(0, 1fr) 410px;
}
.panel-scroll {
padding: 17px;
}
.actions {
margin-right: -17px;
margin-bottom: -17px;
margin-left: -17px;
padding-right: 17px;
padding-bottom: 17px;
padding-left: 17px;
}
}
@media (max-width: 820px) {
body {
overflow: auto;
}
.topbar {
height: auto;
min-height: 76px;
padding: 12px 15px;
}
.seed-badge {
display: none;
}
.layout {
display: block;
height: auto;
}
.scene-panel {
height: 56dvh;
min-height: 420px;
border-right: 0;
border-bottom: 1px solid #cbd8d3;
}
.control-panel {
overflow: visible;
}
.tabs {
position: sticky;
top: 0;
z-index: 8;
}
.panel-scroll {
height: auto;
overflow: visible;
}
.actions {
position: static;
}
}
@media (max-width: 520px) {
.brand-copy p {
display: none;
}
.top-reset {
font-size: 0.69rem;
}
.scene-hud {
top: 12px;
left: 12px;
right: 12px;
}
.event-pill {
max-width: 45%;
font-size: 0.64rem;
}
.building-card {
width: 150px;
padding: 8px 9px;
}
.building-card h3 {
font-size: 0.68rem;
}
.building-score strong {
font-size: 1rem;
}
.mini-line {
grid-template-columns: 29px 1fr 25px;
font-size: 0.52rem;
}
.scene-legend {
left: 12px;
bottom: 12px;
max-width: calc(100% - 100px);
font-size: 0.58rem;
}
.view-controls {
right: 12px;
bottom: 12px;
}
.drag-hint {
display: none;
}
.contribution-row {
grid-template-columns: 91px minmax(0, 1fr) 32px;
gap: 7px;
}
.comparison-summary {
grid-template-columns: 1fr 1fr;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</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>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div class="brand-copy">
<h1>Cedar Commons</h1>
<p>Community shelter funding sandbox</p>
</div>
</div>
<div class="top-actions">
<div class="seed-badge">CC-08 · fixed demand sequence</div>
<button class="top-reset" id="resetScenario" type="button">Reset scenario</button>
</div>
</header>
<main class="layout">
<section class="scene-panel" aria-label="Interactive voxel shelter comparison">
<div id="sceneHost">
<canvas
id="voxelScene"
tabindex="0"
aria-label="Voxel view of two shelter funding scenarios. Drag to orbit and use the mouse wheel to zoom."
></canvas>
</div>
<div class="scene-hud">
<div class="live-pill">
<span class="live-dot" aria-hidden="true"></span>
Live round comparison
</div>
<div class="event-pill" id="sceneEvent">Round 1 · Baseline week</div>
</div>
<div class="building-card" id="voluntaryCard" aria-hidden="true"></div>
<div class="building-card" id="sharedCard" aria-hidden="true"></div>
<div class="scene-legend" aria-hidden="true">
<span class="legend-item"><i class="legend-swatch" style="background:var(--heat)"></i>Heat</span>
<span class="legend-item"><i class="legend-swatch" style="background:var(--food)"></i>Food</span>
<span class="legend-item"><i class="legend-swatch" style="background:var(--care)"></i>Care</span>
<span class="legend-item"><i class="legend-swatch" style="background:var(--beds)"></i>Beds</span>
<span class="legend-item">Cubes = funded service units</span>
</div>
<div class="drag-hint">Drag to orbit · Wheel to zoom</div>
<div class="view-controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetView" type="button" aria-label="Reset camera view">⌂</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
</div>
</section>
<aside class="control-panel" aria-label="Simulation controls">
<nav class="tabs" role="tablist" aria-label="Simulation sections">
<button
class="tab-button active"
id="tabOverview"
type="button"
role="tab"
aria-selected="true"
aria-controls="overviewPage"
data-tab="overview"
>
Round
</button>
<button
class="tab-button"
id="tabRules"
type="button"
role="tab"
aria-selected="false"
aria-controls="rulesPage"
data-tab="rules"
>
Rules
</button>
<button
class="tab-button"
id="tabCompare"
type="button"
role="tab"
aria-selected="false"
aria-controls="comparePage"
data-tab="compare"
>
Compare
</button>
</nav>
<div class="panel-scroll">
<section class="tab-page" id="overviewPage" role="tabpanel" aria-labelledby="tabOverview">
<p class="eyebrow">Repeatable scenario</p>
<h2 class="section-title">Test two funding approaches</h2>
<p class="section-intro">
Set voluntary contributions, review both policies against the same needs,
then record the round. Results describe service coverage rather than personal merit.
</p>
<div class="round-card">
<div class="round-top">
<div>
<p class="round-number" id="roundNumber">Round 1 of 8</p>
<h3 id="roundName">Baseline week</h3>
<p id="roundDescription"></p>
</div>
<div class="round-count" id="roundNeedTotal">18 units</div>
</div>
<div class="round-dots" id="roundDots" aria-hidden="true"></div>
</div>
<div class="subheading">
<h3>Service needs this round</h3>
<span>Same needs under both policies</span>
</div>
<div class="needs-grid" id="needsGrid"></div>
<div class="subheading">
<h3>Voluntary contributions</h3>
<span>0–8 credits per household</span>
</div>
<div class="contribution-box">
<div class="contribution-head">
<div>
<h3>Community pool</h3>
<p>Adjust each contribution before recording.</p>
</div>
<div class="voluntary-total">
<strong id="voluntaryTotal">12</strong>
<span>credits pooled</span>
</div>
</div>
<div id="contributionRows"></div>
<p class="schedule-note">
<strong>Agreed schedule:</strong>
Alder 1, Birch 2, Cedar 2, Dune 3, Elm 3, Fen 4.
The agreed pool is always 15 credits.
</p>
</div>
<div class="subheading">
<h3>Live outcomes</h3>
<span>Updates as contributions change</span>
</div>
<div class="outcomes">
<article class="result-card voluntary" id="voluntaryResult"></article>
<article class="result-card shared" id="sharedResult"></article>
</div>
<div class="actions">
<button class="primary-button" id="recordRound" type="button">Record round</button>
<button class="secondary-button" id="nextRound" type="button" hidden>Next round</button>
</div>
</section>
<section class="tab-page" id="rulesPage" role="tabpanel" aria-labelledby="tabRules" hidden>
<p class="eyebrow">Transparent rules</p>
<h2 class="section-title">Everything used in the calculation</h2>
<p class="section-intro">
Cedar Commons is fictional. The demand sequence, contribution schedules,
allocation formulas, and reporting rules remain fixed across repeated runs.
</p>
<article class="rule-block">
<h3>1. Round needs</h3>
<p>
Each round has four service requests: Heat, Food, Care, and Beds.
One funded unit satisfies one requested unit. Both policies receive
exactly the same requests in every round.
</p>
<span class="formula">funded units = min(allocated units, service need)</span>
</article>
<article class="rule-block">
<h3>2. Voluntary funding</h3>
<ul>
<li>Each of six households chooses between 0 and 8 credits.</li>
<li>A fictional matching grant adds 25% of the community pool.</li>
<li>The grant is rounded down and capped at 6 credits.</li>
</ul>
<span class="formula">
match = min(6, floor(voluntary pool × 0.25))<br>
final pool = voluntary pool + match
</span>
</article>
<article class="rule-block">
<h3>3. Agreed shared funding</h3>
<p>
Every household contributes the credit value of its community-defined
capacity band. The total agreed pool is therefore 15 credits.
</p>
<table class="schedule-table">
<thead>
<tr><th>Household</th><th>Capacity band</th><th>Agreed credits</th></tr>
</thead>
<tbody>
<tr><td>Alder</td><td>1</td><td>1</td></tr>
<tr><td>Birch</td><td>2</td><td>2</td></tr>
<tr><td>Cedar</td><td>2</td><td>2</td></tr>
<tr><td>Dune</td><td>3</td><td>3</td></tr>
<tr><td>Elm</td><td>3</td><td>3</td></tr>
<tr><td>Fen</td><td>4</td><td>4</td></tr>
</tbody>
</table>
<p style="margin-top:10px">
Capacity bands are planning inputs, not judgments about residents.
</p>
</article>
<article class="rule-block">
<h3>4. Voluntary benefit allocation</h3>
<p>
The final voluntary pool is divided equally among the four service bays.
Any one-credit rounding remainder goes to Heat, then Food, then Care,
then Beds. Credits assigned above a bay’s need are not moved to another bay.
</p>
<span class="formula">
allocation = ¼ of usable final pool<br>
remainder order: Heat → Food → Care → Beds
</span>
</article>
<article class="rule-block">
<h3>5. Shared benefit allocation</h3>
<p>
The agreed pool is allocated in proportion to each service’s request.
Fractional parts are distributed with the largest-remainder method.
Ties follow the order Heat, Food, Care, Beds.
</p>
<span class="formula">
raw allocation = 15 × service need ÷ total need<br>
floors first, then largest fractional remainders
</span>
</article>
<article class="rule-block">
<h3>6. Measurement and repeatability</h3>
<ul>
<li>Coverage is total funded service units divided by total need.</li>
<li>The lowest-bay figure is the smallest service-specific coverage.</li>
<li>Each round begins with zero reserve; credits do not carry forward.</li>
<li>Contribution size does not change personal benefit eligibility.</li>
<li>Resetting restores all choices and the same eight-round sequence.</li>
</ul>
</article>
<div class="neutral-note">
Outcomes are reported at the service and aggregate level. There is no
household ranking, benefit auction, or moral score.
</div>
</section>
<section class="tab-page" id="comparePage" role="tabpanel" aria-labelledby="tabCompare" hidden>
<p class="eyebrow">Recorded rounds</p>
<h2 class="section-title">Compare coverage over time</h2>
<p class="section-intro">
Recorded rounds use the same demand sequence. Differences are shown in
funded service units and coverage percentage.
</p>
<div id="completeBanner" class="complete-banner" hidden>
All eight rounds are recorded. The final comparison uses the full fixed scenario.
</div>
<div class="comparison-summary" id="comparisonSummary"></div>
<div class="subheading">
<h3>Round-by-round results</h3>
<span id="recordedCount">0 of 8 recorded</span>
</div>
<div class="comparison-table-wrap">
<table class="comparison-table">
<thead>
<tr>
<th>Round</th>
<th>Need</th>
<th>Voluntary</th>
<th>Shared</th>
<th>Unit gap</th>
</tr>
</thead>
<tbody id="comparisonRows"></tbody>
</table>
</div>
<div class="rule-block" style="margin-top:14px">
<h3>Reading the comparison</h3>
<p>
A positive unit gap means the shared policy funded more service units
in that round. A negative gap means the voluntary policy funded more.
Equal totals can still produce different bay-level coverage because
the allocation rules differ.
</p>
</div>
</section>
</div>
</aside>
</main>
</div>
<div class="toast" id="toast" role="status" 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 SERVICE_ORDER = ["heat", "food", "care", "beds"];
const SERVICES = {
heat: { name: "Heat", color: "#e98255" },
food: { name: "Food", color: "#6ca16f" },
care: { name: "Care", color: "#5688b2" },
beds: { name: "Beds", color: "#8a73aa" }
};
const ROUNDS = [
{
name: "Baseline week",
description: "A regular week establishes the starting request pattern.",
needs: { heat: 5, food: 4, care: 6, beds: 3 }
},
{
name: "Cold front",
description: "Longer heating hours coincide with a smaller food request.",
needs: { heat: 7, food: 5, care: 5, beds: 4 }
},
{
name: "Supply delay",
description: "Food arrives late while care and overnight requests remain steady.",
needs: { heat: 5, food: 6, care: 7, beds: 4 }
},
{
name: "Storm week",
description: "High heating and care requests overlap with bed demand.",
needs: { heat: 8, food: 5, care: 6, beds: 5 }
},
{
name: "Restock week",
description: "Food demand rises after a neighborhood delivery gap.",
needs: { heat: 6, food: 7, care: 5, beds: 6 }
},
{
name: "Warm-weather gathering",
description: "Heat requests ease while meals and overnight spaces rise.",
needs: { heat: 4, food: 6, care: 5, beds: 7 }
},
{
name: "Deep cold",
description: "Heating and care requests peak during the coldest sequence entry.",
needs: { heat: 8, food: 6, care: 7, beds: 5 }
},
{
name: "Festival influx",
description: "Meals, care, and beds reach their broadest combined request.",
needs: { heat: 6, food: 8, care: 8, beds: 5 }
}
];
const HOUSEHOLDS = [
{ name: "Alder", capacity: 1 },
{ name: "Birch", capacity: 2 },
{ name: "Cedar", capacity: 2 },
{ name: "Dune", capacity: 3 },
{ name: "Elm", capacity: 3 },
{ name: "Fen", capacity: 4 }
];
const DEFAULT_VOLUNTARY = HOUSEHOLDS.map(() => 2);
const state = {
roundIndex: 0,
voluntary: [...DEFAULT_VOLUNTARY],
recorded: Array(ROUNDS.length).fill(null),
activeTab: "overview"
};
const dom = {
roundNumber: document.getElementById("roundNumber"),
roundName: document.getElementById("roundName"),
roundDescription: document.getElementById("roundDescription"),
roundNeedTotal: document.getElementById("roundNeedTotal"),
roundDots: document.getElementById("roundDots"),
needsGrid: document.getElementById("needsGrid"),
contributionRows: document.getElementById("contributionRows"),
voluntaryTotal: document.getElementById("voluntaryTotal"),
voluntaryResult: document.getElementById("voluntaryResult"),
sharedResult: document.getElementById("sharedResult"),
recordRound: document.getElementById("recordRound"),
nextRound: document.getElementById("nextRound"),
sceneEvent: document.getElementById("sceneEvent"),
voluntaryCard: document.getElementById("voluntaryCard"),
sharedCard: document.getElementById("sharedCard"),
comparisonSummary: document.getElementById("comparisonSummary"),
comparisonRows: document.getElementById("comparisonRows"),
recordedCount: document.getElementById("recordedCount"),
completeBanner: document.getElementById("completeBanner"),
toast: document.getElementById("toast")
};
const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
const sumNeeds = needs => SERVICE_ORDER.reduce((sum, key) => sum + needs[key], 0);
const percent = value => Math.round(value * 10) / 10;
function computeVoluntary(needs) {
const basePool = state.voluntary.reduce((sum, value) => sum + value, 0);
const match = Math.min(6, Math.floor(basePool * 0.25));
const pool = basePool + match;
const totalNeed = sumNeeds(needs);
const usablePool = Math.min(pool, totalNeed);
const allocation = Object.fromEntries(SERVICE_ORDER.map(key => [key, 0]));
const baseAllocation = Math.floor(usablePool / SERVICE_ORDER.length);
let remainder = usablePool - baseAllocation * SERVICE_ORDER.length;
for (const key of SERVICE_ORDER) {
allocation[key] = baseAllocation;
}
for (const key of SERVICE_ORDER) {
if (remainder <= 0) break;
allocation[key] += 1;
remainder -= 1;
}
const funded = Object.fromEntries(
SERVICE_ORDER.map(key => [key, Math.min(allocation[key], needs[key])])
);
const fundedTotal = SERVICE_ORDER.reduce((sum, key) => sum + funded[key], 0);
const coverage = totalNeed ? fundedTotal / totalNeed * 100 : 0;
const lowestBay = Math.min(
...SERVICE_ORDER.map(key => needs[key] ? funded[key] / needs[key] * 100 : 100)
);
return {
basePool,
match,
pool,
allocation,
funded,
fundedTotal,
totalNeed,
coverage,
lowestBay,
unused: pool - fundedTotal,
reserve: Math.max(0, pool - totalNeed)
};
}
function computeShared(needs) {
const pool = HOUSEHOLDS.reduce((sum, household) => sum + household.capacity, 0);
const totalNeed = sumNeeds(needs);
const allocation = Object.fromEntries(SERVICE_ORDER.map(key => [key, 0]));
if (pool >= totalNeed) {
for (const key of SERVICE_ORDER) allocation[key] = needs[key];
} else {
const shares = SERVICE_ORDER.map((key, index) => {
const raw = pool * needs[key] / totalNeed;
return {
key,
index,
raw,
floor: Math.floor(raw),
fraction: raw - Math.floor(raw)
};
});
let assigned = 0;
for (const share of shares) {
allocation[share.key] = share.floor;
assigned += share.floor;
}
const ordered = [...shares].sort(
(a, b) => b.fraction - a.fraction || a.index - b.index
);
let remainder = pool - assigned;
for (const share of ordered) {
if (remainder <= 0) break;
allocation[share.key] += 1;
remainder -= 1;
}
}
const funded = Object.fromEntries(
SERVICE_ORDER.map(key => [key, Math.min(allocation[key], needs[key])])
);
const fundedTotal = SERVICE_ORDER.reduce((sum, key) => sum + funded[key], 0);
const coverage = totalNeed ? fundedTotal / totalNeed * 100 : 0;
const lowestBay = Math.min(
...SERVICE_ORDER.map(key => needs[key] ? funded[key] / needs[key] * 100 : 100)
);
return {
pool,
allocation,
funded,
fundedTotal,
totalNeed,
coverage,
lowestBay,
unused: pool - fundedTotal,
reserve: Math.max(0, pool - totalNeed)
};
}
function currentResults() {
const needs = ROUNDS[state.roundIndex].needs;
return {
needs,
voluntary: { ...computeVoluntary(needs), needs },
shared: { ...computeShared(needs), needs }
};
}
function renderRound() {
const round = ROUNDS[state.roundIndex];
const total = sumNeeds(round.needs);
dom.roundNumber.textContent = `Round ${state.roundIndex + 1} of ${ROUNDS.length}`;
dom.roundName.textContent = round.name;
dom.roundDescription.textContent = round.description;
dom.roundNeedTotal.textContent = `${total} units`;
dom.sceneEvent.textContent = `Round ${state.roundIndex + 1} · ${round.name}`;
dom.roundDots.innerHTML = ROUNDS.map((_, index) => {
const classes = ["round-dot"];
if (index < state.roundIndex || state.recorded[index]) classes.push("done");
if (index === state.roundIndex) classes.push("current");
return `<i class="${classes.join(" ")}"></i>`;
}).join("");
dom.needsGrid.innerHTML = SERVICE_ORDER.map(key => `
<div class="need-chip">
<span class="need-name">
<i class="need-dot" style="background:${SERVICES[key].color}"></i>
${SERVICES[key].name}
</span>
<strong>${round.needs[key]}</strong>
<small>units needed</small>
</div>
`).join("");
}
function renderContributionRows() {
dom.contributionRows.innerHTML = HOUSEHOLDS.map((household, index) => {
const value = state.voluntary[index];
return `
<div class="contribution-row">
<label class="household-label" for="contribution-${index}">
<strong>${household.name}</strong>
<small>Capacity band ${household.capacity}</small>
</label>
<div class="range-wrap">
<input
id="contribution-${index}"
type="range"
min="0"
max="8"
step="1"
value="${value}"
data-index="${index}"
aria-label="${household.name} voluntary contribution"
style="--fill:${value / 8 * 100}%"
/>
</div>
<output class="slider-value" id="slider-value-${index}">${value}</output>
</div>
`;
}).join("");
dom.voluntaryTotal.textContent = state.voluntary.reduce((sum, value) => sum + value, 0);
}
function serviceRows(result) {
return SERVICE_ORDER.map(key => {
const coverage = result.needs[key]
? result.funded[key] / result.needs[key] * 100
: 0;
return `
<div class="service-result">
<span>${SERVICES[key].name}</span>
<div class="service-track">
<div
class="service-fill"
style="width:${coverage}%;background:${SERVICES[key].color}"
></div>
</div>
<span>${result.funded[key]}/${result.needs[key]}</span>
</div>
`;
}).join("");
}
function outcomeMarkup(result, policy) {
const poolDescription = policy === "voluntary"
? `${result.basePool} pooled + ${result.match} match`
: `${result.pool} agreed credits`;
const color = policy === "voluntary" ? "#e47b4d" : "#247d78";
return `
<div class="result-heading">
<h3>${policy === "voluntary" ? "Voluntary funding" : "Agreed shared funding"}</h3>
<span class="policy-tag">${policy === "voluntary" ? "PLAYER SET" : "FIXED SCHEDULE"}</span>
</div>
<div class="result-main">
<div class="result-number">
<strong>${result.fundedTotal}</strong>
<span>of ${result.totalNeed} units funded</span>
</div>
<div>
<div class="coverage-label">
<span>Coverage</span>
<strong>${percent(result.coverage)}%</strong>
</div>
<div class="coverage-track">
<div
class="coverage-fill"
style="width:${result.coverage}%;background:${color}"
></div>
</div>
</div>
</div>
<div class="result-meta">
<span>Pool: <strong>${poolDescription}</strong></span>
<span>Lowest bay: <strong>${percent(result.lowestBay)}%</strong></span>
</div>
<div class="service-results">${serviceRows(result)}</div>
`;
}
function updateRecordControls() {
const recorded = Boolean(state.recorded[state.roundIndex]);
dom.recordRound.disabled = recorded;
dom.recordRound.textContent = recorded ? "Round recorded" : "Record round";
dom.nextRound.hidden = !recorded;
dom.nextRound.textContent =
state.roundIndex === ROUNDS.length - 1 ? "Open comparison" : "Next round";
}
function updateLiveResults() {
const results = currentResults();
dom.voluntaryResult.innerHTML = outcomeMarkup(results.voluntary, "voluntary");
dom.sharedResult.innerHTML = outcomeMarkup(results.shared, "shared");
dom.voluntaryTotal.textContent = state.voluntary.reduce((sum, value) => sum + value, 0);
updateSceneResults(results.voluntary, results.shared);
updateRecordControls();
renderCompare();
}
function renderCompare() {
const records = state.recorded
.map((record, index) => record ? { ...record, index } : null)
.filter(Boolean);
dom.recordedCount.textContent = `${records.length} of ${ROUNDS.length} recorded`;
dom.completeBanner.hidden = records.length !== ROUNDS.length;
if (!records.length) {
dom.comparisonSummary.innerHTML = `
<div class="summary-card"><span>Recorded rounds</span><strong>0</strong></div>
<div class="summary-card"><span>Average coverage gap</span><strong>—</strong></div>
`;
dom.comparisonRows.innerHTML = `
<tr>
<td colspan="5">
<div class="empty-state">
Record a round to begin the comparison.<br>
Both policies will use the same service needs.
</div>
</td>
</tr>
`;
return;
}
const voluntaryCoverage =
records.reduce((sum, record) => sum + record.voluntary.coverage, 0) / records.length;
const sharedCoverage =
records.reduce((sum, record) => sum + record.shared.coverage, 0) / records.length;
const voluntaryUnits =
records.reduce((sum, record) => sum + record.voluntary.fundedTotal, 0);
const sharedUnits =
records.reduce((sum, record) => sum + record.shared.fundedTotal, 0);
const unitGap = sharedUnits - voluntaryUnits;
const gapLabel = unitGap > 0 ? `+${unitGap}` : `${unitGap}`;
dom.comparisonSummary.innerHTML = `
<div class="summary-card">
<span>Voluntary average coverage</span>
<strong>${percent(voluntaryCoverage)}%</strong>
</div>
<div class="summary-card">
<span>Shared average coverage</span>
<strong>${percent(sharedCoverage)}%</strong>
</div>
<div class="summary-card">
<span>Voluntary funded units</span>
<strong>${voluntaryUnits}</strong>
</div>
<div class="summary-card">
<span>Shared − voluntary units</span>
<strong>${gapLabel}</strong>
</div>
`;
dom.comparisonRows.innerHTML = records.map(record => {
const difference = record.shared.fundedTotal - record.voluntary.fundedTotal;
const differenceClass =
difference > 0 ? "delta-positive" :
difference < 0 ? "delta-negative" : "delta-zero";
const differenceText =
difference > 0 ? `+${difference}` : `${difference}`;
return `
<tr>
<td><strong>${record.index + 1}</strong></td>
<td>${record.voluntary.totalNeed}</td>
<td>
<span class="table-bar">
<i style="width:${record.voluntary.coverage}%;background:#e47b4d"></i>
</span>
${record.voluntary.fundedTotal} / ${percent(record.voluntary.coverage)}%
</td>
<td>
<span class="table-bar">
<i style="width:${record.shared.coverage}%;background:#247d78"></i>
</span>
${record.shared.fundedTotal} / ${percent(record.shared.coverage)}%
</td>
<td class="${differenceClass}">${differenceText}</td>
</tr>
`;
}).join("");
}
function switchTab(tab) {
state.activeTab = tab;
document.querySelectorAll(".tab-button").forEach(button => {
const active = button.dataset.tab === tab;
button.classList.toggle("active", active);
button.setAttribute("aria-selected", String(active));
});
document.getElementById("overviewPage").hidden = tab !== "overview";
document.getElementById("rulesPage").hidden = tab !== "rules";
document.getElementById("comparePage").hidden = tab !== "compare";
if (tab === "compare") renderCompare();
}
let toastTimer;
function showToast(message) {
dom.toast.textContent = message;
dom.toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => dom.toast.classList.remove("show"), 2300);
}
function recordCurrentRound() {
if (state.recorded[state.roundIndex]) return;
const results = currentResults();
state.recorded[state.roundIndex] = {
voluntary: JSON.parse(JSON.stringify(results.voluntary)),
shared: JSON.parse(JSON.stringify(results.shared))
};
updateRecordControls();
renderRound();
renderCompare();
showToast(`Round ${state.roundIndex + 1} recorded for both policies.`);
}
function advanceRound() {
if (!state.recorded[state.roundIndex]) return;
if (state.roundIndex === ROUNDS.length - 1) {
switchTab("compare");
showToast("Full eight-round comparison ready.");
return;
}
state.roundIndex += 1;
state.voluntary = [...DEFAULT_VOLUNTARY];
renderRound();
renderContributionRows();
updateLiveResults();
showToast(`Round ${state.roundIndex + 1}: ${ROUNDS[state.roundIndex].name}.`);
}
function resetScenario() {
const shouldReset = window.confirm(
"Reset all contributions and recorded comparisons? The same fixed round sequence will be used."
);
if (!shouldReset) return;
state.roundIndex = 0;
state.voluntary = [...DEFAULT_VOLUNTARY];
state.recorded = Array(ROUNDS.length).fill(null);
renderRound();
renderContributionRows();
updateLiveResults();
switchTab("overview");
showToast("Scenario reset. The fixed sequence is ready.");
}
dom.contributionRows.addEventListener("input", event => {
if (!(event.target instanceof HTMLInputElement)) return;
if (event.target.type !== "range") return;
const index = Number(event.target.dataset.index);
const value = Number(event.target.value);
state.voluntary[index] = value;
event.target.style.setProperty("--fill", `${value / 8 * 100}%`);
document.getElementById(`slider-value-${index}`).textContent = value;
state.recorded[state.roundIndex] = null;
updateLiveResults();
renderRound();
});
dom.recordRound.addEventListener("click", recordCurrentRound);
dom.nextRound.addEventListener("click", advanceRound);
document.getElementById("resetScenario").addEventListener("click", resetScenario);
document.querySelectorAll(".tab-button").forEach(button => {
button.addEventListener("click", () => switchTab(button.dataset.tab));
});
// ---------------------------------------------------------------------
// Three.js voxel scene
// ---------------------------------------------------------------------
const canvas = document.getElementById("voxelScene");
const sceneHost = document.getElementById("sceneHost");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce9e5");
scene.fog = new THREE.Fog("#dce9e5", 48, 90);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 150);
const cameraTarget = new THREE.Vector3(0, 1.2, 0);
const cameraState = {
yaw: 0.31,
pitch: 0.57,
viewSize: 30,
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0
};
function updateCamera() {
const radius = 48;
const horizontal = Math.cos(cameraState.pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * radius,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resizeScene() {
const rect = sceneHost.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const aspect = rect.width / rect.height;
const responsiveSize = cameraState.viewSize * Math.max(1, 1.25 / aspect);
camera.left = -responsiveSize * aspect / 2;
camera.right = responsiveSize * aspect / 2;
camera.top = responsiveSize / 2;
camera.bottom = -responsiveSize / 2;
camera.updateProjectionMatrix();
renderer.setSize(rect.width, rect.height, false);
}
const resizeObserver = new ResizeObserver(resizeScene);
resizeObserver.observe(sceneHost);
const hemisphere = new THREE.HemisphereLight("#f8f4d8", "#6e8c82", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff1d1", 3.1);
sun.position.set(-12, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fillLight = new THREE.DirectionalLight("#b9dddf", 1.25);
fillLight.position.set(18, 12, -15);
scene.add(fillLight);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (materialCache.has(key)) return materialCache.get(key);
const opacity = options.opacity ?? 1;
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
transparent: opacity < 1,
opacity,
depthWrite: opacity >= 0.98,
side: options.side ?? THREE.FrontSide
});
materialCache.set(key, material);
return material;
}
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = getMaterial(color, options);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = options.shadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeTextSprite(
text,
background,
foreground,
scaleX,
scaleY,
options = {}
) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = background;
context.fillRect(5, 8, 502, 112);
context.fillStyle = foreground;
context.font = "700 52px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.NearestFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest ?? false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scaleX, scaleY, 1);
sprite.renderOrder = options.renderOrder ?? 2;
return sprite;
}
addBox(scene, 44, 0.55, 29, 0, -0.32, 0, "#b9cbc0", {
roughness: 1,
shadow: false
});
addBox(scene, 6.3, 0.16, 25, 0, 0, 0, "#e9dcc0", {
roughness: 1,
shadow: false
});
for (let z = -11; z <= 11; z += 2) {
addBox(scene, 5.85, 0.04, 1.68, 0, 0.1, z, "#f1e5cd", {
roughness: 1,
shadow: false
});
}
for (const side of [-1, 1]) {
for (let z = -8; z <= 8; z += 4) {
addBox(scene, 7.3, 0.07, 1.15, side * 12.7, 0.02, z, "#c7d5c9", {
roughness: 1,
shadow: false
});
}
}
const fundingRefs = {
voluntary: {},
shared: {}
};
const buildingRefs = {};
function createEquipment(group, key, x) {
if (key === "heat") {
addBox(group, 1.65, 0.28, 0.9, x, 0.92, -2.3, "#526e70");
for (let i = -1; i <= 1; i++) {
addBox(group, 0.22, 1.15, 0.65, x + i * 0.43, 1.52, -2.3, SERVICES.heat.color);
}
} else if (key === "food") {
addBox(group, 1.75, 0.85, 1.05, x, 0.96, -2.35, "#557969");
addBox(group, 1.9, 0.18, 1.18, x, 1.45, -2.35, "#e3d3a6");
addBox(group, 0.55, 0.48, 0.55, x - 0.46, 1.76, -2.36, SERVICES.food.color);
addBox(group, 0.48, 0.42, 0.48, x + 0.42, 1.72, -2.36, "#d8b75d");
} else if (key === "care") {
addBox(group, 1.7, 0.34, 1.15, x, 1.05, -2.3, "#476c80");
addBox(group, 1.55, 0.24, 1.0, x, 1.32, -2.3, "#d9e9e8");
addBox(group, 0.8, 0.18, 0.48, x, 1.53, -2.55, "#f5f2e8");
} else {
for (let level = 0; level < 2; level++) {
addBox(group, 1.75, 0.22, 1.12, x, 0.98 + level * 1.05, -2.35, "#6f6087");
addBox(group, 1.48, 0.22, 0.95, x, 1.16 + level * 1.05, -2.35, "#e3d9eb");
addBox(group, 0.55, 0.18, 0.7, x - 0.38, 1.35 + level * 1.05, -2.48, "#f1e9f4");
}
}
}
function createBuilding(x, policyKey, title, accent) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
addBox(group, 14.2, 0.5, 11.3, 0, 0.25, 0, "#e7e3d4");
addBox(group, 13.6, 0.16, 10.8, 0, 0.59, 0, "#f4f0e2");
addBox(group, 14, 4.9, 0.3, 0, 3.02, -5.1, "#e8e8dd");
for (const side of [-1, 1]) {
addBox(group, 0.18, 4.5, 9.7, side * 6.9, 2.75, -0.25, "#c7dcd8", {
opacity: 0.24
});
addBox(group, 0.42, 5.1, 0.42, side * 6.7, 2.95, 4.95, accent);
}
addBox(group, 14, 0.38, 0.48, 0, 5.22, 4.95, accent);
addBox(group, 14, 0.34, 2.4, 0, 5.3, -3.92, accent);
addBox(group, 14, 0.18, 0.2, 0, 5.48, -2.7, "#c3d4ce");
const bayPositions = [-4.8, -1.6, 1.6, 4.8];
SERVICE_ORDER.forEach((key, index) => {
const bayX = bayPositions[index];
const tile = addBox(
group,
2.76,
0.12,
6.9,
bayX,
0.75,
-0.25,
SERVICES[key].color,
{ roughness: 0.9 }
);
createEquipment(group, key, bayX);
const roomLabel = makeTextSprite(
SERVICES[key].name.toUpperCase(),
"#fffdf3",
"#34555b",
1.72,
0.43,
{ depthTest: true, renderOrder: 1 }
);
roomLabel.position.set(bayX, 3.9, -4.86);
group.add(roomLabel);
addBox(group, 1.02, 0.16, 1.02, bayX, 0.82, 2.1, "#718586");
const units = [];
for (let unitIndex = 0; unitIndex < 8; unitIndex++) {
const cube = addBox(
group,
0.43,
0.43,
0.43,
bayX,
1.12 + unitIndex * 0.45,
2.1,
SERVICES[key].color,
{ roughness: 0.62 }
);
cube.visible = false;
units.push(cube);
}
fundingRefs[policyKey][key] = { tile, units };
});
const titleSprite = makeTextSprite(
title.toUpperCase(),
accent,
"#fffdf3",
5.4,
1.15,
{ depthTest: false, renderOrder: 3 }
);
titleSprite.position.set(0, 5.25, 5.18);
group.add(titleSprite);
const anchor = new THREE.Object3D();
anchor.position.set(0, 6.6, 0);
group.add(anchor);
buildingRefs[policyKey] = { group, anchor };
}
createBuilding(-11, "voluntary", "Voluntary", "#d8794f");
createBuilding(11, "shared", "Shared", "#2b7e78");
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addBox(group, 0.62, 2.8, 0.62, 0, 1.4, 0, "#84694e");
addBox(group, 2.7, 1.25, 2.7, 0, 3.05, 0, "#6f9b73");
addBox(group, 2.1, 1.35, 2.1, 0, 4.05, 0, "#78a777");
addBox(group, 1.25, 1.1, 1.25, 0.3, 4.95, -0.1, "#8ab783");
}
createTree(-4.4, 7.3, 0.83);
createTree(4.4, 7.3, 0.78);
createTree(-4.5, -7.3, 0.66);
createTree(4.5, -7.3, 0.66);
const sign = makeTextSprite(
"CEDAR COMMONS",
"#173c42",
"#f0c26d",
6.7,
1.55,
{ depthTest: false, renderOrder: 4 }
);
sign.position.set(0, 2.05, -7.2);
scene.add(sign);
addBox(scene, 0.38, 3.6, 0.38, 0, 1.8, -7.25, "#315b5e");
addBox(scene, 2.2, 0.25, 0.3, 0, 0.5, -7.25, "#315b5e");
const people = [];
function createPerson(x, z, shirt, phase) {
const group = new THREE.Group();
group.position.set(x, 0.03, z);
scene.add(group);
addBox(group, 0.42, 0.43, 0.42, 0, 1.35, 0, "#d9b18f");
addBox(group, 0.62, 0.78, 0.42, 0, 0.78, 0, shirt);
addBox(group, 0.2, 0.48, 0.24, -0.18, 0.22, 0, "#455d64");
addBox(group, 0.2, 0.48, 0.24, 0.18, 0.22, 0, "#455d64");
people.push({ group, baseY: group.position.y, phase });
}
[
[-2.4, 2.7, "#4d8b83"],
[-1.3, 4.2, "#d58a55"],
[-0.2, 2.5, "#7d72a0"],
[1.0, 4.3, "#5d85a8"],
[2.2, 2.7, "#b8a44e"],
[0.2, 5.6, "#679b70"]
].forEach((person, index) => {
createPerson(...person, index * 0.72);
});
const benchMaterial = getMaterial("#7a6551");
for (const z of [-1.8, 5.8]) {
const bench = new THREE.Group();
bench.position.set(3.1, 0, z);
scene.add(bench);
addBox(bench, 2.4, 0.25, 0.55, 0, 0.65, 0, "#8b7258");
addBox(bench, 2.4, 0.8, 0.18, 0, 1.05, -0.3, "#8b7258");
addBox(bench, 0.2, 0.55, 0.45, -0.85, 0.35, 0, "#4e5e5d");
addBox(bench, 0.2, 0.55, 0.45, 0.85, 0.35, 0, "#4e5e5d");
}
function buildingCardMarkup(result, title) {
return `
<h3>${title}</h3>
<div class="building-score">
<strong>${result.fundedTotal}</strong>
<span>/ ${result.totalNeed} units funded</span>
</div>
<div class="building-mini">
${SERVICE_ORDER.map(key => {
const coverage = result.needs[key]
? result.funded[key] / result.needs[key] * 100
: 0;
return `
<div class="mini-line">
<span>${SERVICES[key].name}</span>
<div class="mini-track">
<div
class="mini-fill"
style="width:${coverage}%;background:${SERVICES[key].color}"
></div>
</div>
<span>${result.funded[key]}/${result.needs[key]}</span>
</div>
`;
}).join("")}
</div>
`;
}
function updateSceneResults(voluntary, shared) {
for (const policy of ["voluntary", "shared"]) {
const result = policy === "voluntary" ? voluntary : shared;
for (const key of SERVICE_ORDER) {
const refs = fundingRefs[policy][key];
refs.units.forEach((unit, index) => {
unit.visible = index < result.funded[key];
});
const coverage = result.needs[key]
? result.funded[key] / result.needs[key]
: 0;
refs.tile.material.color
.set(SERVICES[key].color)
.lerp(new THREE.Color("#dedfd5"), (1 - coverage) * 0.42);
}
}
dom.voluntaryCard.innerHTML = buildingCardMarkup(voluntary, "Voluntary");
dom.sharedCard.innerHTML = buildingCardMarkup(shared, "Agreed shared");
}
const projected = new THREE.Vector3();
function positionBuildingCards() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
for (const [policy, element] of [
["voluntary", dom.voluntaryCard],
["shared", dom.sharedCard]
]) {
const anchor = buildingRefs[policy].anchor;
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
}
function zoomScene(factor) {
cameraState.viewSize = clamp(cameraState.viewSize * factor, 19, 38);
resizeScene();
}
function resetCamera() {
cameraState.yaw = 0.31;
cameraState.pitch = 0.57;
cameraState.viewSize = 30;
updateCamera();
resizeScene();
}
document.getElementById("zoomIn").addEventListener("click", () => zoomScene(0.88));
document.getElementById("zoomOut").addEventListener("click", () => zoomScene(1.12));
document.getElementById("resetView").addEventListener("click", resetCamera);
canvas.addEventListener("pointerdown", event => {
cameraState.dragging = true;
cameraState.pointerId = event.pointerId;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!cameraState.dragging || event.pointerId !== cameraState.pointerId) return;
const deltaX = event.clientX - cameraState.lastX;
const deltaY = event.clientY - cameraState.lastY;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = clamp(cameraState.pitch + deltaY * 0.004, 0.32, 0.98);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== cameraState.pointerId) return;
cameraState.dragging = false;
cameraState.pointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
zoomScene(event.deltaY > 0 ? 1.08 : 0.92);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", event => {
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "+", "-", "0"].includes(event.key)) {
return;
}
event.preventDefault();
if (event.key === "ArrowLeft") cameraState.yaw -= 0.08;
if (event.key === "ArrowRight") cameraState.yaw += 0.08;
if (event.key === "ArrowUp") cameraState.pitch = clamp(cameraState.pitch + 0.05, 0.32, 0.98);
if (event.key === "ArrowDown") cameraState.pitch = clamp(cameraState.pitch - 0.05, 0.32, 0.98);
if (event.key === "+" || event.key === "=") zoomScene(0.9);
if (event.key === "-") zoomScene(1.1);
if (event.key === "0") resetCamera();
updateCamera();
});
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
people.forEach(person => {
person.group.position.y =
person.baseY + Math.sin(elapsed * 1.35 + person.phase) * 0.025;
});
}
scene.updateMatrixWorld();
camera.updateMatrixWorld();
positionBuildingCards();
renderer.render(scene, camera);
}
renderRound();
renderContributionRows();
updateLiveResults();
updateCamera();
resizeScene();
animate();
</script>
</body>
</html>
```