Prompt specification
Build or customize the Three.js 3D scene "Different decision-rule comparison" 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: Different decision-rule comparison
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/different-decision-rule-comparison-x3852
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a community decision about a shared project. Create fictional preferences for a small group and compare two clearly explained aggregation rules; keep individual preferences fixed so only the rule changes the displayed outcome. Low-poly.
Working Three.js Starter (different-decision-rule-comparison-x3852):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Neighborhood Assembly — A Shared Project</title>
<style>
:root {
color-scheme: dark;
--bg: #08111c;
--panel: #101d2b;
--panel-2: #142536;
--line: rgba(255, 255, 255, 0.11);
--text: #edf4f7;
--muted: #9eb0bc;
--cream: #ffe3a3;
--riverside: #45d6a5;
--library: #8b7cf6;
--bike: #ffb454;
--market: #f06b8b;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 12% 0%, rgba(69, 214, 165, 0.08), transparent 27rem),
radial-gradient(circle at 90% 10%, rgba(139, 124, 246, 0.08), transparent 30rem),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.topbar {
width: min(1600px, calc(100% - 36px));
margin: 0 auto;
padding: 24px 0 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 227, 163, 0.55);
background: rgba(255, 227, 163, 0.08);
color: var(--cream);
clip-path: polygon(50% 0, 94% 25%, 94% 75%, 50% 100%, 6% 75%, 6% 25%);
font-weight: 900;
font-size: 18px;
}
.brand-copy {
display: grid;
gap: 3px;
}
.brand-copy strong {
font-size: 14px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.brand-copy span {
color: var(--muted);
font-size: 12px;
}
.meeting-stamp {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--riverside);
box-shadow: 0 0 18px var(--riverside);
}
main {
width: min(1600px, calc(100% - 36px));
margin: 20px auto 36px;
}
.intro {
display: flex;
justify-content: space-between;
align-items: end;
gap: 24px;
margin-bottom: 18px;
}
.intro h1 {
margin: 0;
max-width: 820px;
font-size: clamp(27px, 3vw, 43px);
line-height: 1.04;
letter-spacing: -0.04em;
font-weight: 750;
}
.intro h1 span {
color: var(--cream);
}
.intro p {
margin: 0;
max-width: 440px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 405px;
gap: 18px;
align-items: start;
}
.stage {
position: relative;
min-height: 690px;
height: min(78vh, 820px);
overflow: hidden;
border: 1px solid var(--line);
border-radius: 24px;
background: #0b1723;
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
isolation: isolate;
}
.stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
.stage canvas:active {
cursor: grabbing;
}
.stage-hud {
position: absolute;
z-index: 2;
inset: 0;
pointer-events: none;
}
.stage-title {
position: absolute;
top: 20px;
left: 20px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 14px;
background: rgba(8, 17, 28, 0.68);
backdrop-filter: blur(12px);
}
.stage-title strong {
display: block;
margin-bottom: 4px;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.stage-title span {
color: var(--muted);
font-size: 12px;
}
.view-reset {
position: absolute;
top: 20px;
right: 20px;
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 999px;
padding: 10px 14px;
color: var(--text);
background: rgba(8, 17, 28, 0.72);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 12px;
}
.view-reset:hover {
background: rgba(255, 255, 255, 0.1);
}
.scene-legend {
position: absolute;
left: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100% - 40px);
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 999px;
color: #c4d1d9;
background: rgba(8, 17, 28, 0.72);
backdrop-filter: blur(12px);
font-size: 11px;
}
.legend-line {
width: 27px;
border-top: 2px dashed rgba(255, 255, 255, 0.5);
}
.loading {
position: absolute;
z-index: 5;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: #0b1723;
font-size: 13px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.panel {
max-height: min(86vh, 900px);
overflow-y: auto;
border: 1px solid var(--line);
border-radius: 24px;
background: linear-gradient(180deg, rgba(20, 37, 54, 0.97), rgba(13, 26, 39, 0.97));
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
scrollbar-width: thin;
scrollbar-color: #40566a transparent;
}
.panel-inner {
padding: 20px;
}
.section-label {
margin: 0 0 10px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.rule-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(0, 0, 0, 0.16);
}
.rule-switch button {
min-height: 42px;
padding: 9px 10px;
border: 0;
border-radius: 10px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition: 160ms ease;
}
.rule-switch button:hover {
color: var(--text);
}
.rule-switch button.active {
color: #17202a;
background: var(--cream);
box-shadow: 0 6px 20px rgba(255, 227, 163, 0.15);
}
.outcome {
position: relative;
overflow: hidden;
margin-top: 12px;
padding: 19px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 18px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.055), transparent 70%),
#0b1724;
}
.outcome::after {
content: "";
position: absolute;
width: 120px;
height: 120px;
top: -55px;
right: -45px;
border-radius: 50%;
background: var(--winner-color, var(--library));
opacity: 0.13;
filter: blur(2px);
}
.outcome-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.outcome h2 {
position: relative;
z-index: 1;
margin: 8px 0 5px;
font-size: 28px;
letter-spacing: -0.035em;
line-height: 1.05;
}
.outcome-type {
color: var(--winner-color, var(--library));
font-size: 13px;
font-weight: 700;
}
.outcome-value {
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #d8e1e6;
font-size: 13px;
line-height: 1.5;
}
.outcome-value strong {
color: white;
}
.rule-comparison {
display: grid;
gap: 9px;
margin-top: 21px;
}
.rule-card {
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
}
.rule-card.active {
border-color: rgba(255, 227, 163, 0.45);
background: rgba(255, 227, 163, 0.045);
}
.rule-card-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
}
.rule-card h3 {
margin: 0;
font-size: 14px;
}
.rule-number {
display: grid;
place-items: center;
width: 24px;
height: 24px;
border: 1px solid var(--line);
border-radius: 50%;
color: var(--muted);
font-size: 10px;
font-weight: 800;
}
.rule-card p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.rule-result {
margin-top: 9px !important;
color: #e9eff2 !important;
font-weight: 650;
}
.panel-section {
margin-top: 22px;
padding-top: 19px;
border-top: 1px solid var(--line);
}
.panel-section h3 {
margin: 0 0 5px;
font-size: 15px;
}
.panel-section > p {
margin: 0 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.rankings {
display: grid;
gap: 7px;
}
.resident-row {
display: grid;
grid-template-columns: 68px 1fr;
align-items: center;
gap: 10px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.resident-name {
display: flex;
align-items: center;
gap: 7px;
font-size: 12px;
font-weight: 700;
}
.resident-dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.rank-list {
display: flex;
justify-content: flex-end;
gap: 4px;
}
.rank-chip {
display: flex;
align-items: center;
gap: 3px;
padding: 4px 5px;
border-radius: 6px;
color: #d7e0e6;
background: rgba(255, 255, 255, 0.055);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.04em;
}
.rank-chip b {
color: var(--muted);
font-size: 8px;
}
.scoreboard {
display: grid;
gap: 10px;
}
.score-row {
display: grid;
grid-template-columns: 105px 1fr 58px;
align-items: center;
gap: 9px;
font-size: 11px;
}
.score-name {
overflow: hidden;
color: #dce5ea;
text-overflow: ellipsis;
white-space: nowrap;
}
.score-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.score-fill {
height: 100%;
width: 0;
border-radius: inherit;
transition: width 500ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.score-value {
color: var(--muted);
text-align: right;
font-variant-numeric: tabular-nums;
}
.fixed-note {
display: flex;
gap: 10px;
margin-top: 21px;
padding: 13px;
border: 1px solid rgba(69, 214, 165, 0.2);
border-radius: 13px;
color: #bfe7d9;
background: rgba(69, 214, 165, 0.055);
font-size: 11px;
line-height: 1.5;
}
.fixed-note span {
flex: 0 0 auto;
font-size: 17px;
}
@media (max-width: 1080px) {
.layout {
grid-template-columns: 1fr;
}
.stage {
height: 70vh;
min-height: 560px;
}
.panel {
max-height: none;
}
.panel-inner {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0 22px;
}
.panel-top,
.rule-comparison,
.panel-section,
.fixed-note {
grid-column: 1 / -1;
}
}
@media (max-width: 650px) {
.topbar,
main {
width: min(100% - 20px, 1600px);
}
.topbar {
padding-top: 17px;
}
.meeting-stamp {
display: none;
}
.intro {
display: block;
}
.intro p {
margin-top: 12px;
}
.stage {
height: 62vh;
min-height: 500px;
border-radius: 18px;
}
.stage-title {
top: 12px;
left: 12px;
max-width: 220px;
}
.view-reset {
top: 12px;
right: 12px;
}
.scene-legend {
left: 12px;
bottom: 12px;
font-size: 10px;
}
.panel-inner {
display: block;
padding: 15px;
}
.resident-row {
grid-template-columns: 62px 1fr;
}
.rank-chip {
padding: 4px;
font-size: 7px;
}
.score-row {
grid-template-columns: 88px 1fr 54px;
}
}
@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">N</div>
<div class="brand-copy">
<strong>Neighborhood Assembly</strong>
<span>Shared Projects Office · Session 07</span>
</div>
</div>
<div class="meeting-stamp">
<span class="live-dot"></span>
Five residents · one proposal
</div>
</header>
<main>
<section class="intro">
<h1>Which shared project should the neighborhood build?</h1>
<p>
The residents’ rankings never change. Switch only the aggregation rule
and watch the community’s displayed decision change.
</p>
</section>
<div class="layout">
<section class="stage" id="stage" aria-label="Interactive low-poly neighborhood meeting scene">
<div class="loading" id="loading">Building the neighborhood…</div>
<div class="stage-hud">
<div class="stage-title">
<strong>Neighborhood Commons</strong>
<span>Drag to orbit · scroll to zoom</span>
</div>
<button class="view-reset" id="resetView" type="button">
Reset view
</button>
<div class="scene-legend">
<span class="legend-line"></span>
Fixed colored threads show each resident’s first choice
</div>
</div>
</section>
<aside class="panel">
<div class="panel-inner">
<div class="panel-top">
<p class="section-label">Displayed aggregation rule</p>
<div class="rule-switch" role="group" aria-label="Choose an aggregation rule">
<button type="button" data-rule="plurality" aria-pressed="true" class="active">
1 · Plurality
</button>
<button type="button" data-rule="borda" aria-pressed="false">
2 · Borda points
</button>
</div>
<section class="outcome" id="outcome" aria-live="polite">
<div class="outcome-kicker">Current outcome</div>
<h2 id="outcomeTitle">Corner Library</h2>
<div class="outcome-type" id="outcomeType">Most first-place votes</div>
<div class="outcome-value" id="outcomeValue">
<strong>2 first-place votes.</strong><br />
Riverside, Bike Hub, and Market Square each receive one.
</div>
</section>
</div>
<div class="rule-comparison">
<article class="rule-card active" data-rule-card="plurality">
<div class="rule-card-head">
<h3>Plurality</h3>
<span class="rule-number">1</span>
</div>
<p>
Count only first-place rankings. The project named first by the
most residents wins.
</p>
<p class="rule-result">
Result: Corner Library — 2 of 5 first-place votes.
</p>
</article>
<article class="rule-card" data-rule-card="borda">
<div class="rule-card-head">
<h3>Borda points</h3>
<span class="rule-number">2</span>
</div>
<p>
Give 4 points for first, 3 for second, 2 for third, and 1 for
fourth. Add each resident’s points for every project.
</p>
<p class="rule-result">
Result: Riverside Park — 16 points, ahead of Library’s 15.
</p>
</article>
</div>
<section class="panel-section">
<h3>The five fixed preferences</h3>
<p>
These fictional rankings stay unchanged in both views.
The order in each row runs from first to fourth choice.
</p>
<div class="rankings" id="rankings"></div>
</section>
<section class="panel-section">
<h3 id="scoreboardTitle">First-place votes</h3>
<p id="scoreboardDescription">
Plurality counts only each resident’s top choice.
</p>
<div class="scoreboard" id="scoreboard"></div>
</section>
<div class="fixed-note">
<span aria-hidden="true">✓</span>
<div>
<strong>Controlled comparison.</strong> The residents, their
complete rankings, and the four candidate projects are identical.
Only the way those fixed rankings are aggregated changes.
</div>
</div>
</div>
</aside>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const candidates = [
{
id: "riverside",
name: "Riverside Park",
short: "RIV",
color: 0x45d6a5,
css: "#45d6a5",
position: [-2.1, -5.25],
firstVotes: 1,
borda: 16
},
{
id: "library",
name: "Corner Library",
short: "LIB",
color: 0x8b7cf6,
css: "#8b7cf6",
position: [-6.25, -2.65],
firstVotes: 2,
borda: 15
},
{
id: "bike",
name: "Bike Hub",
short: "BIKE",
color: 0xffb454,
css: "#ffb454",
position: [2.45, -4.9],
firstVotes: 1,
borda: 10
},
{
id: "market",
name: "Market Square",
short: "MKT",
color: 0xf06b8b,
css: "#f06b8b",
position: [6.15, -2.5],
firstVotes: 1,
borda: 9
}
];
const candidateById = Object.fromEntries(candidates.map((candidate) => [candidate.id, candidate]));
const residents = [
{
name: "Ana",
color: "#ffcf70",
first: "library",
ranking: ["library", "riverside", "bike", "market"]
},
{
name: "Ben",
color: "#ff8b75",
first: "library",
ranking: ["library", "riverside", "market", "bike"]
},
{
name: "Cara",
color: "#75b7ff",
first: "bike",
ranking: ["bike", "riverside", "library", "market"]
},
{
name: "Dev",
color: "#cf9cff",
first: "market",
ranking: ["market", "riverside", "library", "bike"]
},
{
name: "Eli",
color: "#65e0c1",
first: "riverside",
ranking: ["riverside", "library", "bike", "market"]
}
];
const residentPositions = [
[-4.45, 3.6],
[-2.25, 4.85],
[0, 5.15],
[2.25, 4.85],
[4.45, 3.6]
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1723);
scene.fog = new THREE.Fog(0x0b1723, 24, 40);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.prepend(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly neighborhood meeting. Drag or use arrow keys to orbit, and scroll to zoom."
);
const hemisphere = new THREE.HemisphereLight(0xc8e7ff, 0x263c39, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe9c4, 3.0);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x7ea7ff, 1.1);
rim.position.set(9, 7, -12);
scene.add(rim);
function standardMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...extra
});
}
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, width, height, depth, color, x = 0, y = 0, z = 0) {
return addMesh(
parent,
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color),
x,
y,
z
);
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
segments,
color,
x = 0,
y = 0,
z = 0
) {
return addMesh(
parent,
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
standardMaterial(color),
x,
y,
z
);
}
function addBeam(parent, start, end, radius, color) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const beam = addMesh(
parent,
new THREE.CylinderGeometry(radius, radius, length, 6),
standardMaterial(color)
);
beam.position.copy(start).add(end).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return beam;
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.arcTo(x + width, y, x + width, y + height, radius);
context.arcTo(x + width, y + height, x, y + height, radius);
context.arcTo(x, y + height, x, y, radius);
context.arcTo(x, y, x + width, y, radius);
context.closePath();
}
function makeLabel(text, background, foreground = "#f4f8fa", width = 2.8, height = 0.58) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.userData.canvas = canvas;
sprite.userData.context = context;
sprite.userData.texture = texture;
updateLabel(sprite, text, background, foreground);
return sprite;
}
function updateLabel(sprite, text, background, foreground = "#f4f8fa") {
const canvas = sprite.userData.canvas;
const context = sprite.userData.context;
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 8, 8, 496, 112, 26);
context.fillStyle = background;
context.fill();
context.strokeStyle = "rgba(255,255,255,0.17)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = foreground;
context.font = "800 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65, 462);
sprite.userData.texture.needsUpdate = true;
}
function addTree(parent, x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.25, z);
tree.scale.setScalar(scale);
addCylinder(tree, 0.09, 0.13, 0.75, 6, 0x785238, 0, 0.38, 0);
addMesh(
tree,
new THREE.ConeGeometry(0.62, 1.25, 7),
standardMaterial(0x318c61),
0,
1.25,
0
);
addMesh(
tree,
new THREE.ConeGeometry(0.48, 0.95, 7),
standardMaterial(0x48a875),
0,
1.75,
0
);
parent.add(tree);
}
function addBench(parent, x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0.42, z);
bench.rotation.y = rotation;
addBox(bench, 1.25, 0.12, 0.42, 0xa96f43, 0, 0.34, 0);
addBox(bench, 1.25, 0.48, 0.1, 0xb77a48, 0, 0.61, -0.18);
addBox(bench, 0.1, 0.36, 0.38, 0x394450, -0.46, 0.12, 0);
addBox(bench, 0.1, 0.36, 0.38, 0x394450, 0.46, 0.12, 0);
parent.add(bench);
}
function addBike(parent, x, z, color) {
const bike = new THREE.Group();
bike.position.set(x, 0.83, z);
const wheelMaterial = standardMaterial(0x27333d);
const frameMaterial = standardMaterial(color);
const rearWheel = addMesh(
bike,
new THREE.TorusGeometry(0.38, 0.065, 5, 10),
wheelMaterial,
-0.48,
0,
0
);
const frontWheel = addMesh(
bike,
new THREE.TorusGeometry(0.38, 0.065, 5, 10),
wheelMaterial,
0.48,
0,
0
);
rearWheel.rotation.x = 0;
frontWheel.rotation.x = 0;
const p1 = new THREE.Vector3(-0.48, 0, 0);
const p2 = new THREE.Vector3(-0.08, 0.55, 0);
const p3 = new THREE.Vector3(0.28, 0.05, 0);
const p4 = new THREE.Vector3(0.48, 0, 0);
const p5 = new THREE.Vector3(-0.12, 0.05, 0);
addBeam(bike, p1, p2, 0.035, frameMaterial);
addBeam(bike, p2, p5, 0.035, frameMaterial);
addBeam(bike, p5, p1, 0.035, frameMaterial);
addBeam(bike, p2, p3, 0.035, frameMaterial);
addBeam(bike, p3, p5, 0.035, frameMaterial);
addBeam(bike, p3, p4, 0.035, frameMaterial);
addBox(bike, 0.32, 0.08, 0.14, 0x27333d, -0.12, 0.58, 0);
addBeam(
bike,
new THREE.Vector3(0.28, 0.05, 0),
new THREE.Vector3(0.34, 0.55, 0),
0.03,
frameMaterial
);
addBox(bike, 0.26, 0.06, 0.08, 0x27333d, 0.35, 0.56, 0);
parent.add(bike);
}
function createLibrary(parent) {
addBox(parent, 2.35, 1.65, 1.55, 0xd8c6a3, 0, 1.05, -0.1);
addBox(parent, 2.6, 0.16, 1.8, 0xb9a17d, 0, 0.24, -0.1);
const roof = addMesh(
parent,
new THREE.ConeGeometry(1.85, 0.78, 4),
standardMaterial(0x5e4d72),
0,
2.23,
-0.1
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.78;
addBox(parent, 0.55, 0.92, 0.08, 0x4a3f5e, 0, 0.86, 0.71);
[-0.86, -0.3, 0.3, 0.86].forEach((x) => {
addCylinder(parent, 0.1, 0.12, 1.22, 8, 0xf1e5c7, x, 0.97, 0.78);
});
addBox(parent, 1.85, 0.15, 0.25, 0xf1e5c7, 0, 1.58, 0.78);
[-0.74, 0.74].forEach((x) => {
addBox(parent, 0.38, 0.5, 0.07, 0x70c3d2, x, 1.0, 0.7);
});
}
function createRiverside(parent) {
addCylinder(parent, 1.85, 2.0, 0.24, 12, 0x4f9566, 0, 0.27, 0);
const riverShape = new THREE.Shape();
riverShape.moveTo(-1.55, -0.85);
riverShape.lineTo(-0.75, -0.68);
riverShape.lineTo(-0.3, -0.15);
riverShape.lineTo(0.15, 0.22);
riverShape.lineTo(0.62, 0.85);
riverShape.lineTo(1.52, 0.65);
riverShape.lineTo(1.0, -0.1);
riverShape.lineTo(0.46, -0.55);
riverShape.lineTo(-0.1, -0.82);
riverShape.closePath();
const river = addMesh(
parent,
new THREE.ShapeGeometry(riverShape),
standardMaterial(0x50b9d1, { side: THREE.DoubleSide }),
0,
0.41,
0
);
river.rotation.x = -Math.PI / 2;
addTree(parent, -1.05, -0.65, 0.85);
addTree(parent, 0.95, -0.65, 0.72);
addTree(parent, 1.05, 0.65, 0.58);
addBench(parent, -0.75, 0.75, -0.3);
}
function createBikeHub(parent) {
addBox(parent, 2.45, 0.12, 1.65, 0x64727d, 0, 0.31, 0);
[-0.95, 0.95].forEach((x) => {
addBox(parent, 0.09, 1.5, 0.09, 0x46545e, x, 1.05, 0.65);
});
addBox(parent, 2.55, 0.16, 1.8, 0x384753, 0, 1.87, 0);
addBox(parent, 1.65, 0.08, 0.9, 0x91c5cc, 0, 1.78, 0);
addBike(parent, -0.55, 0.18, 0xf2a43f);
addBike(parent, 0.55, 0.18, 0x4bc3a2);
for (let i = 0; i < 4; i++) {
addBox(parent, 0.06, 0.95, 0.06, 0x7b8991, -0.88 + i * 0.58, 0.83, -0.6);
}
}
function createMarket(parent) {
addBox(parent, 2.3, 0.12, 1.65, 0x8b7863, 0, 0.31, 0);
const stallColors = [0xf06b8b, 0xffb454, 0x8b7cf6, 0x45d6a5];
for (let i = 0; i < 4; i++) {
const x = -0.72 + i * 0.48;
addBox(parent, 0.06, 1.1, 0.06, 0x5a4738, x, 0.86, 0.58);
addBox(parent, 0.06, 0.85, 0.06, 0x5a4738, x, 0.72, -0.48);
const canopy = addMesh(
parent,
new THREE.ConeGeometry(0.38, 0.32, 4),
standardMaterial(stallColors[i]),
x,
1.48,
0.05
);
canopy.rotation.y = Math.PI / 4;
canopy.scale.z = 0.72;
}
addBox(parent, 1.5, 0.32, 0.5, 0x9c724b, -0.1, 0.55, 0.08);
addBox(parent, 0.45, 0.28, 0.36, 0xd49b55, -0.48, 0.79, 0.08);
addBox(parent, 0.45, 0.28, 0.36, 0x79a861, 0.25, 0.79, 0.08);
}
// Ground plaza.
addCylinder(scene, 11.7, 12.1, 0.58, 28, 0x172938, 0, -0.35, 0);
addCylinder(scene, 11.3, 11.3, 0.14, 28, 0x203a43, 0, -0.02, 0);
const path = addMesh(
scene,
new THREE.RingGeometry(4.15, 4.62, 36),
standardMaterial(0x41555d),
0,
0.08,
1.25
);
path.rotation.x = -Math.PI / 2;
// Radial paths to the candidate displays.
[
[-6.0, -2.5, -0.62],
[-2.1, -5.25, 0],
[2.45, -4.9, 0.62],
[6.15, -2.5, 1.22]
].forEach(([x, z, rotation]) => {
const walkway = addBox(scene, 1.05, 0.07, 5.25, 0x344a52, x, 0.07, z);
walkway.rotation.y = rotation;
});
// Low-poly trees around the plaza.
[
[-9.7, -1.4, 1.05],
[-8.9, 2.7, 0.8],
[9.3, -0.7, 0.95],
[8.7, 3.0, 0.78],
[-5.0, -8.0, 0.82],
[1.0, -8.8, 0.92],
[6.2, -7.2, 0.8]
].forEach(([x, z, scale]) => addTree(scene, x, z, scale));
// Meeting table.
const table = new THREE.Group();
table.position.set(0, 0, 1.4);
scene.add(table);
addCylinder(table, 2.35, 2.65, 0.32, 12, 0x344550, 0, 0.26, 0);
addCylinder(table, 2.18, 2.18, 0.12, 12, 0xb18a60, 0, 0.48, 0);
addCylinder(table, 0.32, 0.46, 0.55, 8, 0x344550, 0, 0.18, 0);
candidates.forEach((candidate) => {
const tile = addBox(
table,
0.52,
0.035,
0.52,
candidate.color,
(candidate.position[0] * 0.11),
0.56,
(candidate.position[1] * 0.05)
);
tile.rotation.y = Math.PI / 4;
});
const tableLabel = makeLabel("5 RESIDENTS · 4 PROJECTS", "#152535", "#dbe7eb", 3.25, 0.48);
tableLabel.position.set(0, 2.45, 0);
table.add(tableLabel);
const candidateObjects = new Map();
function createCandidate(candidate) {
const group = new THREE.Group();
group.position.set(candidate.position[0], 0, candidate.position[1]);
scene.add(group);
addCylinder(group, 2.3, 2.48, 0.28, 12, 0x253b49, 0, 0.19, 0);
const ringMaterial = standardMaterial(candidate.color, {
emissive: candidate.color,
emissiveIntensity: 0.08,
roughness: 0.55
});
const ring = addMesh(
group,
new THREE.TorusGeometry(2.28, 0.075, 6, 32),
ringMaterial,
0,
0.38,
0
);
ring.rotation.x = Math.PI / 2;
const model = new THREE.Group();
group.add(model);
if (candidate.id === "library") createLibrary(model);
if (candidate.id === "riverside") createRiverside(model);
if (candidate.id === "bike") createBikeHub(model);
if (candidate.id === "market") createMarket(model);
const nameLabel = makeLabel(
candidate.name.toUpperCase(),
"#101d2b",
candidate.css,
candidate.id === "market" ? 3.45 : 3.05,
0.56
);
nameLabel.position.set(0, 4.08, 0);
group.add(nameLabel);
// Plurality display: one diamond per first-place vote.
const firstTokens = new THREE.Group();
firstTokens.position.set(0, 0.45, 1.9);
group.add(firstTokens);
for (let i = 0; i < candidate.firstVotes; i++) {
const token = addMesh(
firstTokens,
new THREE.OctahedronGeometry(0.23),
standardMaterial(candidate.color, {
emissive: candidate.color,
emissiveIntensity: 0.18
}),
(i - (candidate.firstVotes - 1) / 2) * 0.38,
0,
0
);
token.rotation.y = Math.PI / 4;
}
const firstLabel = makeLabel(
`${candidate.firstVotes} FIRST`,
candidate.css,
"#101820",
1.75,
0.4
);
firstLabel.position.set(0, 3.42, 0);
group.add(firstLabel);
// Borda display: one block per rank point.
const scoreGroup = new THREE.Group();
scoreGroup.position.set(1.95, 0, 0.25);
group.add(scoreGroup);
for (let i = 0; i < candidate.borda; i++) {
addBox(
scoreGroup,
0.3,
0.125,
0.3,
candidate.color,
0,
0.46 + i * 0.155,
0
);
}
const scoreLabel = makeLabel(
`${candidate.borda} PTS`,
candidate.css,
"#101820",
1.55,
0.4
);
scoreLabel.position.set(1.95, 3.18, 0.25);
group.add(scoreLabel);
group.userData = {
candidate,
ring,
firstTokens,
firstLabel,
scoreGroup,
scoreLabel,
targetLift: 0,
winner: false
};
candidateObjects.set(candidate.id, group);
}
candidates.forEach(createCandidate);
// Residents around the table.
const residentObjects = [];
residents.forEach((resident, index) => {
const group = new THREE.Group();
group.position.set(
residentPositions[index][0],
0,
residentPositions[index][1]
);
scene.add(group);
const body = addCylinder(group, 0.26, 0.37, 0.95, 6, resident.color, 0, 0.92, 0);
body.rotation.y = Math.PI / 6;
addCylinder(group, 0.1, 0.12, 0.55, 6, 0x334452, -0.16, 0.28, 0);
addCylinder(group, 0.1, 0.12, 0.55, 6, 0x334452, 0.16, 0.28, 0);
const leftArm = addCylinder(group, 0.08, 0.1, 0.78, 5, resident.color, -0.36, 0.9, 0);
leftArm.rotation.z = -0.18;
const rightArm = addCylinder(group, 0.08, 0.1, 0.78, 5, resident.color, 0.36, 0.9, 0);
rightArm.rotation.z = 0.18;
addMesh(
group,
new THREE.IcosahedronGeometry(0.31, 0),
standardMaterial(0xe4b992),
0,
1.67,
0
);
addMesh(
group,
new THREE.SphereGeometry(0.035, 6, 4),
standardMaterial(0x15202a),
-0.1,
1.7,
0.275
);
addMesh(
group,
new THREE.SphereGeometry(0.035, 6, 4),
standardMaterial(0x15202a),
0.1,
1.7,
0.275
);
const firstCandidate = candidateById[resident.first];
const firstToken = addMesh(
group,
new THREE.OctahedronGeometry(0.16),
standardMaterial(firstCandidate.color, {
emissive: firstCandidate.color,
emissiveIntensity: 0.22
}),
0,
2.15,
0
);
firstToken.userData.baseY = 2.15;
const nameLabel = makeLabel(resident.name.toUpperCase(), "#182936", resident.color, 1.35, 0.38);
nameLabel.position.set(0, 2.53, 0);
group.add(nameLabel);
residentObjects.push({ group, firstToken });
});
// Fixed first-choice threads.
residents.forEach((resident, index) => {
const target = candidateObjects.get(resident.first);
const start = new THREE.Vector3(
residentPositions[index][0],
1.55,
residentPositions[index][1]
);
const end = new THREE.Vector3(
target.position.x,
1.05,
target.position.z
);
const middle = new THREE.Vector3(
(start.x + end.x) / 2,
2.5 + Math.abs(start.x - end.x) * 0.04,
(start.z + end.z) / 2
);
const curve = new THREE.QuadraticBezierCurve3(start, middle, end);
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(32));
const material = new THREE.LineDashedMaterial({
color: candidateById[resident.first].color,
transparent: true,
opacity: 0.28,
dashSize: 0.25,
gapSize: 0.16,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
});
// Floating winner badge.
const winnerBadge = new THREE.Group();
scene.add(winnerBadge);
const badgeGem = addMesh(
winnerBadge,
new THREE.OctahedronGeometry(0.28),
standardMaterial(0xffe3a3, {
emissive: 0xffd66d,
emissiveIntensity: 0.65
}),
0,
0,
0
);
const badgeLabel = makeLabel("PLURALITY WINNER", "#ffe3a3", "#16212b", 2.9, 0.48);
badgeLabel.position.set(0, 0.52, 0);
winnerBadge.add(badgeLabel);
// Direct camera controls: no examples or addons are used.
const orbit = {
theta: 0,
phi: 1.03,
radius: 22,
baseRadius: 22,
target: new THREE.Vector3(0, 1.05, -0.35)
};
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
orbit.theta = 0;
orbit.phi = 1.03;
orbit.radius = orbit.baseRadius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + deltaY * 0.005, 0.68, 1.35);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
13,
36
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") orbit.theta -= 0.08;
else if (event.key === "ArrowRight") orbit.theta += 0.08;
else if (event.key === "ArrowUp") orbit.phi = Math.max(0.68, orbit.phi - 0.06);
else if (event.key === "ArrowDown") orbit.phi = Math.min(1.35, orbit.phi + 0.06);
else if (event.key === "+" || event.key === "=") orbit.radius = Math.max(13, orbit.radius - 1);
else if (event.key === "-") orbit.radius = Math.min(36, orbit.radius + 1);
else handled = false;
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("resetView").addEventListener("click", resetView);
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
orbit.baseRadius = camera.aspect < 0.95 ? 29 : camera.aspect < 1.25 ? 25 : 22;
if (!dragging) orbit.radius = orbit.baseRadius;
updateCamera();
}
new ResizeObserver(resize).observe(stage);
resize();
// Build the fixed-preference panel.
const rankingsElement = document.getElementById("rankings");
rankingsElement.innerHTML = residents
.map(
(resident) => `
<div class="resident-row">
<div class="resident-name">
<span class="resident-dot" style="background:${resident.color}"></span>
${resident.name}
</div>
<div class="rank-list">
${resident.ranking
.map(
(id, index) => `
<span class="rank-chip" title="${candidateById[id].name}">
<b>${index + 1}</b>${candidateById[id].short}
</span>
`
)
.join("")}
</div>
</div>
`
)
.join("");
const scoreboardElement = document.getElementById("scoreboard");
const outcomeElement = document.getElementById("outcome");
const outcomeTitle = document.getElementById("outcomeTitle");
const outcomeType = document.getElementById("outcomeType");
const outcomeValue = document.getElementById("outcomeValue");
const scoreboardTitle = document.getElementById("scoreboardTitle");
const scoreboardDescription = document.getElementById("scoreboardDescription");
let currentRule = "plurality";
function competitionRanks(values) {
const sorted = [...values].sort((a, b) => b - a);
return values.map((value) => sorted.indexOf(value) + 1);
}
function renderScoreboard(rule) {
const values = candidates.map((candidate) =>
rule === "plurality" ? candidate.firstVotes : candidate.borda
);
const ranks = competitionRanks(values);
const maxValue = Math.max(...values);
scoreboardElement.innerHTML = candidates
.map((candidate, index) => {
const value = values[index];
const unit = rule === "plurality" ? "vote" : "pts";
return `
<div class="score-row">
<span class="score-name">${candidate.name}</span>
<span class="score-track">
<span
class="score-fill"
style="width:${(value / maxValue) * 100}%;background:${candidate.css}"
></span>
</span>
<span class="score-value">${value} ${unit}</span>
</div>
`;
})
.join("");
}
function setRule(rule) {
currentRule = rule;
const isPlurality = rule === "plurality";
const winnerId = isPlurality ? "library" : "riverside";
const winner = candidateById[winnerId];
document.querySelectorAll("[data-rule]").forEach((button) => {
const active = button.dataset.rule === rule;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
document.querySelectorAll("[data-rule-card]").forEach((card) => {
card.classList.toggle("active", card.dataset.ruleCard === rule);
});
outcomeElement.style.setProperty("--winner-color", winner.css);
outcomeTitle.textContent = winner.name;
outcomeType.textContent = isPlurality
? "Most first-place votes"
: "Most rank points";
outcomeValue.innerHTML = isPlurality
? `<strong>2 first-place votes.</strong><br />
Riverside, Bike Hub, and Market Square each receive one.`
: `<strong>16 Borda points.</strong><br />
Library receives 15, Bike Hub 10, and Market Square 9.`;
scoreboardTitle.textContent = isPlurality
? "First-place votes"
: "Borda rank points";
scoreboardDescription.textContent = isPlurality
? "Plurality counts only each resident’s top choice."
: "Each complete ranking contributes 4, 3, 2, and 1 points.";
updateLabel(
badgeLabel,
isPlurality ? "PLURALITY WINNER" : "BORDA WINNER",
"#ffe3a3",
"#16212b"
);
candidateObjects.forEach((group, id) => {
const isWinner = id === winnerId;
group.userData.winner = isWinner;
group.userData.targetLift = isWinner ? 0.46 : 0;
group.userData.firstTokens.visible = isPlurality;
group.userData.firstLabel.visible = isPlurality;
group.userData.scoreGroup.visible = !isPlurality;
group.userData.scoreLabel.visible = !isPlurality;
const ringMaterial = group.userData.ring.material;
ringMaterial.color.set(isWinner ? 0xffe3a3 : group.userData.candidate.color);
ringMaterial.emissive.set(isWinner ? 0xffd66d : group.userData.candidate.color);
ringMaterial.emissiveIntensity = isWinner ? 0.72 : 0.08;
});
renderScoreboard(rule);
}
document.querySelectorAll("[data-rule]").forEach((button) => {
button.addEventListener("click", () => setRule(button.dataset.rule));
});
setRule("plurality");
const clock = new THREE.Clock();
const badgeTarget = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = clock.getDelta();
candidateObjects.forEach((group) => {
const lift = reduceMotion
? group.userData.targetLift
: THREE.MathUtils.lerp(
group.position.y,
group.userData.targetLift,
1 - Math.exp(-delta * 6)
);
group.position.y = lift;
const pulse = group.userData.winner && !reduceMotion
? 1 + Math.sin(elapsed * 3.1) * 0.025
: 1;
group.userData.ring.scale.set(pulse, pulse, pulse);
group.userData.ring.material.emissiveIntensity = group.userData.winner
? 0.65 + Math.sin(elapsed * 3.1) * 0.12
: 0.08;
});
residentObjects.forEach(({ firstToken }, index) => {
firstToken.position.y = reduceMotion
? firstToken.userData.baseY
: firstToken.userData.baseY + Math.sin(elapsed * 2 + index * 0.8) * 0.055;
firstToken.rotation.y += reduceMotion ? 0 : delta * 0.7;
});
badgeGem.rotation.y += reduceMotion ? 0 : delta * 1.2;
badgeGem.position.y = reduceMotion ? 0 : Math.sin(elapsed * 2.6) * 0.08;
const winnerGroup = candidateObjects.get(
currentRule === "plurality" ? "library" : "riverside"
);
badgeTarget.set(
winnerGroup.position.x,
winnerGroup.position.y + 4.9,
winnerGroup.position.z
);
winnerBadge.position.lerp(
badgeTarget,
reduceMotion ? 1 : 1 - Math.exp(-delta * 7)
);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
loading.remove();
animate();
</script>
</body>
</html>
```