Prompt specification
Build or customize the Three.js 3D scene "People counters on two equal tiles" 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: People counters on two equal tiles
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/people-counters-on-two-equal-tiles-x1333
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts population density. Represent people with simple standing counters on two equally sized ground tiles. Use a shared legend so differences in counter count directly show density differences. Stylized solid forms.
Working Three.js Starter (people-counters-on-two-equal-tiles-x1333):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Population Density — Equal-Area Tiles</title>
<style>
:root {
--bg: #09151d;
--panel: rgba(13, 29, 38, 0.88);
--border: rgba(255, 255, 255, 0.12);
--text: #f4f7f4;
--muted: #9fb1b8;
--accent-a: #48d6c2;
--accent-b: #ff7b72;
--counter: #ffca58;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
background:
radial-gradient(circle at 72% 18%, rgba(59, 102, 119, 0.22), transparent 36%),
radial-gradient(circle at 20% 85%, rgba(31, 89, 92, 0.18), transparent 34%),
linear-gradient(145deg, #0c1b24, #071119 72%);
}
canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.masthead {
position: absolute;
z-index: 5;
top: 0;
left: 0;
width: min(460px, calc(100% - 40px));
padding: 28px 30px 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: #b9c9ce;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 2px;
content: "";
background: var(--counter);
border-radius: 10px;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 720;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.tools {
position: absolute;
z-index: 8;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 10px;
}
.tool-button {
display: inline-flex;
align-items: center;
justify-content: center;
height: 38px;
padding: 0 14px;
color: #e8eeee;
background: rgba(12, 27, 36, 0.82);
border: 1px solid var(--border);
border-radius: 999px;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease;
}
.tool-button:hover {
background: rgba(28, 50, 60, 0.95);
transform: translateY(-1px);
}
.tool-button svg {
width: 15px;
height: 15px;
margin-right: 7px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.hint {
position: absolute;
z-index: 5;
right: 27px;
bottom: 25px;
color: rgba(205, 217, 221, 0.58);
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
}
.legend {
position: absolute;
z-index: 7;
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 17px;
min-width: 335px;
padding: 15px 18px;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
}
.legend-icon {
position: relative;
flex: 0 0 34px;
width: 34px;
height: 48px;
}
.legend-icon::before {
position: absolute;
top: 2px;
left: 11px;
width: 13px;
height: 13px;
content: "";
background: var(--counter);
border-radius: 50%;
box-shadow: 0 2px 7px rgba(255, 202, 88, 0.24);
}
.legend-icon::after {
position: absolute;
bottom: 3px;
left: 8px;
width: 19px;
height: 28px;
content: "";
background: var(--counter);
border-radius: 9px 9px 6px 6px;
clip-path: polygon(28% 0, 72% 0, 100% 82%, 74% 100%, 50% 82%, 26% 100%, 0 82%);
}
.legend-copy {
line-height: 1.3;
}
.legend-copy strong {
display: block;
margin-bottom: 4px;
font-size: 13px;
font-weight: 680;
}
.legend-copy span {
color: var(--muted);
font-size: 11px;
}
.equal-badge {
margin-left: auto;
padding-left: 16px;
color: #c5d2d5;
border-left: 1px solid var(--border);
font-size: 10px;
font-weight: 700;
line-height: 1.45;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
white-space: nowrap;
}
.zone-label {
position: absolute;
z-index: 4;
width: 174px;
padding: 10px 13px 11px;
background: rgba(10, 23, 31, 0.86);
border: 1px solid var(--border);
border-top: 2px solid var(--accent);
border-radius: 11px;
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(12px);
}
.zone-label .label-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
color: #aebfc5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.zone-label .label-top i {
width: 7px;
height: 7px;
background: var(--accent);
border-radius: 50%;
}
.zone-label strong {
display: block;
font-size: 18px;
font-weight: 730;
letter-spacing: -0.025em;
}
.zone-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
@media (max-width: 700px) {
.masthead {
width: calc(100% - 32px);
padding: 20px 18px 14px;
}
h1 {
font-size: 34px;
}
.intro {
max-width: 300px;
font-size: 11px;
}
.tools {
top: auto;
right: 16px;
bottom: 16px;
}
.tool-button {
width: 38px;
padding: 0;
}
.tool-button span {
display: none;
}
.tool-button svg {
margin: 0;
}
.legend {
left: 16px;
bottom: 16px;
min-width: 0;
max-width: calc(100% - 76px);
gap: 12px;
padding: 12px 14px;
}
.legend-copy strong {
font-size: 11px;
}
.legend-copy span {
font-size: 9px;
}
.equal-badge {
display: none;
}
.zone-label {
width: 138px;
padding: 8px 10px 9px;
}
.zone-label strong {
font-size: 14px;
}
.zone-label small {
font-size: 9px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas
id="scene"
aria-label="Interactive 3D comparison of population density on two equal-area tiles"
></canvas>
<header class="masthead">
<div class="eyebrow">Population study 01</div>
<h1>Population<br />density</h1>
<p class="intro">
Two equal-area ground tiles. One shared scale. More standing counters
means more people—and therefore greater population density.
</p>
</header>
<div class="tools">
<button class="tool-button" id="resetView" type="button" title="Reset camera view">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 4v6h6"></path>
<path d="M5.5 15.5a8 8 0 1 0 .5-8.5L4 10"></path>
</svg>
<span>Reset view</span>
</button>
</div>
<section class="zone-label" id="labelA" style="--accent: var(--accent-a)">
<div class="label-top"><span>Tile A · 1 km²</span><i></i></div>
<strong>160,000 / km²</strong>
<small>16 standing counters</small>
</section>
<section class="zone-label" id="labelB" style="--accent: var(--accent-b)">
<div class="label-top"><span>Tile B · 1 km²</span><i></i></div>
<strong>280,000 / km²</strong>
<small>28 standing counters</small>
</section>
<aside class="legend" aria-label="Shared population legend">
<div class="legend-icon" aria-hidden="true"></div>
<div class="legend-copy">
<strong>1 counter = 10,000 people</strong>
<span>Shared scale for both tiles</span>
</div>
<div class="equal-badge">Equal area<br />Same scale</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</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 app = document.querySelector("#app");
const canvas = document.querySelector("#scene");
const labelA = document.querySelector("#labelA");
const labelB = document.querySelector("#labelB");
const resetButton = document.querySelector("#resetView");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09151d);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const hemisphere = new THREE.HemisphereLight(0xcce8ff, 0x33483d, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.1);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8fd8ff, 0.8);
fillLight.position.set(8, 6, -8);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x0c1a22,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.37;
ground.receiveShadow = true;
scene.add(ground);
const groundGrid = new THREE.GridHelper(50, 25, 0x29404a, 0x1b3038);
groundGrid.position.y = -0.365;
groundGrid.material.transparent = true;
groundGrid.material.opacity = 0.28;
scene.add(groundGrid);
const TILE_SIZE = 6.4;
const TILE_X = 3.6;
const tileCenterA = -TILE_X;
const tileCenterB = TILE_X;
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x263b43,
roughness: 0.76,
metalness: 0.03
});
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xdde3dc,
roughness: 0.9,
metalness: 0
});
function createTile(x, accentColor) {
const group = new THREE.Group();
group.position.x = x;
const base = new THREE.Mesh(
new THREE.BoxGeometry(6.56, 0.36, 6.56),
baseMaterial
);
base.position.y = -0.18;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const surface = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.1, TILE_SIZE),
tileMaterial
);
surface.position.y = 0.05;
surface.castShadow = true;
surface.receiveShadow = true;
group.add(surface);
const grid = new THREE.GridHelper(TILE_SIZE, 8, 0x82918d, 0x82918d);
grid.position.y = 0.106;
grid.material.transparent = true;
grid.material.opacity = 0.18;
group.add(grid);
const accent = new THREE.Mesh(
new THREE.BoxGeometry(0.85, 0.035, 0.16),
new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.55
})
);
accent.position.set(-2.65, 0.125, 3.02);
accent.castShadow = true;
group.add(accent);
scene.add(group);
return group;
}
createTile(tileCenterA, 0x48d6c2);
createTile(tileCenterB, 0xff7b72);
const counterMaterial = new THREE.MeshStandardMaterial({
color: 0xffca58,
roughness: 0.52,
metalness: 0.04
});
const headGeometry = new THREE.SphereGeometry(0.155, 16, 12);
const bodyGeometry = new THREE.CylinderGeometry(0.13, 0.16, 0.48, 12);
const baseGeometry = new THREE.CylinderGeometry(0.18, 0.18, 0.075, 12);
function createStandingCounter() {
const group = new THREE.Group();
const body = new THREE.Mesh(bodyGeometry, counterMaterial);
body.position.y = 0.36;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(headGeometry, counterMaterial);
head.position.y = 0.735;
head.castShadow = true;
group.add(head);
const foot = new THREE.Mesh(baseGeometry, counterMaterial);
foot.position.y = 0.0375;
foot.castShadow = true;
group.add(foot);
return group;
}
function populateTile({
centerX,
columns,
rows,
xSpacing,
zSpacing
}) {
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const counter = createStandingCounter();
counter.position.set(
centerX + (column - (columns - 1) / 2) * xSpacing,
0.1,
(row - (rows - 1) / 2) * zSpacing
);
scene.add(counter);
}
}
}
// Tile A: 4 × 4 = 16 counters.
populateTile({
centerX: tileCenterA,
columns: 4,
rows: 4,
xSpacing: 1.25,
zSpacing: 1.25
});
// Tile B: 7 × 4 = 28 counters.
populateTile({
centerX: tileCenterB,
columns: 7,
rows: 4,
xSpacing: 0.78,
zSpacing: 1.25
});
const cameraTarget = new THREE.Vector3(0, 0.1, 0);
let azimuth = 0;
let elevation = 0.69;
let cameraZoom = 1;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const radius = 22;
const horizontal = Math.cos(elevation) * radius;
camera.position.set(
Math.sin(azimuth) * horizontal,
Math.sin(elevation) * radius,
Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resetCamera() {
azimuth = 0;
elevation = 0.69;
cameraZoom = 1;
updateCamera();
}
function resize() {
const width = app.clientWidth;
const height = app.clientHeight;
const aspect = width / height;
const requiredWidth = 16.6;
const viewHeight = Math.max(10.4, requiredWidth / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraZoom;
renderer.setSize(width, height, false);
camera.updateProjectionMatrix();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
azimuth -= deltaX * 0.005;
elevation = THREE.MathUtils.clamp(
elevation + deltaY * 0.004,
0.34,
1.18
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.75
);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
window.addEventListener("resize", resize);
const labelAnchorA = new THREE.Vector3(tileCenterA, 0.25, -2.95);
const labelAnchorB = new THREE.Vector3(tileCenterB, 0.25, -2.95);
const projected = new THREE.Vector3();
function positionLabel(element, anchor) {
projected.copy(anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * app.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * app.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
resize();
updateCamera();
function animate() {
positionLabel(labelA, labelAnchorA);
positionLabel(labelB, labelAnchorB);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```