Prompt specification
Build or customize the Three.js 3D scene "Change a notice and compare distribution delay" 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: Change a notice and compare distribution delay
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-a-notice-and-compare-distribution-delay-x2340
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts early printed news sheets and their distribution. Let users correct one symbol before or after printing a batch of fictional notices. Track which copies contain the change and distinguish production delay from transport delay. Low-poly.
Working Three.js Starter (change-a-notice-and-compare-distribution-delay-x2340):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Morning Ledger — Newsprint in Motion</title>
<style>
:root {
--ink: #302922;
--muted: #71675b;
--paper: #f4ead3;
--paper-deep: #e8dcc0;
--line: #c9b996;
--amber: #d89031;
--blue: #5687aa;
--green: #647f57;
--red: #a55345;
--shadow: 0 14px 36px rgba(54, 42, 28, .18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfc3a8;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.masthead {
position: fixed;
z-index: 10;
top: 16px;
left: 18px;
right: 18px;
height: 58px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 9px 16px;
border: 1px solid rgba(72, 57, 37, .42);
background: rgba(246, 238, 215, .92);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
pointer-events: none;
}
.masthead-title {
display: flex;
align-items: baseline;
gap: 15px;
}
.masthead-title strong {
font-size: 20px;
letter-spacing: .08em;
}
.masthead-title span {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
letter-spacing: .12em;
text-transform: uppercase;
}
.masthead-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.edition {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
letter-spacing: .08em;
}
.panel {
position: fixed;
z-index: 12;
border: 1px solid rgba(72, 57, 37, .42);
background: rgba(246, 238, 215, .94);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.controls {
left: 18px;
top: 90px;
width: 330px;
padding: 16px;
max-height: calc(100vh - 108px);
overflow: auto;
}
.tracking {
right: 18px;
top: 90px;
width: 350px;
padding: 15px;
max-height: calc(100vh - 270px);
overflow: auto;
}
.eyebrow {
margin: 0 0 6px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: .15em;
text-transform: uppercase;
}
h2 {
margin: 0 0 12px;
font-size: 20px;
font-weight: 500;
}
.rule {
height: 1px;
margin: 14px 0;
background: var(--line);
}
.notice-card {
padding: 12px;
border: 1px solid var(--line);
background: #f8efd9;
box-shadow: inset 0 0 20px rgba(111, 81, 35, .08);
}
.notice-kicker {
text-align: center;
font-size: 10px;
font-weight: bold;
letter-spacing: .18em;
}
.notice {
margin: 9px 0 7px;
font-size: 19px;
line-height: 1.35;
text-align: center;
}
#symbolInput {
width: 38px;
height: 34px;
border: 0;
border-bottom: 2px solid var(--red);
outline: none;
background: rgba(165, 83, 69, .08);
color: var(--red);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 21px;
font-weight: 800;
text-align: center;
}
.small-note {
margin: 7px 0 0;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.45;
}
.status-note {
min-height: 45px;
margin: 10px 0;
padding: 9px 10px;
border-left: 3px solid var(--line);
background: rgba(119, 96, 62, .07);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.45;
}
.status-note.good { border-left-color: var(--green); }
.status-note.warn { border-left-color: var(--amber); }
.button-row {
display: flex;
gap: 8px;
}
button {
min-height: 37px;
padding: 8px 11px;
border: 1px solid #76664f;
background: #e8dcc0;
color: var(--ink);
cursor: pointer;
transition: transform .12s ease, background .12s ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
background: #f8efd9;
}
button:active:not(:disabled) { transform: translateY(0); }
button:disabled {
cursor: not-allowed;
opacity: .48;
}
.primary {
width: 100%;
margin-top: 9px;
border-color: #4f4639;
background: var(--ink);
color: #f5ead2;
font-weight: bold;
letter-spacing: .04em;
}
.primary:hover:not(:disabled) { background: #4b4034; }
.delay {
margin: 11px 0 14px;
}
.delay-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 5px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 700;
}
.delay-label output {
color: var(--muted);
font-weight: 500;
}
input[type="range"] {
width: 100%;
accent-color: var(--amber);
cursor: pointer;
}
#transportDelay { accent-color: var(--blue); }
.legend {
display: grid;
gap: 7px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
color: var(--muted);
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 13px;
height: 13px;
border: 1px solid rgba(0,0,0,.15);
background: var(--amber);
}
.swatch.transport { background: var(--blue); }
.swatch.route { background: var(--green); }
.swatch.corrected { background: #b7c9a9; }
.swatch.original { background: #ded1b4; }
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 12px;
}
.stat {
padding: 8px 5px;
border: 1px solid var(--line);
text-align: center;
background: rgba(255,255,255,.22);
}
.stat strong {
display: block;
font-size: 21px;
font-weight: 500;
}
.stat span {
display: block;
margin-top: 2px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
letter-spacing: .08em;
text-transform: uppercase;
}
.batch-list {
display: grid;
gap: 9px;
}
.batch-card {
padding: 10px;
border: 1px solid var(--line);
background: rgba(255,255,255,.2);
}
.batch-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
}
.batch-title {
font-size: 15px;
font-weight: bold;
}
.batch-subtitle {
margin-top: 2px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.status-pill {
flex: 0 0 auto;
padding: 3px 6px;
border: 1px solid var(--line);
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
letter-spacing: .04em;
text-transform: uppercase;
}
.status-pill.production { background: #eed6aa; color: #704a17; }
.status-pill.waiting { background: #c9dfec; color: #315a76; }
.status-pill.transit { background: #d5e0ce; color: #405a38; }
.status-pill.delivered { background: #d8d3c5; color: #4e4a42; }
.stage-strip {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 3px;
margin: 9px 0 7px;
}
.stage {
padding: 4px 2px;
border-top: 3px solid #cfc3a7;
color: #918677;
text-align: center;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 7px;
letter-spacing: .03em;
text-transform: uppercase;
}
.stage.active { border-top-color: var(--amber); color: var(--ink); }
.stage.active.transport { border-top-color: var(--blue); }
.stage.active.route { border-top-color: var(--green); }
.stage.done { border-top-color: #8b806d; }
.symbol-change {
margin: 6px 0;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.symbol-change .arrow { color: var(--muted); }
.symbol-change .changed { color: var(--green); font-weight: bold; }
.copy-grid {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin: 7px 0;
}
.copy-chip {
padding: 3px 6px;
border: 1px solid #bfb092;
background: #ded1b4;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
cursor: help;
}
.copy-chip.corrected {
border-color: #7f9870;
background: #b7c9a9;
}
.batch-action {
width: 100%;
min-height: 31px;
padding: 5px 7px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.applied-label {
color: var(--green);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: bold;
}
.event-log {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.event {
display: grid;
grid-template-columns: 38px 1fr;
gap: 7px;
padding: 5px 0;
border-bottom: 1px dotted #c8ba9a;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
line-height: 1.4;
}
.event time { color: var(--muted); }
.event.production { border-left: 3px solid var(--amber); }
.event.transport { border-left: 3px solid var(--blue); }
.event.delivery { border-left: 3px solid var(--green); }
.event.correction { border-left: 3px solid var(--red); }
.timeline {
position: fixed;
z-index: 11;
left: 366px;
right: 386px;
bottom: 18px;
padding: 12px 14px;
max-height: 176px;
overflow: hidden;
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.timeline-head .eyebrow { margin: 0; }
.timeline-legend {
display: flex;
gap: 12px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
}
.timeline-legend span::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 4px;
background: var(--amber);
}
.timeline-legend .transport::before { background: var(--blue); }
.timeline-legend .route::before { background: var(--green); }
#timelineRows {
max-height: 105px;
overflow: auto;
}
.timeline-row {
display: grid;
grid-template-columns: 56px 1fr 42px;
align-items: center;
gap: 7px;
min-height: 29px;
}
.timeline-label,
.timeline-time {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
}
.timeline-time { text-align: right; }
.track {
position: relative;
height: 21px;
border: 1px solid #cabb9c;
background:
repeating-linear-gradient(90deg, transparent 0, transparent calc(20% - 1px), rgba(80,65,42,.08) calc(20% - 1px), rgba(80,65,42,.08) 20%),
rgba(255,255,255,.22);
}
.segment {
position: absolute;
top: 3px;
height: 13px;
min-width: 2px;
background: var(--amber);
}
.segment.transport { background: var(--blue); }
.segment.route { background: var(--green); }
.playhead {
position: absolute;
z-index: 4;
top: -3px;
bottom: -3px;
width: 1px;
background: var(--red);
pointer-events: none;
}
.playhead::before {
content: "";
position: absolute;
top: -2px;
left: -2px;
width: 5px;
height: 5px;
background: var(--red);
transform: rotate(45deg);
}
.empty-state {
padding: 18px 8px;
color: var(--muted);
text-align: center;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 205px;
max-width: min(520px, 80vw);
padding: 10px 14px;
transform: translate(-50%, 20px);
border: 1px solid #514536;
background: rgba(48, 41, 34, .94);
color: #f6ecd5;
box-shadow: var(--shadow);
opacity: 0;
pointer-events: none;
transition: opacity .18s ease, transform .18s ease;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.camera-help {
position: fixed;
z-index: 8;
left: 18px;
bottom: 18px;
padding: 7px 9px;
border: 1px solid rgba(72,57,37,.32);
background: rgba(246,238,215,.78);
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
pointer-events: none;
}
@media (max-width: 1120px) {
.tracking {
top: auto;
bottom: 18px;
max-height: 48vh;
}
.timeline {
left: 366px;
right: 18px;
bottom: 18px;
height: 180px;
}
.camera-help { display: none; }
}
@media (max-width: 760px) {
.masthead { height: 52px; }
.masthead-title span, .edition { display: none; }
.controls {
top: 78px;
width: calc(50% - 23px);
max-height: 46vh;
}
.tracking {
width: calc(50% - 23px);
max-height: 46vh;
}
.timeline { display: none; }
.notice { font-size: 15px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Low-poly printing workshop and newspaper distribution scene"></canvas>
<header class="masthead">
<div class="masthead-title">
<strong>THE MORNING LEDGER</strong>
<span>Newsprint, in motion · production study 1784</span>
</div>
<div class="masthead-actions">
<span class="edition">FICTIONAL EDITION · FOUR COPIES PER BATCH</span>
<button id="resetCamera" type="button">Reset view</button>
</div>
</header>
<aside class="panel controls">
<p class="eyebrow">Proof sheet</p>
<h2>One symbol to correct</h2>
<div class="notice-card">
<div class="notice-kicker">IMPORTANT NOTICE TO HARBOR WATCHMEN</div>
<div class="notice">
THE HARBOR BELL WILL RING AT<br>
<input id="symbolInput" value="9" maxlength="1" aria-label="Correction symbol" inputmode="text">
O’CLOCK.
</div>
<p class="small-note">The original proof reads <strong>8</strong>. Change only the highlighted symbol.</p>
</div>
<div id="draftStatus" class="status-note">Uncorrected draft. Enter a symbol and apply it before printing.</div>
<div class="button-row">
<button id="applyDraft" type="button" style="flex:1">Correct draft</button>
<button id="printBatch" type="button" class="primary">Print four-copy batch</button>
</div>
<div class="rule"></div>
<p class="eyebrow">Separate delays</p>
<div class="delay">
<label class="delay-label" for="productionDelay">
<span>■ Press / production delay</span>
<output id="productionValue">3.0 s</output>
</label>
<input id="productionDelay" type="range" min="1" max="8" step="0.5" value="3">
<p class="small-note">Time at the press before the batch is ready for dispatch.</p>
</div>
<div class="delay">
<label class="delay-label" for="transportDelay">
<span>■ Courier / transport delay</span>
<output id="transportValue">2.5 s</output>
</label>
<input id="transportDelay" type="range" min="0" max="10" step="0.5" value="2.5">
<p class="small-note">Waiting time after production, before the courier leaves.</p>
</div>
<div class="rule"></div>
<div class="legend">
<div class="legend-row"><i class="swatch"></i> Production stage</div>
<div class="legend-row"><i class="swatch transport"></i> Transport wait</div>
<div class="legend-row"><i class="swatch route"></i> Route travel</div>
<div class="legend-row"><i class="swatch corrected"></i> Copy contains the correction</div>
<div class="legend-row"><i class="swatch original"></i> Original printed copy</div>
</div>
</aside>
<aside class="panel tracking">
<p class="eyebrow">Copy registry</p>
<h2>Which copies changed?</h2>
<div class="stats">
<div class="stat"><strong id="batchCount">0</strong><span>Batches</span></div>
<div class="stat"><strong id="copyCount">0</strong><span>Copies</span></div>
<div class="stat"><strong id="correctedCount">0</strong><span>Corrected</span></div>
</div>
<div id="batchList" class="batch-list">
<div class="empty-state">No batches yet. Print a proof to begin.</div>
</div>
<div class="event-log">
<p class="eyebrow">Dispatch record</p>
<div id="eventLog"></div>
</div>
</aside>
<section class="panel timeline">
<div class="timeline-head">
<p class="eyebrow">Production timeline</p>
<div class="timeline-legend">
<span>Production</span>
<span class="transport">Transport wait</span>
<span class="route">Route travel</span>
</div>
</div>
<div id="timelineRows">
<div class="empty-state">The timeline begins when a batch enters the press.</div>
</div>
</section>
<div class="camera-help">DRAG TO ORBIT · SHIFT-DRAG TO PAN · SCROLL TO ZOOM · CLICK A SHEET TO INSPECT</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State
// -------------------------------------------------------------------------
const ORIGINAL_SYMBOL = "8";
const COPIES_PER_BATCH = 4;
const ROUTE_DURATION = 4.5;
const draft = {
symbol: ORIGINAL_SYMBOL,
changed: false
};
let batches = [];
let batchSerial = 0;
let events = [];
let selectedSheet = null;
let toastTimer = 0;
const appStart = performance.now();
let simTime = 0;
let lastUiUpdate = 0;
const $ = selector => document.querySelector(selector);
const symbolInput = $("#symbolInput");
const draftStatus = $("#draftStatus");
const batchList = $("#batchList");
const eventLog = $("#eventLog");
const timelineRows = $("#timelineRows");
function escapeHtml(value) {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function cleanSymbol() {
const chars = Array.from(symbolInput.value.trim());
symbolInput.value = chars[0] || ORIGINAL_SYMBOL;
}
function toast(message) {
const el = $("#toast");
el.textContent = message;
el.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => el.classList.remove("show"), 2800);
}
function addEvent(type, message) {
events.unshift({ time: simTime, type, message });
events = events.slice(0, 30);
}
function stageFor(batch, time = simTime) {
if (time < batch.productionEnd) return "production";
if (time < batch.transitAt) return "waiting";
if (time < batch.deliveredAt) return "transit";
return "delivered";
}
function stageProgress(batch, time = simTime) {
const stage = stageFor(batch, time);
if (stage === "production") {
return (time - batch.startedAt) / batch.productionDuration;
}
if (stage === "waiting") {
return (time - batch.productionEnd) / Math.max(1, batch.transportDuration);
}
if (stage === "transit") {
return (time - batch.transitAt) / ROUTE_DURATION;
}
return 1;
}
function stageLabel(stage) {
return {
production: "At press",
waiting: "Awaiting courier",
transit: "In transit",
delivered: "Delivered"
}[stage];
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const canvas = $("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfc3a8);
scene.fog = new THREE.Fog(0xcfc3a8, 31, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0.8, 1.0, 0.7),
yaw: 0.76,
pitch: 0.62,
radius: 29
};
function resetCamera() {
cameraState.target.set(0.8, 1.0, 0.7);
cameraState.yaw = 0.76;
cameraState.pitch = 0.62;
cameraState.radius = 29;
}
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + radius * Math.cos(pitch) * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
const hemi = new THREE.HemisphereLight(0xfff3d2, 0x6d7663, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4ae, 3.3);
sun.position.set(-12, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d2df, 0.7);
fill.position.set(12, 8, -10);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true,
...options
});
}
const mats = {
ground: material(0xb9aa89),
workshopFloor: material(0xc8b995),
road: material(0x77766d),
roadEdge: material(0xa99b7e),
wood: material(0x765039),
woodLight: material(0x9a7048),
woodDark: material(0x51392b),
metal: material(0x545650, { metalness: 0.35, roughness: 0.58 }),
ink: material(0x3d4440),
paper: material(0xe7d9b9),
paperEdge: material(0xcbb98f),
green: material(0x5d7954),
red: material(0xa55345),
blue: material(0x557b95),
gold: material(0xc49746),
black: material(0x2f302b)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function labelSprite(text, options = {}) {
const c = document.createElement("canvas");
c.width = 640;
c.height = 150;
const ctx = c.getContext("2d");
ctx.fillStyle = options.background || "rgba(48,41,34,.90)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = options.border || "#d4bd83";
ctx.lineWidth = 7;
ctx.strokeRect(9, 9, c.width - 18, c.height - 18);
ctx.fillStyle = options.color || "#f5e9cc";
ctx.font = `700 ${options.fontSize || 45}px Georgia`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest !== false,
depthWrite: false
}));
const width = options.width || 4.2;
sprite.scale.set(width, width * 150 / 640, 1);
return sprite;
}
// Ground and district plan.
box(32, 0.3, 19, mats.ground, 0, -0.2, 0);
box(10.5, 0.035, 10.8, mats.workshopFloor, -6.5, 0.0, -0.4);
box(12.4, 0.045, 1.85, mats.road, 5.6, 0.025, 3.8);
box(1.85, 0.045, 10.5, mats.road, 7.45, 0.028, 0.8);
box(12.7, 0.05, 0.18, mats.roadEdge, 5.6, 0.055, 4.79);
box(12.7, 0.05, 0.18, mats.roadEdge, 5.6, 0.055, 2.81);
box(0.18, 0.05, 10.7, mats.roadEdge, 6.47, 0.055, 0.8);
box(0.18, 0.05, 10.7, mats.roadEdge, 8.43, 0.055, 0.8);
const pressZoneLabel = labelSprite("THE PRINT HOUSE", {
width: 4.7,
fontSize: 47,
depthTest: false
});
pressZoneLabel.position.set(-7.4, 5.0, -1.1);
scene.add(pressZoneLabel);
const dispatchLabel = labelSprite("DISPATCH & COURIERS", {
width: 4.6,
fontSize: 43,
background: "rgba(54,72,82,.92)",
depthTest: false
});
dispatchLabel.position.set(0.8, 4.0, 3.0);
scene.add(dispatchLabel);
const districtLabel = labelSprite("HARBOR NEIGHBORHOODS", {
width: 5.6,
fontSize: 42,
background: "rgba(63,82,61,.92)",
depthTest: false
});
districtLabel.position.set(10.4, 4.8, 0.8);
scene.add(districtLabel);
// Printing press.
const press = new THREE.Group();
press.position.set(-8.2, 0, -1.0);
scene.add(press);
box(3.1, 0.35, 2.4, mats.woodDark, 0, 0.2, 0, press);
box(2.8, 0.18, 2.0, mats.wood, 0, 0.48, 0, press);
for (const x of [-1.18, 1.18]) {
for (const z of [-0.78, 0.78]) {
box(0.28, 3.65, 0.28, mats.wood, x, 2.15, z, press);
}
}
box(3.0, 0.36, 0.42, mats.woodDark, 0, 4.05, -0.78, press);
box(3.0, 0.36, 0.42, mats.woodDark, 0, 4.05, 0.78, press);
box(0.42, 0.36, 1.95, mats.woodDark, -1.18, 4.05, 0, press);
box(0.42, 0.36, 1.95, mats.woodDark, 1.18, 4.05, 0, press);
const pressPlaten = box(2.05, 0.25, 1.4, mats.metal, 0, 2.55, 0, press);
box(2.3, 0.18, 1.6, mats.woodLight, 0, 1.85, 0, press);
cylinder(0.13, 0.13, 1.65, 8, mats.metal, 0, 3.35, 0, press);
cylinder(0.28, 0.28, 0.18, 10, mats.gold, 0, 4.16, 0, press);
const pressWheel = new THREE.Mesh(
new THREE.TorusGeometry(0.88, 0.11, 6, 18),
mats.woodDark
);
pressWheel.position.set(1.6, 2.55, 0.15);
pressWheel.castShadow = true;
press.add(pressWheel);
for (let i = 0; i < 6; i++) {
const spoke = box(0.07, 1.55, 0.07, mats.woodDark, 0, 0, 0, pressWheel);
spoke.rotation.z = i * Math.PI / 6;
}
const roller = cylinder(0.26, 0.26, 1.65, 10, mats.ink, 0, 1.2, 0.92, press);
roller.rotation.z = Math.PI / 2;
const pressLampMaterial = material(0xd89031, {
emissive: 0x7a3c08,
emissiveIntensity: 0.8
});
const pressLamp = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 8, 6),
pressLampMaterial
);
pressLamp.position.set(-1.25, 4.47, 0);
press.add(pressLamp);
function addTable(x, z, width = 3, depth = 2) {
box(width, 0.18, depth, mats.woodLight, x, 1.02, z);
for (const dx of [-width / 2 + 0.2, width / 2 - 0.2]) {
for (const dz of [-depth / 2 + 0.2, depth / 2 - 0.2]) {
box(0.16, 0.95, 0.16, mats.woodDark, x + dx, 0.5, z);
}
}
}
addTable(-4.3, 0.75, 2.7, 1.9);
addTable(1.2, 3.0, 2.3, 1.9);
// Paper bundles and ink supplies.
for (let i = 0; i < 7; i++) {
box(1.25, 0.045, 1.65, mats.paper, -4.6, 1.16 + i * 0.045, 0.65);
}
cylinder(0.24, 0.28, 0.42, 8, mats.ink, -5.2, 1.33, 0.05);
cylinder(0.19, 0.22, 0.36, 8, mats.red, -4.6, 1.29, 0.02);
// Houses.
function createHouse(x, z, title, wallColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(3.4, 0.18, 2.8, mats.roadEdge, 0, 0.09, 0, group);
const walls = material(wallColor);
box(2.65, 2.0, 2.25, walls, 0, 1.08, 0, group);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.18, 1.42, 4),
material(0x795744)
);
roof.position.y = 2.76;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.87;
roof.castShadow = true;
group.add(roof);
box(0.66, 1.35, 0.08, mats.woodDark, 0, 0.76, 1.16, group);
box(0.5, 0.52, 0.06, mats.blue, -0.78, 1.35, 1.16, group);
box(0.5, 0.52, 0.06, mats.blue, 0.78, 1.35, 1.16, group);
box(0.34, 0.7, 0.34, mats.red, 0.85, 2.76, -0.35, group);
box(1.65, 0.16, 0.72, mats.woodLight, 0, 0.19, 1.35, group);
const sign = labelSprite(title, {
width: 2.35,
fontSize: 38,
background: "rgba(67,54,39,.9)"
});
sign.position.set(0, 3.78, 0);
group.add(sign);
}
createHouse(10.7, -3.5, "NORTH QUAY", 0xcbb889);
createHouse(10.7, 0.9, "MARKET ROW", 0xb7c0a0);
createHouse(10.7, 5.2, "OLD HARBOR", 0xd0b49b);
// Low-poly trees.
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.13, 0.18, 1.4, 6, mats.woodDark, 0, 0.7, 0, group);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.82, 0),
mats.green
);
crown.position.y = 1.85;
crown.scale.set(0.9, 1.18, 0.9);
crown.castShadow = true;
group.add(crown);
}
createTree(13.6, -5.7, 1.05);
createTree(13.2, 7.0, 0.95);
createTree(-12.2, 6.6, 1.1);
createTree(4.7, -6.2, 0.8);
// People.
function createPerson(x, z, shirtColor, facing = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = facing;
scene.add(group);
const shirt = material(shirtColor);
cylinder(0.16, 0.22, 0.66, 6, shirt, 0, 1.15, 0, group);
cylinder(0.08, 0.09, 0.62, 6, mats.woodDark, -0.11, 0.43, 0, group);
cylinder(0.08, 0.09, 0.62, 6, mats.woodDark, 0.11, 0.43, 0, group);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.22, 0),
material(0xc79770)
);
head.position.y = 1.68;
head.castShadow = true;
group.add(head);
cylinder(0.22, 0.25, 0.14, 8, mats.woodDark, 0, 1.84, 0, group);
}
createPerson(-6.25, 1.8, 0x8a5f49, -0.8);
createPerson(3.0, 2.1, 0x4f7188, 1.4);
// Cart templates.
function createCart() {
const group = new THREE.Group();
group.visible = false;
scene.add(group);
box(1.18, 0.16, 1.45, mats.woodLight, 0, 0.78, 0, group);
box(0.08, 0.48, 1.45, mats.woodDark, -0.57, 1.03, 0, group);
box(0.08, 0.48, 1.45, mats.woodDark, 0.57, 1.03, 0, group);
box(1.18, 0.48, 0.08, mats.woodDark, 0, 1.03, -0.69, group);
box(1.18, 0.12, 0.08, mats.woodDark, 0, 1.15, 0.69, group);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.46, 0.46]) {
const wheel = cylinder(0.25, 0.25, 0.1, 10, mats.woodDark, x, 0.34, z, group);
wheel.rotation.x = Math.PI / 2;
}
}
box(0.08, 0.08, 1.2, mats.woodDark, -0.38, 1.35, 1.05, group);
box(0.08, 0.08, 1.2, mats.woodDark, 0.38, 1.35, 1.05, group);
box(0.85, 0.08, 0.08, mats.woodDark, 0, 1.35, 1.6, group);
return group;
}
// Notice sheet textures.
function noticeTexture(copy, batch) {
const c = document.createElement("canvas");
c.width = 384;
c.height = 512;
const ctx = c.getContext("2d");
ctx.fillStyle = "#eee0bc";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "#5f4d37";
ctx.lineWidth = 4;
ctx.strokeRect(16, 16, c.width - 32, c.height - 32);
ctx.lineWidth = 1;
ctx.strokeRect(25, 25, c.width - 50, c.height - 50);
ctx.fillStyle = "#3d3328";
ctx.textAlign = "center";
ctx.font = "bold 28px Georgia";
ctx.fillText("THE MORNING LEDGER", 192, 61);
ctx.fillRect(41, 73, 302, 3);
ctx.font = "11px monospace";
ctx.fillText("HARBOR EDITION • VOL. XII • NO. 44", 192, 96);
ctx.fillText("IMPORTANT NOTICE TO HARBOR WATCHMEN", 192, 121);
ctx.fillStyle = "#4b4032";
ctx.font = "bold 22px Georgia";
ctx.fillText("THE HARBOR BELL", 192, 174);
ctx.fillText("WILL RING AT", 192, 207);
ctx.fillStyle = copy.correction?.mode === "errata" ? "#6a4f3e" : "#2f2923";
ctx.font = "bold 74px Georgia";
ctx.fillText(copy.printedSymbol, 192, 291);
ctx.font = "24px Georgia";
ctx.fillText("O’CLOCK.", 192, 332);
ctx.strokeStyle = "#79664c";
ctx.beginPath();
ctx.moveTo(49, 363);
ctx.lineTo(335, 363);
ctx.stroke();
ctx.fillStyle = "#5c5142";
ctx.font = "13px Georgia";
ctx.fillText("Attend with your lantern and keep the", 192, 396);
ctx.fillText("western stair clear for the night watch.", 192, 418);
if (copy.correction?.mode === "errata") {
ctx.save();
ctx.translate(274, 322);
ctx.rotate(-0.12);
ctx.fillStyle = "#f7efcf";
ctx.strokeStyle = "#a55345";
ctx.lineWidth = 4;
ctx.fillRect(-51, -50, 102, 100);
ctx.strokeRect(-51, -50, 102, 100);
ctx.fillStyle = "#a55345";
ctx.textAlign = "center";
ctx.font = "bold 13px monospace";
ctx.fillText("CORRECT", 0, -29);
ctx.font = "bold 50px Georgia";
ctx.fillText(copy.correction.symbol, 0, 22);
ctx.font = "10px monospace";
ctx.fillText("ERRATA SLIP", 0, 40);
ctx.restore();
}
if (copy.correction?.mode === "pre-print") {
ctx.fillStyle = "#5d7954";
ctx.fillRect(42, 438, 300, 24);
ctx.fillStyle = "#f4ead1";
ctx.font = "bold 11px monospace";
ctx.fillText("CORRECTED BEFORE PRESS", 192, 454);
}
ctx.fillStyle = "#675b4a";
ctx.font = "11px monospace";
ctx.fillText(`${copy.id} • COPY ${copy.number}`, 192, 486);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const clickableSheets = [];
function createSheetVisual(copy, batch) {
const group = new THREE.Group();
group.visible = false;
scene.add(group);
box(1.29, 0.035, 1.72, mats.paperEdge, 0, 0, 0, group);
const texture = noticeTexture(copy, batch);
const sheetMaterial = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.95,
side: THREE.DoubleSide
});
const top = new THREE.Mesh(new THREE.PlaneGeometry(1.25, 1.67), sheetMaterial);
top.rotation.x = -Math.PI / 2;
top.position.y = 0.022;
top.receiveShadow = true;
top.userData.copyId = copy.id;
group.add(top);
clickableSheets.push(top);
const marker = box(
0.15, 0.028, 0.18,
material(0x769363),
0.54, 0.045, -0.75,
group
);
marker.visible = Boolean(copy.correction);
const visual = { group, top, material: sheetMaterial, marker };
copy.visual = visual;
return visual;
}
function refreshSheetTexture(copy) {
if (!copy.visual) return;
const oldTexture = copy.visual.material.map;
copy.visual.material.map = noticeTexture(copy, copy.batch);
copy.visual.material.needsUpdate = true;
copy.visual.marker.visible = Boolean(copy.correction);
if (oldTexture) oldTexture.dispose();
}
// Batch creation and correction.
function printBatch() {
const number = ++batchSerial;
const productionDuration = Number($("#productionDelay").value) * 1000;
const transportDuration = Number($("#transportDelay").value) * 1000;
const destinations = [-3.5, 0.9, 5.2];
const destination = destinations[(number - 1) % destinations.length];
const batch = {
id: `B${String(number).padStart(2, "0")}`,
number,
printedSymbol: draft.symbol,
correction: draft.symbol !== ORIGINAL_SYMBOL
? { symbol: draft.symbol, mode: "pre-print" }
: null,
startedAt: simTime,
productionDuration,
productionEnd: simTime + productionDuration,
transportDuration,
transitAt: simTime + productionDuration + transportDuration,
deliveredAt: simTime + productionDuration + transportDuration + ROUTE_DURATION * 1000,
destination,
copies: [],
cart: null,
route: null,
flags: {
productionLogged: false,
dispatchLogged: false,
deliveredLogged: false
}
};
batch.route = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.2, 0, 3.0),
new THREE.Vector3(4.8, 0, 3.8),
new THREE.Vector3(7.4, 0, destination),
new THREE.Vector3(9.35, 0, destination)
], false, "catmullrom", 0.15);
batch.cart = createCart();
for (let i = 0; i < COPIES_PER_BATCH; i++) {
const copy = {
id: `${batch.id}-C${String(i + 1).padStart(2, "0")}`,
number: i + 1,
batch,
printedSymbol: batch.printedSymbol,
correction: batch.correction ? { ...batch.correction } : null,
visual: null
};
batch.copies.push(copy);
createSheetVisual(copy, batch);
}
batches.push(batch);
addEvent(
"production",
`Batch ${batch.id} entered the press • ${COPIES_PER_BATCH} copies • symbol ${batch.printedSymbol}`
);
if (batch.correction) {
addEvent(
"correction",
`Batch ${batch.id} printed with pre-press correction ${ORIGINAL_SYMBOL} → ${batch.correction.symbol}`
);
}
toast(
`Batch ${batch.id} is at the press. Production delay: ${(productionDuration / 1000).toFixed(1)} seconds.`
);
renderUI();
}
function applyDraftCorrection() {
cleanSymbol();
const value = symbolInput.value;
if (value === draft.symbol) {
toast("That symbol is already in the draft.");
return;
}
draft.symbol = value;
draft.changed = value !== ORIGINAL_SYMBOL;
addEvent(
"correction",
`Draft changed ${ORIGINAL_SYMBOL} → ${value}; this applies only to the next batch`
);
toast(
batches.length
? "Draft corrected. Existing printed copies remain unchanged; the next batch will use the new symbol."
: "Draft corrected. Print a batch now and all four copies will contain the change."
);
renderUI();
}
function correctPrintedBatch(batchId) {
const batch = batches.find(item => item.id === batchId);
if (!batch || batch.correction) return;
cleanSymbol();
const symbol = symbolInput.value;
if (symbol === batch.printedSymbol) {
toast("Choose a symbol different from the one already printed.");
return;
}
batch.correction = { symbol, mode: "errata" };
for (const copy of batch.copies) {
copy.correction = { symbol, mode: "errata" };
refreshSheetTexture(copy);
}
addEvent(
"correction",
`Errata slip added to all ${batch.copies.length} copies of batch ${batch.id}: ${batch.printedSymbol} → ${symbol}`
);
toast(
`Post-print correction applied to batch ${batch.id}. The original ink remains, and a ${symbol} errata slip is attached.`
);
renderUI();
}
// -------------------------------------------------------------------------
// Visual batch animation
// -------------------------------------------------------------------------
function updateBatchVisuals(batch, now) {
const stage = stageFor(batch, now);
const progress = Math.max(0, Math.min(1, stageProgress(batch, now)));
if (stage === "production") {
batch.cart.visible = false;
const visibleCount = Math.max(
1,
Math.ceil(progress * batch.copies.length)
);
batch.copies.forEach((copy, index) => {
copy.visual.group.visible = index < visibleCount;
copy.visual.group.position.set(
-4.6 + (index % 2) * 0.07,
1.18 + index * 0.048,
0.66 + Math.floor(index / 2) * 0.06
);
copy.visual.group.rotation.y = (index - 1.5) * 0.012;
});
} else if (stage === "waiting") {
batch.cart.visible = false;
batch.copies.forEach((copy, index) => {
copy.visual.group.visible = true;
copy.visual.group.position.set(
0.85 + (index % 2) * 0.06,
1.18 + index * 0.048,
2.76 + Math.floor(index / 2) * 0.06
);
copy.visual.group.rotation.y = (index - 1.5) * 0.015;
});
} else if (stage === "transit") {
batch.cart.visible = true;
const point = batch.route.getPointAt(progress);
const tangent = batch.route.getTangentAt(Math.min(0.999, progress));
batch.cart.position.copy(point);
batch.cart.rotation.y = Math.atan2(tangent.x, tangent.z);
batch.copies.forEach((copy, index) => {
copy.visual.group.visible = true;
copy.visual.group.position.set(
point.x + ((index % 2) - 0.5) * 0.36,
0.98 + Math.floor(index / 2) * 0.052,
point.z + (Math.floor(index / 2) - 0.5) * 0.36
);
copy.visual.group.rotation.y = batch.cart.rotation.y;
});
} else {
batch.cart.visible = false;
batch.copies.forEach((copy, index) => {
copy.visual.group.visible = true;
copy.visual.group.position.set(
9.38 + (index % 2) * 0.08,
0.34 + index * 0.048,
batch.destination + (Math.floor(index / 2) - 0.5) * 0.15
);
copy.visual.group.rotation.y = (index - 1.5) * 0.02;
});
}
}
function updateSimulation() {
for (const batch of batches) {
const stage = stageFor(batch, simTime);
if (simTime >= batch.productionEnd && !batch.flags.productionLogged) {
batch.flags.productionLogged = true;
addEvent(
"production",
`Batch ${batch.id} production complete after ${(batch.productionDuration / 1000).toFixed(1)} s`
);
}
if (simTime >= batch.transitAt && !batch.flags.dispatchLogged) {
batch.flags.dispatchLogged = true;
addEvent(
"transport",
`Batch ${batch.id} courier departed after ${(batch.transportDuration / 1000).toFixed(1)} s transport wait`
);
}
if (simTime >= batch.deliveredAt && !batch.flags.deliveredLogged) {
batch.flags.deliveredLogged = true;
addEvent(
"delivery",
`Batch ${batch.id} delivered to the neighborhood`
);
}
updateBatchVisuals(batch, simTime);
}
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function renderDraftStatus() {
if (draft.symbol === ORIGINAL_SYMBOL) {
draftStatus.className = "status-note";
draftStatus.textContent = "Uncorrected draft. Enter a symbol and apply it before printing.";
return;
}
draftStatus.className = "status-note good";
draftStatus.textContent = batches.length
? `Draft corrected ${ORIGINAL_SYMBOL} → ${draft.symbol}. This affects the next batch only; existing copies keep their printed symbol.`
: `Pre-press correction ${ORIGINAL_SYMBOL} → ${draft.symbol}. Print now and all four copies will contain the change.`;
}
function renderBatchList() {
if (!batches.length) {
batchList.innerHTML = '<div class="empty-state">No batches yet. Print a proof to begin.</div>';
return;
}
batchList.innerHTML = [...batches].reverse().map(batch => {
const stage = stageFor(batch, simTime);
const correctedCopies = batch.copies.filter(copy => copy.correction).length;
const correctionText = batch.correction
? `${escapeHtml(batch.printedSymbol)} <span class="arrow">→</span> <span class="changed">${escapeHtml(batch.correction.symbol)}</span>`
: `Printed <span class="changed">${escapeHtml(batch.printedSymbol)}</span> · unchanged`;
const correctionMode = batch.correction?.mode === "pre-print"
? "Corrected before press"
: batch.correction?.mode === "errata"
? "Post-print errata"
: "No correction";
const sameSymbol = symbolInput.value === batch.printedSymbol;
const action = batch.correction
? `<div class="applied-label">✓ ${escapeHtml(correctionMode)}</div>`
: `<button class="batch-action" type="button" data-correct="${batch.id}">${
sameSymbol
? "Select a different symbol for errata"
: `Attach ${escapeHtml(symbolInput.value)} errata slip`
}</button>`;
return `
<article class="batch-card" data-batch-card="${batch.id}">
<div class="batch-head">
<div>
<div class="batch-title">Batch ${batch.id}</div>
<div class="batch-subtitle">${COPIES_PER_BATCH} copies · ${escapeHtml(correctionMode)}</div>
</div>
<span class="status-pill ${stage}">${stageLabel(stage)}</span>
</div>
<div class="stage-strip">
<div class="stage ${stage === "production" ? "active" : stage !== "production" ? "done" : ""}">Production</div>
<div class="stage transport ${stage === "waiting" ? "active" : stage === "transit" || stage === "delivered" ? "done" : ""}">Transport wait</div>
<div class="stage route ${stage === "transit" ? "active" : stage === "delivered" ? "done" : ""}">Route travel</div>
</div>
<div class="symbol-change">${correctionText}</div>
<div class="copy-grid">
${batch.copies.map(copy => `
<span
class="copy-chip ${copy.correction ? "corrected" : ""}"
data-copy-id="${copy.id}"
title="${copy.correction
? `${copy.id}: corrected to ${copy.correction.symbol} via ${copy.correction.mode === "errata" ? "errata slip" : "pre-press correction"}`
: `${copy.id}: original printed symbol ${copy.printedSymbol}`}"
>${copy.id}${copy.correction ? " ✓" : ""}</span>
`).join("")}
</div>
<div class="batch-subtitle">${correctedCopies}/${COPIES_PER_BATCH} copies contain the change</div>
${action}
</article>
`;
}).join("");
}
function renderEventLog() {
if (!events.length) {
eventLog.innerHTML = '<div class="empty-state">Events will appear here.</div>';
return;
}
eventLog.innerHTML = events.slice(0, 12).map(event => `
<div class="event ${event.type}">
<time>+${event.time.toFixed(1)}s</time>
<span>${escapeHtml(event.message)}</span>
</div>
`).join("");
}
function renderTimeline() {
if (!batches.length) {
timelineRows.innerHTML = '<div class="empty-state">The timeline begins when a batch enters the press.</div>';
return;
}
const end = Math.max(22, simTime + 7);
const start = Math.max(0, end - 29);
const span = end - start;
function segmentStyle(from, to) {
const clippedStart = Math.max(from, start);
const clippedEnd = Math.min(to, end);
if (clippedEnd <= clippedStart) return null;
return `left:${((clippedStart - start) / span) * 100}%;width:${((clippedEnd - clippedStart) / span) * 100}%`;
}
timelineRows.innerHTML = batches.map(batch => {
const prod = segmentStyle(batch.startedAt, batch.productionEnd);
const wait = segmentStyle(batch.productionEnd, batch.transitAt);
const route = segmentStyle(batch.transitAt, batch.deliveredAt);
const playhead = simTime >= start && simTime <= end
? `<i class="playhead" style="left:${((simTime - start) / span) * 100}%"></i>`
: "";
return `
<div class="timeline-row">
<div class="timeline-label">Batch ${batch.id}</div>
<div class="track">
${prod ? `<i class="segment production" style="${prod}"></i>` : ""}
${wait ? `<i class="segment transport" style="${wait}"></i>` : ""}
${route ? `<i class="segment route" style="${route}"></i>` : ""}
${playhead}
</div>
<div class="timeline-time">${stageLabel(stageFor(batch, simTime))}</div>
</div>
`;
}).join("");
}
function renderUI() {
const allCopies = batches.flatMap(batch => batch.copies);
const corrected = allCopies.filter(copy => copy.correction).length;
$("#batchCount").textContent = batches.length;
$("#copyCount").textContent = allCopies.length;
$("#correctedCount").textContent = corrected;
renderDraftStatus();
renderBatchList();
renderEventLog();
renderTimeline();
}
// -------------------------------------------------------------------------
// Input and custom camera controls
// -------------------------------------------------------------------------
$("#applyDraft").addEventListener("click", applyDraftCorrection);
$("#printBatch").addEventListener("click", printBatch);
$("#resetCamera").addEventListener("click", resetCamera);
$("#productionDelay").addEventListener("input", event => {
$("#productionValue").textContent = `${Number(event.target.value).toFixed(1)} s`;
});
$("#transportDelay").addEventListener("input", event => {
$("#transportValue").textContent = `${Number(event.target.value).toFixed(1)} s`;
});
symbolInput.addEventListener("blur", cleanSymbol);
symbolInput.addEventListener("keydown", event => {
if (event.key === "Enter") {
cleanSymbol();
applyDraftCorrection();
}
});
document.addEventListener("click", event => {
const correctButton = event.target.closest("[data-correct]");
if (correctButton) {
correctPrintedBatch(correctButton.dataset.correct);
return;
}
const chip = event.target.closest("[data-copy-id]");
if (chip) {
const copy = allCopiesForLookup().find(item => item.id === chip.dataset.copyId);
if (!copy) return;
const correction = copy.correction
? `contains correction ${copy.correction.symbol} (${copy.correction.mode === "errata" ? "errata slip" : "pre-press"})`
: `retains original symbol ${copy.printedSymbol}`;
toast(`${copy.id}: ${correction}.`);
}
});
function allCopiesForLookup() {
return batches.flatMap(batch => batch.copies);
}
let dragging = false;
let dragButton = 0;
let pointerX = 0;
let pointerY = 0;
let movedDistance = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
pointerX = event.clientX;
pointerY = event.clientY;
movedDistance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
movedDistance += Math.abs(dx) + Math.abs(dy);
if (event.shiftKey || dragButton === 2) {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
Math.sin(cameraState.yaw),
0,
Math.cos(cameraState.yaw)
);
const scale = cameraState.radius * 0.0015;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -10, 12);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -8, 9);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.25,
1.22
);
}
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (movedDistance < 6) inspectSheet(event);
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
13,
43
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function inspectSheet(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickableSheets, false);
for (const hit of hits) {
const copy = allCopiesForLookup().find(item => item.id === hit.object.userData.copyId);
if (!copy || !copy.visual.group.visible) continue;
if (selectedSheet) selectedSheet.scale.set(1, 1, 1);
selectedSheet = copy.visual.group;
selectedSheet.scale.set(1.06, 1.06, 1.06);
const correction = copy.correction
? `Correction ${copy.correction.symbol} applied by ${copy.correction.mode === "errata" ? "an errata slip" : "pre-press editing"}.`
: `No correction. Original symbol ${copy.printedSymbol}.`;
toast(`${copy.id}: ${correction}`);
break;
}
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
let previousFrame = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(0.05, (now - previousFrame) / 1000);
previousFrame = now;
simTime = (now - appStart) / 1000;
updateSimulation();
updateCamera();
const pressing = batches.some(batch => stageFor(batch, simTime) === "production");
if (pressing) {
pressWheel.rotation.z -= delta * 1.25;
pressPlaten.position.y = 2.49 + Math.abs(Math.sin(now * 0.009)) * 0.22;
pressLampMaterial.color.set(0xd89031);
pressLampMaterial.emissive.set(0x7a3c08);
} else {
pressPlaten.position.y = 2.53;
pressLampMaterial.color.set(0x66865a);
pressLampMaterial.emissive.set(0x29451f);
}
if (now - lastUiUpdate > 100) {
renderUI();
lastUiUpdate = now;
}
renderer.render(scene, camera);
}
renderUI();
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```