Prompt specification
Build or customize the Three.js 3D scene "Historical counting desk and merchant ledger" 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: Historical counting desk and merchant ledger
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/historical-counting-desk-and-merchant-ledger-x2483
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Create a referenced counting desk with an abacus, goods counters, and a simple ledger. Show equivalent quantities represented physically and symbolically using a clearly stated notation.
Working Three.js Starter (historical-counting-desk-and-merchant-ledger-x2483):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Equivalent Counting Desk</title>
<style>
:root {
--ink: #193e3a;
--teal: #4f8f86;
--paper: #f7efd9;
--accent: #df9b50;
--panel: rgba(255, 250, 237, 0.91);
--border: rgba(25, 62, 58, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded8c9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 38px rgba(44, 43, 32, 0.14);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 20px;
left: 20px;
width: min(430px, calc(100vw - 40px));
padding: 17px 20px 16px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 38px);
font-weight: 600;
line-height: 1.03;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 0;
color: rgba(25, 62, 58, 0.72);
font-size: 13px;
line-height: 1.45;
}
#notation-card {
bottom: 20px;
left: 20px;
width: min(430px, calc(100vw - 40px));
padding: 16px 18px;
}
.notation-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 11px;
}
.notation-heading strong {
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#quantity-display {
min-width: 48px;
padding: 3px 10px 4px;
border-radius: 999px;
background: var(--ink);
color: #fff8e8;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
line-height: 1;
text-align: center;
}
.equation {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 10px;
font-size: 14px;
font-weight: 750;
}
.symbol {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 26px;
height: 26px;
padding: 0 8px;
border-radius: 8px;
background: rgba(79, 143, 134, 0.14);
color: #356e66;
}
.symbol.good {
border-radius: 5px 12px 5px 12px;
transform: rotate(-3deg);
}
.symbol.bead {
border-radius: 50%;
}
.symbol.mark {
border-radius: 3px;
font-family: Georgia, serif;
font-size: 21px;
}
.equals {
color: rgba(25, 62, 58, 0.42);
font-family: Georgia, serif;
font-size: 18px;
}
.notation-note {
margin: 0;
color: rgba(25, 62, 58, 0.7);
font-size: 12px;
line-height: 1.45;
}
#controls {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 9px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 10px;
background: #fffaf0;
color: var(--ink);
font: inherit;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
opacity 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
background: #fff;
}
button:active:not(:disabled) {
transform: translateY(1px);
}
button:focus-visible {
outline: 3px solid rgba(79, 143, 134, 0.38);
outline-offset: 2px;
}
button:disabled {
cursor: default;
opacity: 0.35;
}
#decrease,
#increase {
width: 42px;
height: 42px;
font-size: 24px;
}
#reset-count {
height: 42px;
padding: 0 13px;
font-size: 12px;
}
#view-hint {
top: 20px;
right: 20px;
padding: 10px 13px;
color: rgba(25, 62, 58, 0.72);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #ded8c9;
color: var(--ink);
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
#notation-card {
bottom: 76px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
#controls {
right: 12px;
bottom: 12px;
}
#view-hint {
display: none;
}
.notation-note {
font-size: 11px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly counting desk"></canvas>
<section id="title-card" class="panel">
<p class="eyebrow">Low-poly counting study</p>
<h1>Equivalent Counting Desk</h1>
<p class="subtitle">
Physical goods, abacus beads, and ledger marks express the same quantity.
Change the count to compare all three representations.
</p>
</section>
<section id="notation-card" class="panel" aria-live="polite">
<div class="notation-heading">
<strong>Counting notation</strong>
<span id="quantity-display" aria-label="Current quantity">4</span>
</div>
<div class="equation" aria-label="One good equals one active bead equals one ledger mark">
<span class="symbol good" title="One wrapped good">1</span>
<span class="equals">=</span>
<span class="symbol bead" title="One active abacus bead">●</span>
<span class="equals">=</span>
<span class="symbol mark" title="One ledger mark">I</span>
<span>one unit</span>
</div>
<p class="notation-note">
Each wrapped good has one teal tag. On the abacus, one teal bead occupies
a rail; the remaining brown beads are parked. The ledger records one
vertical stroke per unit.
</p>
</section>
<div id="controls" class="panel" aria-label="Count controls">
<button id="decrease" type="button" aria-label="Decrease quantity">−</button>
<button id="reset-count" type="button">Reset count</button>
<button id="increase" type="button" aria-label="Increase quantity">+</button>
</div>
<div id="view-hint" class="panel">
Drag to orbit · Scroll to zoom · Double-click to reset view
</div>
<div id="loading">Preparing the counting desk…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and direct camera controls
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded8c9);
scene.fog = new THREE.Fog(0xded8c9, 17, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.39,
phi: 0.94,
radius: 12.8,
target: new THREE.Vector3(0, 2.0, 0)
};
function updateCamera() {
const horizontalRadius =
orbit.radius * Math.sin(orbit.phi);
camera.position.set(
orbit.target.x +
horizontalRadius * Math.sin(orbit.theta),
orbit.target.y +
orbit.radius * Math.cos(orbit.phi),
orbit.target.z +
horizontalRadius * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.theta -= deltaX * 0.007;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.006,
0.48,
1.34
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.009,
8.2,
18
);
updateCamera();
},
{ passive: false }
);
function resetView() {
orbit.theta = 0.39;
orbit.phi = 0.94;
orbit.radius = 12.8;
updateCamera();
}
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff4d8,
0x66766f,
1.65
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe6b9, 3.25);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e3dc, 1.15);
fillLight.position.set(7, 6, -5);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Procedural materials and textures
// -------------------------------------------------------------------------
function makeWoodTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 512;
const context = textureCanvas.getContext("2d");
context.fillStyle = "#a56d43";
context.fillRect(0, 0, 512, 512);
for (let line = 0; line < 85; line++) {
const y = (line / 84) * 512;
const wave = Math.sin(line * 1.73) * 8;
context.beginPath();
context.moveTo(0, y + wave);
context.bezierCurveTo(
140,
y - 14 + wave,
330,
y + 18 - wave,
512,
y + wave * 0.4
);
context.strokeStyle =
line % 4 === 0
? "rgba(65, 35, 20, 0.18)"
: "rgba(255, 214, 153, 0.12)";
context.lineWidth = line % 5 === 0 ? 2.2 : 1;
context.stroke();
}
for (let knot = 0; knot < 5; knot++) {
const x = 62 + knot * 102;
const y = 75 + ((knot * 139) % 330);
context.beginPath();
context.ellipse(x, y, 17, 7, -0.18, 0, Math.PI * 2);
context.strokeStyle = "rgba(72, 37, 21, 0.22)";
context.lineWidth = 2;
context.stroke();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.1, 1.1);
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const woodTexture = makeWoodTexture();
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const woodMaterial = new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.8,
metalness: 0
});
const darkWoodMaterial = material(0x593c2b);
const deepWoodMaterial = material(0x3f3029);
const brassMaterial = material(0xb68a42, {
roughness: 0.38,
metalness: 0.62
});
const tealMaterial = material(0x4f8f86, {
roughness: 0.68
});
const brownBeadMaterial = material(0x8b5d42, {
roughness: 0.65
});
const creamMaterial = material(0xf2e6c8);
const clothMaterial = material(0xc8b58e);
const paperMaterial = material(0xf8efd7);
const coverMaterial = material(0x315b55);
function addMesh(geometry, meshMaterial, parent = scene) {
const mesh = new THREE.Mesh(geometry, meshMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(
width,
height,
depth,
meshMaterial,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = addMesh(
new THREE.BoxGeometry(width, height, depth),
meshMaterial,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
// -------------------------------------------------------------------------
// Floor and counting desk
// -------------------------------------------------------------------------
const floor = addMesh(
new THREE.PlaneGeometry(60, 60),
material(0xc9c6b6, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.castShadow = false;
const DESK_TOP = 2.3;
addBox(10.8, 0.36, 5.6, woodMaterial, 0, 2.12, 0);
addBox(10.95, 0.12, 5.75, darkWoodMaterial, 0, 1.93, 0);
// Desk legs.
for (const x of [-4.65, 4.65]) {
for (const z of [-2.15, 2.15]) {
addBox(0.48, 1.94, 0.48, darkWoodMaterial, x, 0.97, z);
addBox(0.6, 0.12, 0.6, deepWoodMaterial, x, 0.08, z);
}
}
// Aprons and a shallow front drawer.
addBox(9.7, 0.5, 0.25, darkWoodMaterial, 0, 1.62, 2.52);
addBox(9.7, 0.5, 0.25, darkWoodMaterial, 0, 1.62, -2.52);
addBox(0.25, 0.5, 4.5, darkWoodMaterial, -4.75, 1.62, 0);
addBox(0.25, 0.5, 4.5, darkWoodMaterial, 4.75, 1.62, 0);
addBox(3.9, 0.66, 0.16, woodMaterial, 0, 1.63, 2.69);
addBox(3.45, 0.49, 0.04, darkWoodMaterial, 0, 1.63, 2.79);
const drawerHandle = addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 1.25, 10),
brassMaterial
);
drawerHandle.rotation.z = Math.PI / 2;
drawerHandle.position.set(0, 1.64, 2.91);
for (const x of [-0.58, 0.58]) {
const support = addMesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.22, 8),
brassMaterial
);
support.rotation.x = Math.PI / 2;
support.position.set(x, 1.64, 2.82);
}
// Counting cloth under the physical goods.
const cloth = addBox(
4.8,
0.055,
1.85,
clothMaterial,
-2.45,
DESK_TOP + 0.03,
0
);
cloth.castShadow = false;
// -------------------------------------------------------------------------
// Canvas-based labels
// -------------------------------------------------------------------------
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.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function makeLabel(text, options = {}) {
const width = options.width ?? 768;
const height = options.height ?? 144;
const labelCanvas = document.createElement("canvas");
labelCanvas.width = width;
labelCanvas.height = height;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const spriteMaterial = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(spriteMaterial);
sprite.scale.set(
options.scaleX ?? 2.8,
options.scaleY ?? 0.525,
1
);
sprite.renderOrder = 20;
function draw(newText) {
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(32, 50, 45, 0.16)";
roundedRect(
context,
12,
15,
width - 24,
height - 24,
25
);
context.fill();
context.fillStyle = options.background ?? "rgba(25, 62, 58, 0.94)";
roundedRect(
context,
8,
8,
width - 16,
height - 24,
24
);
context.fill();
context.strokeStyle = "rgba(255,255,255,0.2)";
context.lineWidth = 3;
roundedRect(
context,
8,
8,
width - 16,
height - 24,
24
);
context.stroke();
let fontSize = options.fontSize ?? 42;
context.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
while (
context.measureText(newText).width >
width - 80 &&
fontSize > 20
) {
fontSize -= 1;
context.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
}
context.fillStyle = options.color ?? "#fff7df";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(newText, width / 2, (height - 8) / 2);
texture.needsUpdate = true;
}
draw(text);
return {
sprite,
texture,
setText: draw
};
}
const physicalLabel = makeLabel("PHYSICAL GOODS · 4");
physicalLabel.sprite.position.set(-2.5, 4.08, 0);
scene.add(physicalLabel.sprite);
const abacusLabel = makeLabel("ABACUS · 4 ACTIVE BEADS");
abacusLabel.sprite.position.set(1.3, 3.63, -0.72);
scene.add(abacusLabel.sprite);
const ledgerLabel = makeLabel("LEDGER · 4 MARKS");
ledgerLabel.sprite.position.set(1.35, 3.12, 1.48);
scene.add(ledgerLabel.sprite);
const equationLabel = makeLabel("N = 4 · 1 GOOD = 1 BEAD = 1 MARK", {
width: 1024,
height: 154,
fontSize: 39,
scaleX: 4.1,
scaleY: 0.62,
background: "rgba(247, 239, 217, 0.96)",
color: "#285f57"
});
equationLabel.sprite.position.set(-2.35, 3.17, 1.55);
scene.add(equationLabel.sprite);
// -------------------------------------------------------------------------
// Physical goods: each teal-tagged bundle represents one unit
// -------------------------------------------------------------------------
const sackGroups = [];
for (let index = 0; index < 5; index++) {
const sackGroup = new THREE.Group();
sackGroup.position.set(
-4.02 + index * 0.78,
DESK_TOP + 0.07,
index % 2 === 0 ? -0.08 : 0.1
);
scene.add(sackGroup);
const body = addMesh(
new THREE.DodecahedronGeometry(0.48, 0),
tealMaterial,
sackGroup
);
body.scale.set(0.86, 1.12, 0.82);
body.position.y = 0.48;
body.rotation.y = index * 0.42;
const neck = addMesh(
new THREE.CylinderGeometry(0.13, 0.19, 0.27, 7),
creamMaterial,
sackGroup
);
neck.position.y = 1.02;
const tie = addMesh(
new THREE.TorusGeometry(0.16, 0.035, 5, 10),
brassMaterial,
sackGroup
);
tie.rotation.x = Math.PI / 2;
tie.position.y = 0.94;
const unitTag = makeLabel("1", {
width: 192,
height: 144,
fontSize: 67,
scaleX: 0.46,
scaleY: 0.34,
background: "rgba(248, 239, 216, 0.98)",
color: "#285f57"
});
unitTag.sprite.position.set(0, 1.33, 0);
sackGroup.add(unitTag.sprite);
sackGroup.userData.targetScale = index < 4 ? 1 : 0;
sackGroup.scale.setScalar(sackGroup.userData.targetScale);
sackGroups.push(sackGroup);
}
// -------------------------------------------------------------------------
// Abacus: one active teal bead on a rail equals one unit
// -------------------------------------------------------------------------
const abacus = new THREE.Group();
abacus.position.set(1.3, DESK_TOP + 0.01, -0.67);
scene.add(abacus);
addBox(4.62, 0.16, 3.04, woodMaterial, 0, 0.08, 0, abacus);
addBox(4.72, 0.07, 3.14, darkWoodMaterial, 0, 0.18, 0, abacus);
addBox(0.18, 1.02, 3.0, darkWoodMaterial, -2.2, 0.64, 0, abacus);
addBox(0.18, 1.02, 3.0, darkWoodMaterial, 2.2, 0.64, 0, abacus);
addBox(4.4, 0.15, 0.17, darkWoodMaterial, 0, 0.82, -1.43, abacus);
addBox(4.4, 0.15, 0.17, darkWoodMaterial, 0, 0.82, 1.43, abacus);
const railPositions = [-1.05, -0.525, 0, 0.525, 1.05];
const beadGeometry = new THREE.IcosahedronGeometry(0.16, 0);
const abacusRows = [];
for (let row = 0; row < railPositions.length; row++) {
const z = railPositions[row];
const rod = addMesh(
new THREE.CylinderGeometry(0.026, 0.026, 4.1, 8),
brassMaterial,
abacus
);
rod.rotation.z = Math.PI / 2;
rod.position.set(0, 0.64, z);
const rowLabel = makeLabel(String(row + 1), {
width: 128,
height: 128,
fontSize: 62,
scaleX: 0.25,
scaleY: 0.25,
background: "rgba(182, 138, 66, 0.98)",
color: "#fff8df"
});
rowLabel.sprite.position.set(-2.34, 0.65, z);
abacus.add(rowLabel.sprite);
const beads = [];
for (let beadIndex = 0; beadIndex < 8; beadIndex++) {
const isActive = row < 4 && beadIndex === 0;
const bead = addMesh(
beadGeometry,
isActive ? tealMaterial : brownBeadMaterial,
abacus
);
const parkedX = -0.05 + beadIndex * 0.3;
bead.position.set(
isActive ? -1.62 : parkedX,
0.64,
z
);
bead.scale.set(0.78, 1, 1);
bead.userData.targetX = bead.position.x;
beads.push(bead);
}
abacusRows.push(beads);
}
// -------------------------------------------------------------------------
// Open ledger with a dynamically drawn page
// -------------------------------------------------------------------------
const ledger = new THREE.Group();
ledger.position.set(1.35, DESK_TOP + 0.035, 1.48);
ledger.rotation.y = -0.06;
scene.add(ledger);
addBox(4.25, 0.12, 1.9, coverMaterial, 0, 0.06, 0, ledger);
addBox(2.03, 0.18, 1.72, paperMaterial, -1.02, 0.17, 0, ledger);
addBox(2.03, 0.18, 1.72, paperMaterial, 1.02, 0.17, 0, ledger);
addBox(0.09, 0.2, 1.74, darkWoodMaterial, 0, 0.18, 0, ledger);
const leftPageCanvas = document.createElement("canvas");
leftPageCanvas.width = 512;
leftPageCanvas.height = 384;
const leftContext = leftPageCanvas.getContext("2d");
leftContext.fillStyle = "#f8efd8";
leftContext.fillRect(0, 0, 512, 384);
leftContext.strokeStyle = "#d9caa5";
leftContext.lineWidth = 2;
for (let y = 94; y < 340; y += 38) {
leftContext.beginPath();
leftContext.moveTo(35, y);
leftContext.lineTo(477, y);
leftContext.stroke();
}
leftContext.fillStyle = "#315b55";
leftContext.font = "800 28px Georgia, serif";
leftContext.fillText("ACCOUNT BOOK", 35, 45);
leftContext.fillStyle = "#6d806f";
leftContext.font = "700 19px sans-serif";
leftContext.fillText("GOODS / UNITS", 35, 80);
leftContext.fillText("METHOD", 35, 156);
leftContext.fillText("RECORD", 35, 270);
leftContext.fillStyle = "#244d47";
leftContext.font = "18px sans-serif";
leftContext.fillText("Wrapped goods", 35, 118);
leftContext.fillText("One active bead", 35, 194);
leftContext.fillText("Vertical marks", 35, 308);
const leftPageTexture = new THREE.CanvasTexture(leftPageCanvas);
leftPageTexture.colorSpace = THREE.SRGBColorSpace;
leftPageTexture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const rightPageCanvas = document.createElement("canvas");
rightPageCanvas.width = 512;
rightPageCanvas.height = 384;
const rightContext = rightPageCanvas.getContext("2d");
const rightPageTexture = new THREE.CanvasTexture(rightPageCanvas);
rightPageTexture.colorSpace = THREE.SRGBColorSpace;
rightPageTexture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const leftPage = addMesh(
new THREE.PlaneGeometry(1.88, 1.48),
new THREE.MeshStandardMaterial({
map: leftPageTexture,
roughness: 0.92
}),
ledger
);
leftPage.rotation.x = -Math.PI / 2;
leftPage.position.set(-1.02, 0.267, 0);
leftPage.castShadow = false;
const rightPage = addMesh(
new THREE.PlaneGeometry(1.88, 1.48),
new THREE.MeshStandardMaterial({
map: rightPageTexture,
roughness: 0.92
}),
ledger
);
rightPage.rotation.x = -Math.PI / 2;
rightPage.position.set(1.02, 0.267, 0);
rightPage.castShadow = false;
function drawLedger(count) {
const context = rightContext;
context.fillStyle = "#f8efd8";
context.fillRect(0, 0, 512, 384);
context.strokeStyle = "#d9caa5";
context.lineWidth = 2;
context.strokeRect(18, 18, 476, 348);
context.fillStyle = "#315b55";
context.font = "800 28px Georgia, serif";
context.fillText("LEDGER", 35, 56);
context.fillStyle = "#6d806f";
context.font = "700 18px sans-serif";
context.fillText("TOTAL GOODS", 35, 91);
context.fillStyle = "#285f57";
context.font = "800 104px Georgia, serif";
context.fillText(String(count), 35, 190);
context.fillStyle = "#6d806f";
context.font = "700 17px sans-serif";
context.fillText("UNITS", 37, 221);
context.strokeStyle = "#d9caa5";
context.beginPath();
context.moveTo(35, 244);
context.lineTo(477, 244);
context.stroke();
context.fillStyle = "#6d806f";
context.font = "700 17px sans-serif";
context.fillText("RECORD MARKS", 35, 273);
context.strokeStyle = "#4f8f86";
context.lineWidth = 9;
context.lineCap = "round";
for (let index = 0; index < count; index++) {
const x = 46 + index * 28;
context.beginPath();
context.moveTo(x, 315);
context.lineTo(x, 344);
context.stroke();
}
rightPageTexture.needsUpdate = true;
}
// A small pencil beside the ledger.
const pencil = addMesh(
new THREE.CylinderGeometry(0.045, 0.045, 2.15, 6),
material(0xcf8842)
);
pencil.rotation.z = Math.PI / 2;
pencil.position.set(3.65, DESK_TOP + 0.09, 1.54);
const pencilTip = addMesh(
new THREE.ConeGeometry(0.06, 0.22, 6),
creamMaterial
);
pencilTip.rotation.z = -Math.PI / 2;
pencilTip.position.set(4.83, DESK_TOP + 0.09, 1.54);
// -------------------------------------------------------------------------
// Quantity controls and synchronized representations
// -------------------------------------------------------------------------
const quantityDisplay = document.querySelector("#quantity-display");
const decreaseButton = document.querySelector("#decrease");
const increaseButton = document.querySelector("#increase");
const resetButton = document.querySelector("#reset-count");
let quantity = 4;
function setQuantity(nextQuantity) {
quantity = THREE.MathUtils.clamp(nextQuantity, 0, 5);
quantityDisplay.textContent = String(quantity);
quantityDisplay.setAttribute(
"aria-label",
`${quantity} unit${quantity === 1 ? "" : "s"}`
);
decreaseButton.disabled = quantity === 0;
increaseButton.disabled = quantity === 5;
sackGroups.forEach((sack, index) => {
sack.userData.targetScale = index < quantity ? 1 : 0;
if (sack.userData.targetScale > 0) sack.visible = true;
});
abacusRows.forEach((row, rowIndex) => {
const railIsActive = rowIndex < quantity;
row.forEach((bead, beadIndex) => {
if (railIsActive && beadIndex === 0) {
bead.material = tealMaterial;
bead.userData.targetX = -1.62;
} else {
bead.material = brownBeadMaterial;
if (railIsActive) {
bead.userData.targetX = -0.05 + (beadIndex - 1) * 0.3;
} else {
bead.userData.targetX = -0.05 + beadIndex * 0.3;
}
}
});
});
drawLedger(quantity);
physicalLabel.setText(`PHYSICAL GOODS · ${quantity}`);
abacusLabel.setText(`ABACUS · ${quantity} ACTIVE BEADS`);
ledgerLabel.setText(`LEDGER · ${quantity} MARKS`);
equationLabel.setText(
`N = ${quantity} · 1 GOOD = 1 BEAD = 1 MARK`
);
}
decreaseButton.addEventListener("click", () => {
setQuantity(quantity - 1);
});
increaseButton.addEventListener("click", () => {
setQuantity(quantity + 1);
});
resetButton.addEventListener("click", () => {
setQuantity(4);
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowDown" || event.key === "ArrowLeft") {
event.preventDefault();
setQuantity(quantity - 1);
}
if (event.key === "ArrowUp" || event.key === "ArrowRight") {
event.preventDefault();
setQuantity(quantity + 1);
}
});
setQuantity(4);
// -------------------------------------------------------------------------
// Animation and responsive rendering
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
sackGroups.forEach((sack) => {
const target = sack.userData.targetScale;
const current = sack.scale.x;
const next = THREE.MathUtils.lerp(current, target, 0.12);
sack.scale.setScalar(next);
if (target === 0 && next < 0.003) {
sack.visible = false;
}
});
abacusRows.forEach((row) => {
row.forEach((bead) => {
bead.position.x = THREE.MathUtils.lerp(
bead.position.x,
bead.userData.targetX,
0.12
);
});
});
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 50 : 38;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
animate();
document.querySelector("#loading").classList.add("hidden");
</script>
</body>
</html>
```