Prompt specification
Build or customize the Three.js 3D scene "Changing a Rule Transparently" 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: Changing a Rule Transparently
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/changing-a-rule-transparently-x3264
Scene Description Prompt:
Build a low-poly community hall booking simulation; replay identical requests under dated rule versions and compare allocations. Three.js from cdnjs, one HTML file.
Acceptance criteria: Keep the renderer canvas CSS height and width stable. On resizing do not modify the dimensions of the ResizeObserver target inside its callback. Exercise both fictional rule versions in the replay.
Technical checks: Keep the canvas dimensions stable and avoid resizing the observer target in its own callback. Show that replay runs under each of the two rule versions.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (changing-a-rule-transparently-x3264):
```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="#f3f2ec">
<title>Common Ground — Community Hall Allocation Replay</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='16' fill='%2317786d'/%3E%3Cpath d='M13 30 32 16l19 14v20H13z' fill='%23fff'/%3E%3Cpath d='M27 50V34h10v16' fill='%2317786d'/%3E%3C/svg%3E">
<style>
:root {
--paper: #f3f2ec;
--card: #ffffff;
--ink: #172622;
--muted: #6a7772;
--line: #dde3dc;
--line-strong: #cbd4cc;
--green: #17786d;
--green-dark: #10584f;
--green-soft: #e4f2ed;
--amber: #d99828;
--amber-soft: #fbf0d8;
--red: #c9574e;
--red-soft: #f9e5e1;
--blue: #637bd8;
--shadow: 0 12px 35px rgba(31, 48, 42, 0.07);
}
* {
box-sizing: border-box;
}
html {
color-scheme: light;
background: var(--paper);
}
body {
margin: 0;
min-width: 320px;
background:
radial-gradient(circle at 82% 8%, rgba(48, 139, 121, 0.07), transparent 25rem),
var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-variant-numeric: tabular-nums;
}
button,
input,
select,
textarea {
font: inherit;
}
button {
color: inherit;
}
.topbar {
position: sticky;
top: 0;
z-index: 30;
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 28px;
background: rgba(255, 255, 255, 0.92);
border-bottom: 1px solid rgba(205, 214, 206, 0.9);
backdrop-filter: blur(18px);
}
.brand {
display: flex;
align-items: center;
gap: 11px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border-radius: 12px;
background: var(--green);
box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.08);
}
.brand-mark::before {
content: "";
position: absolute;
left: 8px;
right: 8px;
bottom: 8px;
height: 15px;
background: #fff;
clip-path: polygon(50% 0, 100% 42%, 91% 42%, 91% 100%, 9% 100%, 9% 42%, 0 42%);
}
.brand-copy {
display: grid;
line-height: 1.12;
}
.brand-copy strong {
font-size: 15px;
letter-spacing: -0.01em;
}
.brand-copy small {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 18px;
}
.deterministic-badge {
display: flex;
align-items: center;
gap: 8px;
color: #4d625b;
font-size: 12px;
font-weight: 650;
}
.deterministic-badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: #32a57f;
box-shadow: 0 0 0 4px rgba(50, 165, 127, 0.12);
}
.button {
border: 0;
border-radius: 11px;
padding: 11px 15px;
cursor: pointer;
font-size: 13px;
font-weight: 750;
transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
}
.button:focus-visible,
.rule-card:focus-visible,
tr:focus-visible {
outline: 3px solid rgba(23, 120, 109, 0.25);
outline-offset: 3px;
}
.button:disabled {
cursor: wait;
opacity: 0.66;
}
.button-primary {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 9px;
background: var(--green);
color: #fff;
box-shadow: 0 7px 18px rgba(23, 120, 109, 0.18);
}
.button-primary:hover:not(:disabled) {
background: var(--green-dark);
}
.button-secondary {
background: #edf1ed;
color: #34534c;
}
.play-icon {
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid currentColor;
}
.app-shell {
width: min(1560px, 100%);
margin: 0 auto;
display: grid;
grid-template-columns: 324px minmax(0, 1fr);
gap: 24px;
padding: 26px 28px 46px;
}
.sidebar {
min-width: 0;
}
.intro {
padding: 4px 4px 21px;
}
.eyebrow {
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.intro h1 {
margin: 11px 0 10px;
font-size: clamp(29px, 3vw, 40px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.card {
background: var(--card);
border: 1px solid var(--line);
border-radius: 17px;
box-shadow: var(--shadow);
}
.replay-card {
padding: 17px;
margin-bottom: 16px;
}
.card-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.card-heading h2,
.card-heading h3 {
margin: 0;
font-size: 13px;
letter-spacing: -0.01em;
}
.status-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 999px;
background: var(--green-soft);
color: var(--green-dark);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
}
.status-chip::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: currentColor;
}
.replay-summary {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 12px;
}
.summary-cell {
padding: 9px 8px;
background: #f6f7f3;
border: 1px solid #e8ece6;
border-radius: 10px;
}
.summary-cell strong {
display: block;
font-size: 14px;
}
.summary-cell small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.2;
}
.full-button {
width: 100%;
}
.progress-track {
height: 5px;
margin: 14px 0 12px;
overflow: hidden;
border-radius: 999px;
background: #e9ede8;
}
.progress-bar {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--green), #4cae92);
transition: width 220ms ease;
}
.replay-log {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
}
.replay-log li {
display: grid;
grid-template-columns: 40px 1fr;
gap: 8px;
align-items: center;
color: #7a8681;
font-size: 10px;
transition: color 180ms ease;
}
.replay-log time {
color: #9aa49f;
font-size: 9px;
font-weight: 700;
}
.replay-log li.done {
color: #36564e;
}
.replay-log li.active {
color: var(--green);
font-weight: 750;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 22px 4px 10px;
color: #7a8782;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.rule-list {
display: grid;
gap: 9px;
}
.rule-card {
position: relative;
width: 100%;
padding: 14px 14px 13px 16px;
text-align: left;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.75);
cursor: pointer;
transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}
.rule-card::before {
content: "";
position: absolute;
top: 14px;
bottom: 14px;
left: 0;
width: 3px;
border-radius: 0 4px 4px 0;
background: var(--rule-color);
}
.rule-card:hover,
.rule-card.is-focused {
transform: translateY(-1px);
border-color: var(--rule-color);
background: #fff;
}
.rule-topline {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.rule-date {
color: var(--rule-color);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.rule-count {
color: #73807b;
font-size: 9px;
font-weight: 700;
}
.rule-card strong {
display: block;
margin-top: 6px;
font-size: 13px;
}
.rule-card p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.source-card {
padding: 14px;
}
.source-card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.source-card-header strong {
font-size: 12px;
}
.source-card-header span {
color: var(--muted);
font-size: 9px;
}
.source-list {
display: grid;
max-height: 218px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #cbd4cd transparent;
}
.source-row {
display: grid;
grid-template-columns: 51px minmax(0, 1fr) auto;
gap: 7px;
align-items: center;
padding: 8px 2px;
border-top: 1px solid #edf0ec;
font-size: 9px;
}
.source-row:first-child {
border-top: 0;
}
.source-id {
color: var(--green);
font-weight: 800;
}
.source-name {
overflow: hidden;
color: #52635d;
text-overflow: ellipsis;
white-space: nowrap;
}
.source-time {
color: #8a9691;
}
.technical-note {
display: flex;
gap: 9px;
margin: 14px 4px 0;
color: #83908b;
font-size: 9px;
line-height: 1.45;
}
.technical-note::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 50%;
background: #9baaa4;
box-shadow: 0 0 0 3px #e4e8e3;
}
.workspace {
min-width: 0;
}
.workspace-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
margin: 2px 2px 17px;
}
.workspace-header h2 {
margin: 5px 0 0;
font-size: clamp(22px, 2.6vw, 31px);
letter-spacing: -0.035em;
}
.workspace-header p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
}
.date-pill {
display: inline-flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.7);
color: #52635d;
font-size: 10px;
font-weight: 700;
}
.date-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--green);
}
.metrics {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 11px;
margin-bottom: 14px;
}
.metric {
position: relative;
min-height: 94px;
padding: 15px 16px;
overflow: hidden;
background: rgba(255, 255, 255, 0.87);
border: 1px solid var(--line);
border-radius: 15px;
box-shadow: 0 8px 25px rgba(31, 48, 42, 0.045);
}
.metric::after {
content: "";
position: absolute;
right: -16px;
bottom: -28px;
width: 74px;
height: 74px;
border-radius: 50%;
background: var(--metric-soft, #edf3ef);
}
.metric-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
display: block;
margin-top: 8px;
font-size: 25px;
font-weight: 780;
letter-spacing: -0.04em;
}
.metric-note {
display: block;
margin-top: 4px;
color: #7c8883;
font-size: 9px;
}
.metric.delta .metric-value {
color: var(--green);
}
.map-card {
overflow: hidden;
margin-bottom: 14px;
}
.map-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 14px 17px;
border-bottom: 1px solid var(--line);
}
.map-title {
display: flex;
align-items: center;
gap: 10px;
}
.map-title-icon {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border-radius: 9px;
background: var(--green-soft);
color: var(--green);
}
.map-title strong {
display: block;
font-size: 12px;
}
.map-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 11px;
color: #68756f;
font-size: 9px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--dot-color);
}
#viewport {
position: relative;
width: 100%;
height: 540px;
overflow: hidden;
isolation: isolate;
contain: layout paint;
background: #e8ede8;
}
/* The canvas CSS box is stable and absolute, so its drawing buffer never
affects the ResizeObserver target's layout. */
#viewport > canvas {
position: absolute;
inset: 0;
display: block;
width: 100% !important;
height: 100% !important;
pointer-events: none;
}
.stage-divider {
position: absolute;
z-index: 4;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: rgba(73, 91, 83, 0.16);
pointer-events: none;
}
.version-overlay {
position: absolute;
z-index: 5;
top: 15px;
width: calc(50% - 31px);
max-width: 430px;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 8px 24px rgba(32, 49, 43, 0.08);
backdrop-filter: blur(10px);
pointer-events: none;
transition: transform 200ms ease, box-shadow 200ms ease;
}
.version-overlay.flash {
transform: translateY(2px);
box-shadow: 0 0 0 3px rgba(23, 120, 109, 0.18), 0 10px 28px rgba(32, 49, 43, 0.12);
}
.version-one {
left: 15px;
}
.version-two {
left: calc(50% + 15px);
}
.version-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.version-date {
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.version-number {
padding: 4px 6px;
border-radius: 6px;
background: #edf1ed;
color: #66746e;
font-size: 8px;
font-weight: 850;
text-transform: uppercase;
}
.version-title {
display: flex;
align-items: baseline;
gap: 7px;
margin-top: 5px;
}
.version-title strong {
font-size: 14px;
letter-spacing: -0.02em;
}
.version-title span {
color: #6f7c77;
font-size: 9px;
}
.version-stats {
display: flex;
align-items: center;
justify-content: space-between;
gap: 9px;
margin-top: 7px;
color: #74807b;
font-size: 8px;
}
.version-stats strong {
color: var(--ink);
font-size: 11px;
}
.version-rooms {
padding-top: 6px;
border-top: 1px solid rgba(199, 210, 202, 0.65);
color: #68766f;
font-size: 8px;
white-space: nowrap;
}
.map-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 15px;
border-top: 1px solid var(--line);
background: #fafbf8;
color: #7b8782;
font-size: 9px;
}
.map-footer strong {
color: #50635c;
}
.table-card {
overflow: hidden;
}
.table-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
padding: 15px 17px;
border-bottom: 1px solid var(--line);
}
.table-header h3 {
margin: 0;
font-size: 13px;
}
.table-header p {
margin: 5px 0 0;
color: var(--muted);
font-size: 9px;
}
.changed-key {
display: inline-flex;
align-items: center;
gap: 6px;
color: #6e7b76;
font-size: 9px;
white-space: nowrap;
}
.changed-key::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: #f0c96b;
}
.selection-note {
min-height: 47px;
padding: 10px 17px;
border-bottom: 1px solid #e6ebe5;
background: #f8faf7;
color: #66756f;
font-size: 10px;
line-height: 1.5;
}
.selection-note strong {
color: var(--green-dark);
}
.table-scroll {
overflow-x: auto;
}
table {
width: 100%;
min-width: 900px;
border-collapse: collapse;
font-size: 10px;
}
th {
padding: 10px 12px;
text-align: left;
background: #f4f6f2;
color: #7b8883;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
td {
padding: 11px 12px;
border-top: 1px solid #edf0eb;
vertical-align: middle;
}
tbody tr {
cursor: pointer;
transition: background 130ms ease;
}
tbody tr:hover,
tbody tr.is-selected {
background: #f2f8f4;
}
tbody tr.changed td:first-child {
box-shadow: inset 3px 0 0 #e4b344;
}
.request-id {
color: var(--green);
font-weight: 820;
}
.request-name {
color: #334740;
font-weight: 680;
}
.request-time,
.muted-cell {
color: #7b8782;
}
.room-pill,
.wait-pill,
.delta-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
border-radius: 7px;
white-space: nowrap;
font-size: 9px;
font-weight: 720;
}
.room-pill {
background: color-mix(in srgb, var(--room-color) 12%, white);
color: color-mix(in srgb, var(--room-color) 75%, #263a34);
}
.room-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--room-color);
}
.wait-pill {
background: var(--red-soft);
color: #a3443c;
}
.delta-pill {
background: #f0f2ed;
color: #75817c;
}
.delta-pill.changed {
background: var(--amber-soft);
color: #9a6811;
}
.toast {
position: fixed;
z-index: 80;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 12px 15px;
border: 1px solid #cfe1d8;
border-radius: 12px;
background: rgba(255, 255, 255, 0.95);
box-shadow: 0 14px 40px rgba(31, 48, 42, 0.14);
color: #36574e;
font-size: 11px;
font-weight: 700;
opacity: 0;
transform: translateY(12px);
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translateY(0);
}
.toast::before {
content: "✓";
display: grid;
width: 20px;
height: 20px;
place-items: center;
border-radius: 50%;
background: var(--green-soft);
color: var(--green);
font-weight: 900;
}
@media (max-width: 1100px) {
.app-shell {
grid-template-columns: 285px minmax(0, 1fr);
padding-inline: 20px;
}
.metrics {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.version-rooms {
white-space: normal;
}
}
@media (max-width: 860px) {
.topbar {
padding-inline: 18px;
}
.deterministic-badge {
display: none;
}
.app-shell {
grid-template-columns: 1fr;
padding: 20px 18px 38px;
}
.sidebar {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.intro,
.technical-note {
grid-column: 1 / -1;
}
.section-label {
grid-column: 1 / -1;
margin-bottom: -2px;
}
.source-card {
grid-column: 1 / -1;
}
.source-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: 18px;
max-height: none;
}
}
@media (max-width: 720px) {
.topbar {
height: 62px;
}
.brand-copy small {
display: none;
}
.top-actions .button {
padding: 9px 11px;
font-size: 11px;
}
.app-shell {
padding-inline: 12px;
}
.sidebar {
grid-template-columns: 1fr;
}
.intro,
.technical-note,
.section-label,
.source-card {
grid-column: auto;
}
.rule-list {
grid-template-columns: 1fr 1fr;
}
.source-list {
grid-template-columns: 1fr;
}
.workspace-header {
align-items: flex-start;
flex-direction: column;
}
.metrics {
gap: 8px;
}
.metric {
min-height: 87px;
padding: 13px;
}
.metric-value {
font-size: 22px;
}
.map-header,
.table-header {
align-items: flex-start;
flex-direction: column;
}
.legend {
justify-content: flex-start;
}
#viewport {
height: 760px;
}
.stage-divider {
top: 50%;
right: 0;
bottom: auto;
left: 0;
width: 100%;
height: 1px;
}
.version-overlay {
width: calc(100% - 30px);
max-width: none;
}
.version-one {
top: 12px;
left: 15px;
}
.version-two {
top: calc(50% + 12px);
left: 15px;
}
.map-footer {
align-items: flex-start;
flex-direction: column;
}
}
@media (max-width: 430px) {
.rule-list {
grid-template-columns: 1fr;
}
.metrics {
grid-template-columns: 1fr 1fr;
}
.version-title span {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Common Ground</strong>
<small>Allocation policy lab</small>
</div>
</div>
<div class="top-actions">
<div class="deterministic-badge">Deterministic replay</div>
<button class="button button-primary" id="topReplayButton" type="button">
<span class="play-icon" aria-hidden="true"></span>
Replay
</button>
</div>
</header>
<main class="app-shell">
<aside class="sidebar">
<section class="intro">
<div class="eyebrow">Community facilities / Simulation 04</div>
<h1>One booking list.<br>Two fair outcomes.</h1>
<p>Replay the same nine requests under two dated rule versions and inspect how policy changes room assignments.</p>
</section>
<section class="card replay-card" aria-labelledby="replayHeading">
<div class="card-heading">
<h2 id="replayHeading">Comparison run</h2>
<span class="status-chip" id="replayStatus" aria-live="polite">Complete</span>
</div>
<div class="replay-summary">
<div class="summary-cell">
<strong>9</strong>
<small>frozen requests</small>
</div>
<div class="summary-cell">
<strong>18 May</strong>
<small>shared date</small>
</div>
<div class="summary-cell">
<strong>4</strong>
<small>eligible rooms</small>
</div>
</div>
<button class="button button-primary full-button" id="replayButton" type="button">
<span class="play-icon" aria-hidden="true"></span>
<span id="replayButtonLabel">Replay both versions</span>
</button>
<div class="progress-track" aria-hidden="true">
<div class="progress-bar" id="progressBar"></div>
</div>
<ol class="replay-log" id="replayLog">
<li data-step="0" class="done"><time>00:00</time><span>Input ledger frozen</span></li>
<li data-step="1" class="done"><time>00:01</time><span>2022 policy solved</span></li>
<li data-step="2" class="done"><time>00:02</time><span>2024 policy solved</span></li>
<li data-step="3" class="done"><time>00:03</time><span>Decisions compared</span></li>
</ol>
</section>
<div class="section-label">
<span>Rule versions</span>
<span>Click to inspect</span>
</div>
<section class="rule-list" aria-label="Fictional booking rule versions">
<button class="rule-card" id="ruleCardV1" type="button" style="--rule-color:#9d7047" aria-pressed="false">
<div class="rule-topline">
<span class="rule-date">2022-05-01 · Rule v1</span>
<span class="rule-count" id="ruleCountV1">7 accepted</span>
</div>
<strong>Fixed-room policy</strong>
<p>Exact room only, strict capacity, first-arrival order, no relocation.</p>
</button>
<button class="rule-card" id="ruleCardV2" type="button" style="--rule-color:#17786d" aria-pressed="false">
<div class="rule-topline">
<span class="rule-date">2024-09-01 · Rule v2</span>
<span class="rule-count" id="ruleCountV2">9 accepted</span>
</div>
<strong>Shared-inventory policy</strong>
<p>Capacity and overlap checks, compatible spillover, closest suitable room.</p>
</button>
</section>
<section class="card source-card">
<div class="source-card-header">
<strong>Identical replay input</strong>
<span>Arrival order</span>
</div>
<div class="source-list" id="sourceList"></div>
</section>
<div class="technical-note">Single Three.js canvas with two scissor-rendered scenes. The observed layout box is never resized from its observer callback.</div>
</aside>
<section class="workspace">
<header class="workspace-header">
<div>
<div class="eyebrow">Dated policy comparison</div>
<h2>Community hall allocation replay</h2>
<p>Same demand, same arrival order, two published fictional rule sets.</p>
</div>
<div class="date-pill">18 May 2025 · 09:00–16:30</div>
</header>
<section class="metrics" aria-label="Replay summary">
<article class="metric">
<span class="metric-label">Identical inputs</span>
<strong class="metric-value" id="metricInputs">9</strong>
<span class="metric-note">Frozen for every policy</span>
</article>
<article class="metric">
<span class="metric-label">2022 approvals</span>
<strong class="metric-value" id="metricV1">7 / 9</strong>
<span class="metric-note">2 requests waitlisted</span>
</article>
<article class="metric" style="--metric-soft:#e4f2ed">
<span class="metric-label">2024 approvals</span>
<strong class="metric-value" id="metricV2">9 / 9</strong>
<span class="metric-note">No requests waitlisted</span>
</article>
<article class="metric delta" style="--metric-soft:#e4f2ed">
<span class="metric-label">Policy shifts</span>
<strong class="metric-value" id="metricChanges">2</strong>
<span class="metric-note">Decisions changed after spillover</span>
</article>
</section>
<section class="card map-card" aria-labelledby="mapHeading">
<div class="map-header">
<div class="map-title">
<div class="map-title-icon" aria-hidden="true">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none">
<path d="M4 5.5 12 2l8 3.5v9L12 22l-8-7.5v-9Z" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
<path d="M4 5.5 12 9l8-3.5M12 9v13M8 7v7l4 2 4-2V7" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
</svg>
</div>
<div>
<strong id="mapHeading">Cutaway allocation map</strong>
<small>Request markers show room assignments, not concurrent headcount</small>
</div>
</div>
<div class="legend" aria-label="Booking category legend">
<span class="legend-item"><i class="legend-dot" style="--dot-color:#2f9e91"></i>Community</span>
<span class="legend-item"><i class="legend-dot" style="--dot-color:#e6a63a"></i>Civic</span>
<span class="legend-item"><i class="legend-dot" style="--dot-color:#ec7669"></i>Commercial</span>
<span class="legend-item"><i class="legend-dot" style="--dot-color:#637bd8"></i>Education</span>
</div>
</div>
<div id="viewport" role="img" aria-label="Side-by-side low-poly community hall maps showing allocations under 2022 and 2024 rule versions">
<div class="stage-divider" aria-hidden="true"></div>
<div class="version-overlay version-one" id="v1Overlay">
<div class="version-top">
<span class="version-date">2022-05-01</span>
<span class="version-number">Rule v1</span>
</div>
<div class="version-title">
<strong>Fixed room</strong>
<span>exact preferences only</span>
</div>
<div class="version-stats">
<span><strong id="v1Accepted">7 / 9</strong> accepted</span>
<span><strong id="v1Waiting">2</strong> waiting</span>
</div>
<div class="version-rooms" id="v1Rooms">Oak 2 · Cedar 2 · Garden 1 · Annex 2</div>
</div>
<div class="version-overlay version-two" id="v2Overlay">
<div class="version-top">
<span class="version-date">2024-09-01</span>
<span class="version-number">Rule v2</span>
</div>
<div class="version-title">
<strong>Shared inventory</strong>
<span>compatible spillover</span>
</div>
<div class="version-stats">
<span><strong id="v2Accepted">9 / 9</strong> accepted</span>
<span><strong id="v2Waiting">0</strong> waiting</span>
</div>
<div class="version-rooms" id="v2Rooms">Oak 2 · Cedar 4 · Garden 1 · Annex 2</div>
</div>
</div>
<div class="map-footer">
<span><strong>Map key:</strong> colored pads are bookings; red flags are waitlisted requests.</span>
<span>Orthographic cutaway · synchronized replay</span>
</div>
</section>
<section class="card table-card" aria-labelledby="ledgerHeading">
<div class="table-header">
<div>
<h3 id="ledgerHeading">Decision ledger</h3>
<p>Select a row to highlight the same request in both scenes.</p>
</div>
<span class="changed-key">Amber rows changed under the newer policy</span>
</div>
<div class="selection-note" id="selectionNote" aria-live="polite"></div>
<div class="table-scroll">
<table>
<thead>
<tr>
<th>Request</th>
<th>Booking</th>
<th>Time</th>
<th>People</th>
<th>2022 · v1</th>
<th>2024 · v2</th>
<th>Policy result</th>
</tr>
</thead>
<tbody id="requestRows"></tbody>
</table>
</div>
</section>
</section>
</main>
<div class="toast" id="toast" role="status" aria-live="polite">Both rule versions replayed successfully</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const CATEGORY_COLORS = {
Community: 0x2f9e91,
Civic: 0xe6a63a,
Commercial: 0xec7669,
Education: 0x637bd8
};
const ROOMS = [
{ id: "oak", name: "Oak Hall", short: "Oak", capacity: 64, x: -2.35, z: -1.55, color: "#9d7047", floor: 0xf0e7d6, stepFree: true },
{ id: "cedar", name: "Cedar Studio", short: "Cedar", capacity: 36, x: 2.35, z: -1.55, color: "#17786d", floor: 0xe3efe8, stepFree: true },
{ id: "garden", name: "Garden Room", short: "Garden", capacity: 28, x: -2.35, z: 1.55, color: "#6f9852", floor: 0xe8efdc, stepFree: false },
{ id: "annex", name: "Annex Room", short: "Annex", capacity: 18, x: 2.35, z: 1.55, color: "#637bd8", floor: 0xe8e9f5, stepFree: true }
];
const roomById = new Map(ROOMS.map((room) => [room.id, room]));
const REQUESTS = [
{ id: "REQ-101", group: "Neighborhood choir", size: 18, preferred: "cedar", start: 540, end: 600, category: "Community", accessible: false },
{ id: "REQ-103", group: "Weekend market", size: 40, preferred: "oak", start: 570, end: 660, category: "Civic", accessible: true },
{ id: "REQ-106", group: "Local product launch", size: 28, preferred: "oak", start: 600, end: 720, category: "Commercial", accessible: false },
{ id: "REQ-102", group: "Youth coding club", size: 22, preferred: "oak", start: 660, end: 780, category: "Community", accessible: true },
{ id: "REQ-104", group: "Seed workshop", size: 14, preferred: "garden", start: 780, end: 900, category: "Community", accessible: false },
{ id: "REQ-107", group: "Digital skills class", size: 16, preferred: "annex", start: 780, end: 840, category: "Education", accessible: true },
{ id: "REQ-105", group: "Therapy circle", size: 10, preferred: "annex", start: 840, end: 960, category: "Community", accessible: true },
{ id: "REQ-108", group: "Open art jam", size: 20, preferred: "cedar", start: 870, end: 990, category: "Community", accessible: false },
{ id: "REQ-109", group: "Repair network", size: 8, preferred: "annex", start: 810, end: 870, category: "Civic", accessible: false }
];
const requestById = new Map(REQUESTS.map((request) => [request.id, request]));
function overlaps(first, second) {
return first.start < second.end && second.start < first.end;
}
function roomDistance(firstId, secondId) {
const first = roomById.get(firstId);
const second = roomById.get(secondId);
return Math.abs(first.x - second.x) + Math.abs(first.z - second.z);
}
function solveV1(input) {
const schedules = Object.fromEntries(ROOMS.map((room) => [room.id, []]));
const result = {};
for (const request of input) {
const room = roomById.get(request.preferred);
const conflict = schedules[room.id].find((booking) => overlaps(request, booking.request));
if (room.capacity >= request.size && !conflict) {
schedules[room.id].push({ request });
result[request.id] = {
status: "booked",
room: room.id,
reason: `Preferred ${room.name} was available`
};
} else {
const conflictNames = schedules[room.id]
.filter((booking) => overlaps(request, booking.request))
.map((booking) => booking.request.id)
.join(", ");
result[request.id] = {
status: "waiting",
room: null,
reason: conflict
? `${room.name} conflicts with ${conflictNames}; fixed-room rule cannot relocate`
: `${room.name} does not meet the required capacity`
};
}
}
return result;
}
function solveV2(input) {
const schedules = Object.fromEntries(ROOMS.map((room) => [room.id, []]));
const result = {};
for (const request of input) {
const preferred = roomById.get(request.preferred);
const preferredConflict = schedules[preferred.id].some((booking) => overlaps(request, booking.request));
if (preferred.capacity >= request.size && !preferredConflict) {
schedules[preferred.id].push({ request });
result[request.id] = {
status: "booked",
room: preferred.id,
reason: `Preferred ${preferred.name} was available`
};
continue;
}
const candidates = ROOMS
.filter((room) => room.capacity >= request.size)
.filter((room) => !request.accessible || room.stepFree)
.filter((room) => !schedules[room.id].some((booking) => overlaps(request, booking.request)))
.sort((first, second) => {
const distanceDifference = roomDistance(first.id, request.preferred) - roomDistance(second.id, request.preferred);
if (distanceDifference !== 0) return distanceDifference;
return ROOMS.indexOf(first) - ROOMS.indexOf(second);
});
if (candidates.length) {
const target = candidates[0];
schedules[target.id].push({ request });
result[request.id] = {
status: "booked",
room: target.id,
reason: `Spilled from ${preferred.name} to ${target.name}; capacity ${request.size}/${target.capacity}`
};
} else {
result[request.id] = {
status: "waiting",
room: null,
reason: "No compatible room with enough capacity was free"
};
}
}
return result;
}
function countAccepted(result) {
return Object.values(result).filter((item) => item.status === "booked").length;
}
function roomCounts(result) {
const counts = Object.fromEntries(ROOMS.map((room) => [room.id, 0]));
for (const item of Object.values(result)) {
if (item.room) counts[item.room] += 1;
}
return counts;
}
function formatTime(minutes) {
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
}
const resultV1 = solveV1(REQUESTS);
const resultV2 = solveV2(REQUESTS);
const changedRequests = REQUESTS.filter((request) => {
const first = resultV1[request.id];
const second = resultV2[request.id];
return first.status !== second.status || first.room !== second.room;
});
const state = {
selectedRequest: "REQ-106",
hoveredRequest: null,
replaying: false,
replayTimers: []
};
function buildSourceList() {
$("sourceList").innerHTML = REQUESTS.map((request) => `
<div class="source-row">
<span class="source-id">${request.id.replace("REQ-", "R-")}</span>
<span class="source-name">${request.group}</span>
<span class="source-time">${formatTime(request.start)}</span>
</div>
`).join("");
}
function roomResultHtml(result) {
if (result.status === "waiting") {
return `<span class="wait-pill">Waitlist</span>`;
}
const room = roomById.get(result.room);
return `<span class="room-pill" style="--room-color:${room.color}">${room.name}</span>`;
}
function renderTable() {
$("requestRows").innerHTML = REQUESTS.map((request) => {
const first = resultV1[request.id];
const second = resultV2[request.id];
const changed = first.status !== second.status || first.room !== second.room;
let delta = "Unchanged";
if (first.status === "waiting" && second.status === "booked") delta = "Approved by spillover";
else if (first.status === "booked" && second.status === "waiting") delta = "Moved to waiting";
else if (first.room !== second.room) delta = "Room reassigned";
return `
<tr data-request="${request.id}" class="${changed ? "changed" : ""} ${request.id === state.selectedRequest ? "is-selected" : ""}" tabindex="0">
<td class="request-id">${request.id}</td>
<td class="request-name">${request.group}</td>
<td class="request-time">${formatTime(request.start)}–${formatTime(request.end)}</td>
<td>${request.size}</td>
<td>${roomResultHtml(first)}</td>
<td>${roomResultHtml(second)}</td>
<td><span class="delta-pill ${changed ? "changed" : ""}">${delta}</span></td>
</tr>
`;
}).join("");
$("requestRows").querySelectorAll("tr").forEach((row) => {
const id = row.dataset.request;
row.addEventListener("mouseenter", () => {
state.hoveredRequest = id;
});
row.addEventListener("mouseleave", () => {
state.hoveredRequest = null;
});
row.addEventListener("click", () => selectRequest(id));
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectRequest(id);
}
});
});
}
function selectRequest(id) {
state.selectedRequest = id;
const request = requestById.get(id);
const first = resultV1[id];
const second = resultV2[id];
$("requestRows").querySelectorAll("tr").forEach((row) => {
row.classList.toggle("is-selected", row.dataset.request === id);
});
$("selectionNote").innerHTML = `
<strong>${id} · ${request.group}</strong> — ${request.size} people, ${formatTime(request.start)}–${formatTime(request.end)},
preferred ${roomById.get(request.preferred).name}.
<strong>2022:</strong> ${first.reason}.
<strong>2024:</strong> ${second.reason}.
`;
}
function updateSummaryUI() {
const v1Accepted = countAccepted(resultV1);
const v2Accepted = countAccepted(resultV2);
const v1Waiting = REQUESTS.length - v1Accepted;
const v2Waiting = REQUESTS.length - v2Accepted;
const v1Counts = roomCounts(resultV1);
const v2Counts = roomCounts(resultV2);
$("metricInputs").textContent = REQUESTS.length;
$("metricV1").textContent = `${v1Accepted} / ${REQUESTS.length}`;
$("metricV2").textContent = `${v2Accepted} / ${REQUESTS.length}`;
$("metricChanges").textContent = changedRequests.length;
$("v1Accepted").textContent = `${v1Accepted} / ${REQUESTS.length}`;
$("v2Accepted").textContent = `${v2Accepted} / ${REQUESTS.length}`;
$("v1Waiting").textContent = v1Waiting;
$("v2Waiting").textContent = v2Waiting;
$("ruleCountV1").textContent = `${v1Accepted} accepted`;
$("ruleCountV2").textContent = `${v2Accepted} accepted`;
$("v1Rooms").textContent = ROOMS.map((room) => `${room.short} ${v1Counts[room.id]}`).join(" · ");
$("v2Rooms").textContent = ROOMS.map((room) => `${room.short} ${v2Counts[room.id]}`).join(" · ");
}
buildSourceList();
renderTable();
updateSummaryUI();
selectRequest(state.selectedRequest);
const viewport = $("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
renderer.setClearColor(0xe8ede8, 1);
renderer.domElement.className = "hall-canvas";
renderer.domElement.setAttribute("aria-label", "Interactive comparative 3D hall allocation rendering");
viewport.prepend(renderer.domElement);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(parent, width, height, depth, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeBadgeTexture(text, subtitle, background, foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = background;
roundedRect(context, 5, 7, 502, 114, 28);
context.fill();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.font = "800 42px system-ui, sans-serif";
context.fillText(text, 256, subtitle ? 49 : 65);
if (subtitle) {
context.globalAlpha = 0.78;
context.font = "650 19px system-ui, sans-serif";
context.fillText(subtitle, 256, 89);
context.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return { texture, aspect: canvas.width / canvas.height };
}
function makeSprite(text, subtitle, background, foreground, worldWidth = 1.2) {
const badge = makeBadgeTexture(text, subtitle, background, foreground);
const material = new THREE.SpriteMaterial({
map: badge.texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth / badge.aspect, 1);
sprite.renderOrder = 30;
return sprite;
}
function makeRoomLabel(room) {
const badge = makeBadgeTexture(room.name.toUpperCase(), `${room.capacity} capacity`, "rgba(255,255,255,0.9)", "#31463f");
const material = new THREE.MeshBasicMaterial({
map: badge.texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const plane = new THREE.Mesh(new THREE.PlaneGeometry(2.45, 2.45 / badge.aspect), material);
plane.rotation.x = -Math.PI / 2;
plane.position.set(room.x, 0.237, room.z < 0 ? room.z + 1.02 : room.z - 1.02);
plane.renderOrder = 2;
return plane;
}
function addTree(parent, x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.15, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.18, 1.05, 5),
standardMaterial(0x8d6b4f)
);
trunk.position.y = 0.52;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.78, 0),
standardMaterial(0x6f9870)
);
crown.position.y = 1.42;
crown.scale.set(1, 1.1, 0.92);
crown.castShadow = true;
group.add(crown);
const crownSmall = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.52, 0),
standardMaterial(0x83a77a)
);
crownSmall.position.set(0.4, 1.62, -0.08);
crownSmall.castShadow = true;
group.add(crownSmall);
parent.add(group);
}
function addLamp(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, -0.15, z);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 1.8, 6),
standardMaterial(0x52625d)
);
pole.position.y = 0.9;
pole.castShadow = true;
group.add(pole);
const lamp = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.16, 0.28),
standardMaterial(0xf1d998, { emissive: 0x8d6d20, emissiveIntensity: 0.18 })
);
lamp.position.y = 1.82;
lamp.castShadow = true;
group.add(lamp);
parent.add(group);
}
function addVisitor(parent, x, z, color, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.15, z);
group.scale.setScalar(scale);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.13, 0.38, 6),
standardMaterial(color)
);
body.position.y = 0.19;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12, 0),
standardMaterial(0xd9a77b)
);
head.position.y = 0.48;
head.castShadow = true;
group.add(head);
parent.add(group);
}
function createBookingMarker(request) {
const group = new THREE.Group();
const color = CATEGORY_COLORS[request.category];
const pad = addBox(
group,
1.28,
0.045,
0.63,
0,
0.025,
0,
color,
{ roughness: 0.72 }
);
pad.userData.isBookingPad = true;
const figureCount = Math.max(4, Math.min(6, Math.ceil(request.size / 7)));
for (let index = 0; index < figureCount; index += 1) {
const column = index % 3;
const row = Math.floor(index / 3);
const person = new THREE.Group();
person.position.set((column - 1) * 0.31, 0, (row - 0.5) * 0.25);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.09, 0.22, 5),
standardMaterial(index % 2 ? 0xf2e8d6 : 0xffffff)
);
body.position.y = 0.13;
body.castShadow = true;
person.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.085, 0),
standardMaterial(0xd7a77d)
);
head.position.y = 0.31;
head.castShadow = true;
person.add(head);
group.add(person);
}
const sign = makeSprite(request.id.replace("REQ-", "R-"), request.group, `#${color.toString(16).padStart(6, "0")}`, "#ffffff", 0.96);
sign.position.set(0, 0.76, 0);
group.add(sign);
group.userData.requestId = request.id;
group.userData.booked = false;
return group;
}
function createWaitingMarker(request) {
const group = new THREE.Group();
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 0.95, 5),
standardMaterial(0x8f4e47)
);
pole.position.y = 0.475;
pole.castShadow = true;
group.add(pole);
const sign = makeSprite(`${request.id.replace("REQ-", "R-")} · WAIT`, "No compatible room", "#b94e46", "#ffffff", 1.42);
sign.position.set(0, 1.15, 0);
group.add(sign);
group.userData.requestId = request.id;
group.visible = false;
return group;
}
function createHallScene(version, result) {
const scene = new THREE.Scene();
scene.background = new THREE.Color(version === 1 ? 0xe8eeea : 0xefede6);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
camera.position.set(10.5, 12.8, 14.5);
camera.lookAt(0, 0.3, 0.45);
scene.add(new THREE.HemisphereLight(0xf8fcff, 0x77867b, 2.15));
const sun = new THREE.DirectionalLight(0xfff3dc, 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xcce4ff, 0.85);
fillLight.position.set(8, 7, -6);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
standardMaterial(version === 1 ? 0xd9e2dc : 0xe0ded5)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.17;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(38, 38, 0xaebdb5, 0xc8d1ca);
grid.position.y = -0.158;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const hall = new THREE.Group();
scene.add(hall);
addBox(hall, 10.7, 0.28, 7.0, 0, 0, 0, 0x73847c, { roughness: 0.96 });
addBox(hall, 10.1, 0.09, 6.45, 0, 0.16, 0, 0xe5e8df);
const roomFloors = new Map();
for (const room of ROOMS) {
const floor = addBox(hall, 4.3, 0.08, 2.65, room.x, 0.205, room.z, room.floor);
floor.userData.baseColor = new THREE.Color(room.floor);
roomFloors.set(room.id, floor);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(floor.geometry),
new THREE.LineBasicMaterial({ color: 0x9caaa1, transparent: true, opacity: 0.38 })
);
edges.position.copy(floor.position);
hall.add(edges);
hall.add(makeRoomLabel(room));
}
const wallColor = 0xf3f2e9;
addBox(hall, 10.35, 0.96, 0.18, 0, 0.64, -3.28, wallColor);
addBox(hall, 10.35, 0.28, 0.18, 0, 0.30, 3.28, wallColor);
addBox(hall, 0.18, 0.58, 6.45, -5.18, 0.46, 0, wallColor);
addBox(hall, 0.18, 0.58, 6.45, 5.18, 0.46, 0, wallColor);
addBox(hall, 0.14, 0.48, 6.35, 0, 0.40, 0, wallColor);
addBox(hall, 10.25, 0.34, 0.14, 0, 0.33, 0, wallColor);
addBox(hall, 2.35, 0.13, 1.0, 0, 1.62, 3.73, 0x2c7c71);
addBox(hall, 0.11, 1.45, 0.11, -1.02, 0.90, 4.08, 0x52645e);
addBox(hall, 0.11, 1.45, 0.11, 1.02, 0.90, 4.08, 0x52645e);
addBox(hall, 2.65, 0.10, 0.72, 0, 0.02, 4.35, 0xb9beb4);
addBox(hall, 3.05, 0.10, 0.72, 0, -0.05, 5.02, 0xc8ccc2);
addBox(hall, 0.85, 0.23, 1.45, -3.92, 0.34, -1.52, 0xb58a59);
addBox(hall, 0.72, 0.42, 1.75, 4.02, 0.37, -1.48, 0x839b91);
addBox(hall, 0.72, 0.34, 1.65, 4.02, 0.33, 1.55, 0x7c85ad);
addBox(hall, 0.70, 0.30, 0.75, -3.95, 0.31, 1.67, 0x78945f);
addBox(hall, 0.35, 0.25, 0.35, -3.95, 0.53, 1.67, 0x456b43);
const hallSign = makeSprite("COMMUNITY HALL", "Four rooms · one shared ledger", "#264c45", "#ffffff", 2.35);
hallSign.position.set(0, 2.08, 3.82);
hall.add(hallSign);
addTree(scene, -6.35, 1.65, 1.0);
addTree(scene, 6.35, -1.15, 0.9);
addTree(scene, -6.65, -3.0, 0.76);
addLamp(scene, -5.85, 3.65);
addLamp(scene, 5.85, 3.65);
addVisitor(scene, -1.6, 4.65, 0x637bd8, 0.95);
addVisitor(scene, 1.65, 4.85, 0x2f9e91, 0.88);
addVisitor(scene, 2.05, 4.45, 0xe6a63a, 0.82);
const markers = new Map();
const waitingMarkers = new Map();
for (const request of REQUESTS) {
const marker = createBookingMarker(request);
scene.add(marker);
markers.set(request.id, marker);
const waiting = createWaitingMarker(request);
scene.add(waiting);
waitingMarkers.set(request.id, waiting);
}
const accepted = countAccepted(result);
const waitingCount = REQUESTS.length - accepted;
const summaryColor = waitingCount ? "#b94e46" : "#17786d";
const summarySign = makeSprite(
waitingCount ? `${waitingCount} WAITING` : `${accepted} / ${REQUESTS.length} PLACED`,
waitingCount ? "Fixed-room outcome" : "Shared inventory outcome",
summaryColor,
"#ffffff",
1.95
);
summarySign.position.set(0, 0.75, 4.65);
scene.add(summarySign);
const record = {
version,
scene,
camera,
markers,
waitingMarkers,
roomFloors,
pulse: 0
};
applyAllocation(record, result);
return record;
}
const bookingSlots = [
{ x: -0.93, z: -0.42 },
{ x: 0.93, z: -0.42 },
{ x: -0.93, z: 0.42 },
{ x: 0.93, z: 0.42 }
];
const sceneV1 = createHallScene(1, resultV1);
const sceneV2 = createHallScene(2, resultV2);
const sceneRecords = { 1: sceneV1, 2: sceneV2 };
function applyAllocation(record, result) {
const assigned = Object.fromEntries(ROOMS.map((room) => [room.id, []]));
for (const request of REQUESTS) {
const marker = record.markers.get(request.id);
const allocation = result[request.id];
marker.userData.booked = allocation.status === "booked";
marker.visible = marker.userData.booked;
if (allocation.status === "booked") {
const room = roomById.get(allocation.room);
const slotIndex = assigned[room.id].length;
const slot = bookingSlots[Math.min(slotIndex, bookingSlots.length - 1)];
assigned[room.id].push(request.id);
marker.position.set(room.x + slot.x, 0.245, room.z + slot.z);
marker.scale.setScalar(0.001);
} else {
marker.position.set(0, -2, 0);
}
}
const waiting = REQUESTS.filter((request) => result[request.id].status === "waiting");
waiting.forEach((request, index) => {
const marker = record.waitingMarkers.get(request.id);
marker.visible = true;
marker.position.set((index - (waiting.length - 1) / 2) * 1.58, -0.14, 4.72);
});
for (const room of ROOMS) {
const floor = record.roomFloors.get(room.id);
const count = assigned[room.id].length;
const accent = new THREE.Color(0x55aa97);
floor.material.color.copy(floor.userData.baseColor).lerp(accent, Math.min(0.22, count * 0.045));
}
}
function updateOrthographicCamera(camera, width, height) {
const safeWidth = Math.max(1, width);
const safeHeight = Math.max(1, height);
const aspect = safeWidth / safeHeight;
const targetWidth = 14.8;
const targetHeight = 10.9;
const viewHeight = Math.max(targetHeight, targetWidth / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
let renderWidth = 1;
let renderHeight = 1;
function renderRegion(record, x, y, width, height) {
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
renderer.clear(true, true, true);
updateOrthographicCamera(record.camera, width, height);
renderer.render(record.scene, record.camera);
}
function renderComparison() {
renderer.setScissorTest(true);
if (renderWidth >= 720) {
const split = Math.floor(renderWidth / 2);
renderRegion(sceneV1, 0, 0, split, renderHeight);
renderRegion(sceneV2, split, 0, renderWidth - split, renderHeight);
} else {
const split = Math.floor(renderHeight / 2);
renderRegion(sceneV1, 0, split, renderWidth, renderHeight - split);
renderRegion(sceneV2, 0, 0, renderWidth, split);
}
renderer.setScissorTest(false);
}
let resizeQueued = false;
let lastWidth = 0;
let lastHeight = 0;
function resizeRenderer() {
const rect = viewport.getBoundingClientRect();
const width = Math.max(1, Math.round(rect.width));
const height = Math.max(1, Math.round(rect.height));
if (width === lastWidth && height === lastHeight) return;
lastWidth = width;
lastHeight = height;
// false means Three.js updates only the drawing buffer.
// It does not rewrite the canvas CSS width or height.
renderer.setSize(width, height, false);
}
function queueResize() {
if (resizeQueued) return;
resizeQueued = true;
requestAnimationFrame(() => {
resizeQueued = false;
resizeRenderer();
});
}
/*
ResizeObserver watches the layout container, not the canvas.
Its callback only queues work for the next frame. It never writes a
width, height, style, class, or other dimension to the observed target.
The canvas is absolutely positioned, keeping the target's box stable.
*/
if ("ResizeObserver" in window) {
const resizeObserver = new ResizeObserver(queueResize);
resizeObserver.observe(viewport);
}
window.addEventListener("resize", queueResize, { passive: true });
resizeRenderer();
function setReplayStep(activeStep) {
$("replayLog").querySelectorAll("li").forEach((item, index) => {
item.classList.toggle("active", index === activeStep);
item.classList.toggle("done", index < activeStep);
});
}
function clearReplayTimers() {
state.replayTimers.forEach((timer) => clearTimeout(timer));
state.replayTimers = [];
}
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("show");
window.setTimeout(() => toast.classList.remove("show"), 2600);
}
function setReplayButtonsDisabled(disabled) {
$("replayButton").disabled = disabled;
$("topReplayButton").disabled = disabled;
$("replayButton").setAttribute("aria-busy", String(disabled));
$("topReplayButton").setAttribute("aria-busy", String(disabled));
}
function runReplay() {
if (state.replaying) return;
clearReplayTimers();
state.replaying = true;
setReplayButtonsDisabled(true);
$("replayButtonLabel").textContent = "Replaying both versions…";
$("replayStatus").textContent = "Running";
$("progressBar").style.width = "8%";
const frozenInput = REQUESTS.map((request) => ({ ...request }));
const freshV1 = solveV1(frozenInput);
const freshV2 = solveV2(frozenInput);
setReplayStep(0);
state.replayTimers.push(window.setTimeout(() => {
$("progressBar").style.width = "34%";
$("replayStatus").textContent = "Solving v1";
setReplayStep(1);
sceneV1.pulse = 1;
applyAllocation(sceneV1, freshV1);
}, 260));
state.replayTimers.push(window.setTimeout(() => {
$("progressBar").style.width = "68%";
$("replayStatus").textContent = "Solving v2";
setReplayStep(2);
sceneV2.pulse = 1;
applyAllocation(sceneV2, freshV2);
}, 900));
state.replayTimers.push(window.setTimeout(() => {
$("progressBar").style.width = "100%";
$("replayStatus").textContent = "Complete";
setReplayStep(3);
state.replaying = false;
setReplayButtonsDisabled(false);
$("replayButtonLabel").textContent = "Replay both versions";
showToast("Both dated rule versions replayed successfully");
}, 1550));
}
$("replayButton").addEventListener("click", runReplay);
$("topReplayButton").addEventListener("click", runReplay);
function focusRule(version) {
const record = version === 1 ? sceneV1 : sceneV2;
const overlay = version === 1 ? $("v1Overlay") : $("v2Overlay");
const card = version === 1 ? $("ruleCardV1") : $("ruleCardV2");
record.pulse = 1;
overlay.classList.remove("flash");
void overlay.offsetWidth;
overlay.classList.add("flash");
window.setTimeout(() => overlay.classList.remove("flash"), 650);
$("ruleCardV1").classList.toggle("is-focused", version === 1);
$("ruleCardV2").classList.toggle("is-focused", version === 2);
$("ruleCardV1").setAttribute("aria-pressed", String(version === 1));
$("ruleCardV2").setAttribute("aria-pressed", String(version === 2));
card.focus({ preventScroll: true });
}
$("ruleCardV1").addEventListener("click", () => focusRule(1));
$("ruleCardV2").addEventListener("click", () => focusRule(2));
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
for (const record of [sceneV1, sceneV2]) {
record.pulse = Math.max(0, record.pulse - delta * 0.7);
const pulseScale = record.pulse > 0 ? 1 + Math.sin(time * 12) * 0.045 * record.pulse : 1;
for (const request of REQUESTS) {
const marker = record.markers.get(request.id);
if (!marker.userData.booked) continue;
const emphasized = request.id === state.selectedRequest || request.id === state.hoveredRequest;
const targetScale = emphasized ? 1.13 : 1;
const nextScale = THREE.MathUtils.damp(marker.scale.x, targetScale, 9, delta);
marker.scale.setScalar(nextScale * pulseScale);
const waitingMarker = record.waitingMarkers.get(request.id);
if (waitingMarker.visible) {
const waitingTarget = emphasized ? 1.12 : 1;
const waitingScale = THREE.MathUtils.damp(waitingMarker.scale.x, waitingTarget, 9, delta);
waitingMarker.scale.setScalar(waitingScale * pulseScale);
}
}
}
renderComparison();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```