Prompt specification
Build or customize the Three.js 3D scene "Print Shop Order Cost Table" 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: Print Shop Order Cost Table
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/print-shop-order-cost-table-x3138
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows fixed costs, variable costs, and break-even quantities. Show a small print shop with setup plates and paper sheets. Increasing the order count adds paper costs while the declared setup cost stays unchanged. Low-poly.
Working Three.js Starter (print-shop-order-cost-table-x3138):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Inkstock — Print Shop Cost Lab</title>
<style>
:root {
--ink: #193d39;
--ink-soft: #315753;
--orange: #ee8052;
--orange-soft: #f8d6c4;
--teal: #2e8c80;
--teal-soft: #d5e9e4;
--paper: #faf8f1;
--canvas: #e7ece5;
--line: #d7dfd8;
--muted: #71817b;
--danger: #b95748;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: var(--canvas);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
width: 100%;
height: 100dvh;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
}
.topbar {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
background: var(--paper);
border-bottom: 1px solid var(--line);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 4px;
padding: 5px;
background: var(--ink);
border-radius: 10px;
transform: rotate(-3deg);
}
.brand-mark span {
display: block;
border-radius: 2px;
background: var(--paper);
}
.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
background: var(--orange);
}
.eyebrow {
margin: 0 0 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 19px;
line-height: 1;
letter-spacing: -0.035em;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
color: var(--ink-soft);
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(46, 140, 128, 0.12);
}
main {
min-height: 0;
display: grid;
grid-template-columns: 365px minmax(0, 1fr);
}
.panel {
min-height: 0;
overflow-y: auto;
padding: 25px 24px 28px;
background: var(--paper);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #bcc9c1 transparent;
}
.intro h2 {
margin: 0 0 10px;
max-width: 280px;
font-size: 31px;
line-height: 1.02;
letter-spacing: -0.055em;
}
.intro p:last-child {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 25px 0 13px;
padding-top: 19px;
border-top: 1px solid var(--line);
}
.section-title h3 {
margin: 0;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.tiny-badge {
padding: 5px 7px;
color: #a65535;
background: var(--orange-soft);
border-radius: 6px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.control {
margin-bottom: 15px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.control label {
color: var(--ink-soft);
font-size: 12px;
font-weight: 650;
}
.control output {
min-width: 65px;
padding: 4px 8px;
color: var(--ink);
background: #edf0ea;
border-radius: 6px;
font-size: 11px;
font-weight: 800;
text-align: center;
font-variant-numeric: tabular-nums;
}
.control:first-of-type output {
color: #a65535;
background: var(--orange-soft);
}
input[type="range"] {
--pct: 50%;
width: 100%;
height: 5px;
margin: 6px 0 0;
border: 0;
border-radius: 99px;
appearance: none;
background:
linear-gradient(
to right,
var(--orange) 0,
var(--orange) var(--pct),
#dfe5de var(--pct),
#dfe5de 100%
);
cursor: pointer;
}
input[type="range"]:focus-visible {
outline: 3px solid rgba(46, 140, 128, 0.25);
outline-offset: 5px;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 1px 5px rgba(25, 61, 57, 0.26);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 1px 5px rgba(25, 61, 57, 0.26);
}
.kpi-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.kpi {
min-height: 90px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fffef9;
}
.kpi:first-child {
background: var(--ink);
color: var(--paper);
border-color: var(--ink);
}
.kpi:nth-child(2) {
background: var(--teal-soft);
border-color: #c9dfd9;
}
.kpi:last-child {
grid-column: 1 / -1;
min-height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
background: var(--orange-soft);
border-color: #efd0bc;
}
.kpi-label {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.kpi:first-child .kpi-label {
color: #b8ccc6;
}
.kpi-value {
font-size: 25px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.055em;
font-variant-numeric: tabular-nums;
}
.kpi:last-child .kpi-value {
color: #a65535;
font-size: 29px;
}
.kpi-unit {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.kpi:first-child .kpi-unit {
color: #b8ccc6;
}
.chart-card {
padding: 13px 12px 9px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fffef9;
}
.chart-legend {
display: flex;
align-items: center;
gap: 13px;
margin: 1px 0 5px 38px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.chart-legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend-line {
width: 13px;
height: 3px;
border-radius: 3px;
background: var(--ink);
}
.legend-line.revenue {
background: var(--orange);
}
#costChart {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.financial-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 11px;
}
.financial-item {
padding: 10px 7px;
border-radius: 9px;
background: #f0f2ed;
text-align: center;
}
.financial-item span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.financial-item strong {
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.status-box {
display: flex;
align-items: center;
gap: 10px;
margin-top: 12px;
padding: 11px 12px;
border-radius: 10px;
color: var(--ink-soft);
background: var(--teal-soft);
font-size: 11px;
font-weight: 700;
line-height: 1.35;
}
.status-box::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
}
.status-box.loss {
color: #8b493d;
background: #f6ded7;
}
.status-box.loss::before {
background: var(--danger);
}
.model-note {
margin: 17px 0 0;
padding-left: 11px;
border-left: 3px solid var(--orange);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 32%, #f3f5ef 0, #e6ebe4 62%, #dce3dc 100%);
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.scene-copy {
position: absolute;
top: 24px;
left: 27px;
z-index: 3;
pointer-events: none;
}
.scene-copy .eyebrow {
color: var(--ink-soft);
}
.scene-copy h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.045em;
}
.scene-copy p {
margin: 6px 0 0;
color: var(--muted);
font-size: 11px;
}
.scene-legend {
position: absolute;
left: 27px;
bottom: 24px;
z-index: 3;
display: flex;
flex-wrap: wrap;
gap: 7px;
pointer-events: none;
}
.scene-chip {
display: flex;
align-items: center;
gap: 6px;
padding: 7px 9px;
border: 1px solid rgba(25, 61, 57, 0.12);
border-radius: 7px;
background: rgba(250, 248, 241, 0.82);
backdrop-filter: blur(8px);
color: var(--ink-soft);
font-size: 9px;
font-weight: 800;
}
.scene-chip i {
width: 7px;
height: 7px;
display: block;
border-radius: 2px;
background: var(--ink);
}
.scene-chip.paper i {
background: var(--teal);
}
.scene-chip.setup i {
background: var(--orange);
}
.camera-help {
position: absolute;
right: 25px;
bottom: 25px;
z-index: 4;
display: flex;
align-items: center;
gap: 10px;
}
.camera-help span {
padding: 7px 10px;
border-radius: 7px;
color: var(--ink-soft);
background: rgba(250, 248, 241, 0.78);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 700;
}
#resetCamera {
width: 36px;
height: 36px;
border: 1px solid rgba(25, 61, 57, 0.14);
border-radius: 9px;
color: var(--ink);
background: rgba(250, 248, 241, 0.9);
cursor: pointer;
font-size: 18px;
box-shadow: 0 4px 14px rgba(25, 61, 57, 0.08);
}
#resetCamera:hover {
background: #fffef9;
transform: rotate(-10deg);
}
.scene-label {
position: absolute;
z-index: 2;
min-width: 112px;
padding: 8px 10px;
border: 1px solid rgba(25, 61, 57, 0.13);
border-radius: 9px;
background: rgba(250, 248, 241, 0.91);
box-shadow: 0 7px 20px rgba(25, 61, 57, 0.11);
backdrop-filter: blur(8px);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.scene-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(25, 61, 57, 0.35);
}
.scene-label .label-top {
margin-bottom: 3px;
color: var(--muted);
font-size: 7px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
font-size: 15px;
line-height: 1.05;
letter-spacing: -0.03em;
font-variant-numeric: tabular-nums;
}
.scene-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
}
.scene-label.setup {
border-color: rgba(238, 128, 82, 0.38);
}
.scene-label.setup strong {
color: #b15c37;
}
.scene-label.paper {
border-color: rgba(46, 140, 128, 0.38);
}
.scene-label.paper strong {
color: var(--teal);
}
.scene-label.break-even {
color: var(--paper);
background: rgba(25, 61, 57, 0.91);
border-color: rgba(25, 61, 57, 0.4);
}
.scene-label.break-even .label-top,
.scene-label.break-even small {
color: #bfd1cc;
}
.scene-label.break-even strong {
color: #fff8e7;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100dvh;
}
.topbar {
height: 68px;
padding: 0 17px;
}
.top-status {
display: none;
}
main {
display: flex;
flex-direction: column;
}
#stage {
order: 0;
height: 58dvh;
min-height: 430px;
}
.panel {
order: 1;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.intro h2 {
max-width: none;
}
.scene-copy {
top: 18px;
left: 18px;
}
.scene-copy h2 {
font-size: 21px;
}
.scene-legend {
left: 18px;
bottom: 18px;
}
.camera-help span {
display: none;
}
.camera-help {
right: 16px;
bottom: 16px;
}
}
@media (max-width: 520px) {
.panel {
padding: 22px 17px 26px;
}
.intro h2 {
font-size: 27px;
}
.kpi-grid {
grid-template-columns: 1fr 1fr;
}
.scene-chip:nth-child(3) {
display: none;
}
.scene-label {
min-width: 96px;
padding: 6px 8px;
}
.scene-label strong {
font-size: 12px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<p class="eyebrow">Production economics</p>
<h1>INKSTOCK / COST LAB</h1>
</div>
</div>
<div class="top-status">
<span class="live-dot"></span>
Live batch model
</div>
</header>
<main>
<aside class="panel">
<section class="intro">
<p class="eyebrow">Small print shop</p>
<h2>One batch.<br />Two cost behaviors.</h2>
<p>
Paper spending rises with every order. The declared setup charge stays
flat for the batch.
</p>
</section>
<div class="section-title">
<h3>Batch assumptions</h3>
<span class="tiny-badge">Setup stays flat</span>
</div>
<section class="controls" aria-label="Cost assumptions">
<div class="control">
<div class="control-head">
<label for="orders">Orders in batch</label>
<output id="ordersOut" for="orders">48</output>
</div>
<input id="orders" type="range" min="0" max="150" step="1" value="48" />
</div>
<div class="control">
<div class="control-head">
<label for="price">Selling price / order</label>
<output id="priceOut" for="price">$18.00</output>
</div>
<input id="price" type="range" min="5" max="40" step="0.25" value="18" />
</div>
<div class="control">
<div class="control-head">
<label for="paper">Paper & ink / order</label>
<output id="paperOut" for="paper">$2.40</output>
</div>
<input id="paper" type="range" min="0.5" max="8" step="0.1" value="2.4" />
</div>
<div class="control">
<div class="control-head">
<label for="setup">Declared setup charge</label>
<output id="setupOut" for="setup">$120</output>
</div>
<input id="setup" type="range" min="0" max="400" step="5" value="120" />
</div>
<div class="control">
<div class="control-head">
<label for="overhead">Monthly shop overhead</label>
<output id="overheadOut" for="overhead">$450</output>
</div>
<input id="overhead" type="range" min="0" max="1000" step="25" value="450" />
</div>
</section>
<div class="section-title">
<h3>Cost snapshot</h3>
</div>
<section class="kpi-grid" aria-label="Calculated costs">
<article class="kpi">
<div class="kpi-label">Fixed cost / batch</div>
<div class="kpi-value" id="fixedValue">$570</div>
<div class="kpi-unit">Overhead + flat setup</div>
</article>
<article class="kpi">
<div class="kpi-label">Variable cost</div>
<div class="kpi-value" id="variableValue">$115.20</div>
<div class="kpi-unit" id="variableUnit">48 × $2.40</div>
</article>
<article class="kpi">
<div>
<div class="kpi-label">Break-even quantity</div>
<div class="kpi-unit" id="breakEvenUnit">Orders needed to cover fixed cost</div>
</div>
<div class="kpi-value" id="breakEvenValue">37</div>
</article>
</section>
<div class="section-title">
<h3>Cost vs. revenue</h3>
</div>
<section class="chart-card">
<div class="chart-legend">
<span><i class="legend-line"></i> Total cost</span>
<span><i class="legend-line revenue"></i> Revenue</span>
</div>
<svg
id="costChart"
viewBox="0 0 320 170"
role="img"
aria-label="Chart comparing total cost and revenue by order quantity"
></svg>
<div class="financial-row">
<div class="financial-item">
<span>Revenue</span>
<strong id="revenueValue">$864.00</strong>
</div>
<div class="financial-item">
<span>Total cost</span>
<strong id="totalCostValue">$685.20</strong>
</div>
<div class="financial-item">
<span>Net result</span>
<strong id="profitValue">+$178.80</strong>
</div>
</div>
<div class="status-box" id="statusBox">
11 orders above break-even
</div>
</section>
<p class="model-note">
Model: fixed cost = monthly overhead + one flat setup charge.
Variable cost = orders × paper-and-ink cost. Break-even quantity =
ceiling(fixed cost ÷ contribution per order).
</p>
</aside>
<section id="stage" aria-label="Interactive low-poly print shop">
<div class="scene-copy">
<p class="eyebrow">Live workshop view</p>
<h2 id="sceneBatch">48-order batch</h2>
<p>Fixed plates. Variable paper. Same shop.</p>
</div>
<div class="scene-label fixed" id="fixedLabel">
<div class="label-top">Monthly overhead</div>
<strong id="fixedSceneValue">$450</strong>
<small>does not scale</small>
</div>
<div class="scene-label setup" id="setupLabel">
<div class="label-top">Declared setup</div>
<strong id="setupSceneValue">$120</strong>
<small>2 plates · unchanged</small>
</div>
<div class="scene-label paper" id="paperLabel">
<div class="label-top">Variable paper</div>
<strong id="paperSceneValue">$115.20</strong>
<small id="paperSceneUnit">48 sheets</small>
</div>
<div class="scene-label break-even" id="breakEvenLabel">
<div class="label-top">Break-even</div>
<strong id="breakEvenSceneValue">37 orders</strong>
<small id="breakEvenSceneUnit">$666 revenue</small>
</div>
<div class="scene-legend">
<div class="scene-chip"><i></i> Fixed shop costs</div>
<div class="scene-chip paper"><i></i> Per-order materials</div>
<div class="scene-chip setup"><i></i> Flat setup</div>
</div>
<div class="camera-help">
<span>Drag to orbit · scroll to zoom</span>
<button id="resetCamera" type="button" title="Reset camera" aria-label="Reset camera">
↺
</button>
</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// UI and financial model
// ---------------------------------------------------------------------
const elements = {
orders: document.querySelector("#orders"),
price: document.querySelector("#price"),
paper: document.querySelector("#paper"),
setup: document.querySelector("#setup"),
overhead: document.querySelector("#overhead"),
ordersOut: document.querySelector("#ordersOut"),
priceOut: document.querySelector("#priceOut"),
paperOut: document.querySelector("#paperOut"),
setupOut: document.querySelector("#setupOut"),
overheadOut: document.querySelector("#overheadOut"),
fixedValue: document.querySelector("#fixedValue"),
variableValue: document.querySelector("#variableValue"),
variableUnit: document.querySelector("#variableUnit"),
breakEvenValue: document.querySelector("#breakEvenValue"),
breakEvenUnit: document.querySelector("#breakEvenUnit"),
revenueValue: document.querySelector("#revenueValue"),
totalCostValue: document.querySelector("#totalCostValue"),
profitValue: document.querySelector("#profitValue"),
statusBox: document.querySelector("#statusBox"),
chart: document.querySelector("#costChart"),
sceneBatch: document.querySelector("#sceneBatch"),
fixedSceneValue: document.querySelector("#fixedSceneValue"),
setupSceneValue: document.querySelector("#setupSceneValue"),
paperSceneValue: document.querySelector("#paperSceneValue"),
paperSceneUnit: document.querySelector("#paperSceneUnit"),
breakEvenSceneValue: document.querySelector("#breakEvenSceneValue"),
breakEvenSceneUnit: document.querySelector("#breakEvenSceneUnit")
};
const money = (value, decimals = 0) =>
new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: decimals,
maximumFractionDigits: decimals
}).format(value);
const compactMoney = (value) => {
if (value >= 1000) return `$${(value / 1000).toFixed(1)}k`;
return `$${Math.round(value)}`;
};
function updateRangeFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--pct", `${percent}%`);
}
function drawChart(state, fixedCost, breakEven) {
const W = 320;
const H = 170;
const margin = { left: 38, right: 12, top: 12, bottom: 28 };
const plotW = W - margin.left - margin.right;
const plotH = H - margin.top - margin.bottom;
const maxQ = 150;
const maxY =
Math.max(
fixedCost + maxQ * state.paper,
maxQ * state.price,
1
) * 1.08;
const x = (q) => margin.left + (q / maxQ) * plotW;
const y = (v) => margin.top + plotH - (v / maxY) * plotH;
const costPath = Array.from({ length: 51 }, (_, i) => {
const q = (i / 50) * maxQ;
const cost = fixedCost + q * state.paper;
return `${i === 0 ? "M" : "L"}${x(q).toFixed(1)},${y(cost).toFixed(1)}`;
}).join(" ");
const revenuePath = Array.from({ length: 51 }, (_, i) => {
const q = (i / 50) * maxQ;
const revenue = q * state.price;
return `${i === 0 ? "M" : "L"}${x(q).toFixed(1)},${y(revenue).toFixed(1)}`;
}).join(" ");
let grid = "";
for (let i = 0; i <= 3; i++) {
const value = (maxY / 3) * i;
const yy = y(value);
grid += `
<line x1="${margin.left}" y1="${yy}" x2="${W - margin.right}" y2="${yy}"
stroke="#dfe4de" stroke-width="1"/>
<text x="${margin.left - 7}" y="${yy + 3}" text-anchor="end"
fill="#84918b" font-size="8">${compactMoney(value)}</text>
`;
}
let axis = "";
[0, 50, 100, 150].forEach((q) => {
axis += `
<text x="${x(q)}" y="${H - 7}" text-anchor="middle"
fill="#84918b" font-size="8">${q}</text>
`;
});
const currentX = x(state.orders);
const currentCost = fixedCost + state.orders * state.paper;
const currentRevenue = state.orders * state.price;
let breakEvenMarkup = "";
if (breakEven !== null && breakEven <= maxQ) {
const bx = x(breakEven);
breakEvenMarkup = `
<line x1="${bx}" y1="${margin.top}" x2="${bx}" y2="${margin.top + plotH}"
stroke="#2e8c80" stroke-width="1" stroke-dasharray="3 3" opacity="0.7"/>
<circle cx="${bx}" cy="${y(fixedCost + breakEven * state.paper)}"
r="3.5" fill="#2e8c80" stroke="#fffef9" stroke-width="2"/>
`;
}
elements.chart.innerHTML = `
<defs>
<linearGradient id="areaGradient" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#ee8052" stop-opacity="0.14"/>
<stop offset="1" stop-color="#ee8052" stop-opacity="0"/>
</linearGradient>
</defs>
${grid}
<path d="${costPath}" fill="none" stroke="#193d39" stroke-width="2.3"
stroke-linejoin="round" stroke-linecap="round"/>
<path d="${revenuePath}" fill="none" stroke="#ee8052" stroke-width="2.3"
stroke-linejoin="round" stroke-linecap="round"/>
<path d="M${x(0)},${y(0)} L${x(state.orders)},${y(currentRevenue)}
L${x(state.orders)},${y(0)} Z" fill="url(#areaGradient)"/>
${breakEvenMarkup}
<line x1="${currentX}" y1="${margin.top}" x2="${currentX}" y2="${margin.top + plotH}"
stroke="#193d39" stroke-width="1" opacity="0.2"/>
<circle cx="${currentX}" cy="${y(currentCost)}" r="3.5"
fill="#193d39" stroke="#fffef9" stroke-width="2"/>
<circle cx="${currentX}" cy="${y(currentRevenue)}" r="3.5"
fill="#ee8052" stroke="#fffef9" stroke-width="2"/>
${axis}
<text x="${margin.left}" y="${H - 18}" fill="#84918b" font-size="7.5">ORDERS</text>
`;
}
function updateModel() {
const state = {
orders: Number(elements.orders.value),
price: Number(elements.price.value),
paper: Number(elements.paper.value),
setup: Number(elements.setup.value),
overhead: Number(elements.overhead.value)
};
[
elements.orders,
elements.price,
elements.paper,
elements.setup,
elements.overhead
].forEach(updateRangeFill);
const fixedCost = state.overhead + state.setup;
const variableCost = state.orders * state.paper;
const totalCost = fixedCost + variableCost;
const revenue = state.orders * state.price;
const profit = revenue - totalCost;
const contribution = state.price - state.paper;
const breakEven =
contribution > 0 ? Math.ceil(fixedCost / contribution) : null;
elements.ordersOut.value = `${state.orders}`;
elements.priceOut.value = money(state.price, 2);
elements.paperOut.value = money(state.paper, 2);
elements.setupOut.value = money(state.setup);
elements.overheadOut.value = money(state.overhead);
elements.fixedValue.textContent = money(fixedCost);
elements.variableValue.textContent = money(variableCost, 2);
elements.variableUnit.textContent = `${state.orders} × ${money(state.paper, 2)}`;
elements.breakEvenValue.textContent =
breakEven === null ? "—" : `${breakEven}`;
elements.breakEvenUnit.textContent =
breakEven === null
? "Selling price must exceed variable cost"
: "Orders needed to cover fixed cost";
elements.revenueValue.textContent = money(revenue, 2);
elements.totalCostValue.textContent = money(totalCost, 2);
elements.profitValue.textContent = `${profit < 0 ? "−" : "+"}${money(
Math.abs(profit),
2
)}`;
elements.profitValue.style.color =
profit < 0 ? "var(--danger)" : "var(--teal)";
elements.statusBox.classList.toggle("loss", profit < 0);
if (breakEven === null) {
elements.statusBox.textContent =
"No break-even: the selling price must exceed variable cost.";
} else if (state.orders === 0) {
elements.statusBox.textContent = "Ready for a batch — no orders yet.";
} else if (state.orders >= breakEven) {
elements.statusBox.textContent = `${state.orders - breakEven} orders above break-even`;
} else {
elements.statusBox.textContent = `${breakEven - state.orders} orders until break-even`;
}
elements.sceneBatch.textContent = `${state.orders}-order batch`;
elements.fixedSceneValue.textContent = money(state.overhead);
elements.setupSceneValue.textContent = money(state.setup);
elements.paperSceneValue.textContent = money(variableCost, 2);
const shownSheets = Math.min(state.orders, 72);
elements.paperSceneUnit.textContent =
state.orders > 72
? `${shownSheets} shown · ${state.orders} billed`
: `${shownSheets} sheet${state.orders === 1 ? "" : "s"}`;
elements.breakEvenSceneValue.textContent =
breakEven === null ? "No break-even" : `${breakEven} orders`;
elements.breakEvenSceneUnit.textContent =
breakEven === null
? "Check the selling price"
: `${money(breakEven * state.price)} revenue`;
drawChart(state, fixedCost, breakEven);
updateWorkshop(state);
}
[
elements.orders,
elements.price,
elements.paper,
elements.setup,
elements.overhead
].forEach((input) => input.addEventListener("input", updateModel));
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ece5);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive 3D print shop");
stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const orbit = {
radius: 12.8,
theta: 0.77,
phi: 1.03
};
const defaultOrbit = { ...orbit };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.radius = defaultOrbit.radius;
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
updateCamera();
}
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.0045, 0.58, 1.35);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.009,
8.2,
17.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf9fff5, 0x8a7661, 2.5);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff7df, 3.3);
sun.position.set(-4, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbadbd5, 1.25);
fill.position.set(7, 5, -5);
scene.add(fill);
const lampLight = new THREE.PointLight(0xffb56b, 16, 7, 2);
lampLight.position.set(0.2, 3.55, 0.1);
scene.add(lampLight);
// Geometry helpers
function matte(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
floor: matte(0xd9d2bf),
wall: matte(0xcbd8cc),
wallSide: matte(0xd7dfd3),
trim: matte(0x36534e),
teal: matte(0x2e766e),
tealDark: matte(0x204b48),
tealLight: matte(0x58a397),
orange: matte(0xee8052),
orangeDark: matte(0xbd603c),
ink: matte(0x253b3a),
metal: matte(0x80918c, { metalness: 0.35, roughness: 0.6 }),
paper: matte(0xfffaf0),
paperEdge: matte(0xe8dfcd),
wood: matte(0xb9875d),
woodLight: matte(0xd1a777),
coral: matte(0xef6f55),
blue: matte(0x518b91),
yellow: matte(0xe4b84e)
};
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 12,
axis = "y"
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
if (axis === "x") mesh.rotation.z = Math.PI / 2;
if (axis === "z") mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Room
addBox(scene, 11, 0.25, 8, materials.floor, 0, -0.14, 0);
addBox(scene, 11, 4.2, 0.18, materials.wall, 0, 2, -4);
addBox(scene, 0.18, 4.2, 8, materials.wallSide, -5.5, 2, 0);
addBox(scene, 11, 0.16, 0.12, materials.trim, 0, 0.12, -3.88);
addBox(scene, 0.12, 0.16, 8, materials.trim, -5.38, 0.12, 0);
const grid = new THREE.GridHelper(10, 25, 0x71857d, 0x8e9b93);
grid.position.y = 0.005;
grid.scale.z = 0.78;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
// Window on the side wall
addBox(scene, 0.06, 1.8, 2.15, matte(0x9ac5c4), -5.38, 2.55, -1.25);
addBox(scene, 0.09, 0.08, 2.35, materials.paper, -5.31, 2.55, -1.25);
addBox(scene, 0.09, 1.95, 0.08, materials.paper, -5.31, 2.55, -1.25);
addBox(scene, 0.2, 0.12, 2.45, materials.woodLight, -5.27, 1.6, -1.25);
addBox(scene, 0.2, 0.12, 2.45, materials.woodLight, -5.27, 3.5, -1.25);
// Back workbench
addBox(scene, 5.4, 0.18, 1.15, materials.woodLight, 2.35, 1.14, -2.85);
[
[0.1, -3.18],
[4.6, -3.18],
[0.1, -2.52],
[4.6, -2.52]
].forEach(([x, z]) => addBox(scene, 0.15, 1.05, 0.15, materials.wood, x, 0.55, z));
// Ink cans
addCylinder(scene, 0.24, 0.48, materials.ink, 2.0, 1.47, -2.9, 10);
addCylinder(scene, 0.24, 0.48, materials.coral, 2.55, 1.47, -2.9, 10);
addCylinder(scene, 0.24, 0.48, materials.blue, 3.1, 1.47, -2.9, 10);
// Paper ream
addBox(scene, 0.8, 0.52, 0.65, materials.paperEdge, 4.35, 1.49, -2.85);
addBox(scene, 0.72, 0.06, 0.58, materials.paper, 4.35, 1.78, -2.85);
// Shelf
addBox(scene, 2.5, 0.14, 0.65, materials.wood, -3.55, 3.15, -3.6);
addBox(scene, 2.5, 0.14, 0.65, materials.wood, -3.55, 2.15, -3.6);
addBox(scene, 0.12, 1.5, 0.12, materials.trim, -4.65, 2.85, -3.77);
addBox(scene, 0.12, 1.5, 0.12, materials.trim, -2.45, 2.85, -3.77);
const boxColors = [materials.orange, materials.tealLight, materials.yellow];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
addBox(
scene,
0.52,
0.42,
0.42,
boxColors[(row + col) % boxColors.length],
-4.25 + col * 0.67,
2.44 + row * 1,
-3.53
);
}
}
// Main printing press
const press = new THREE.Group();
scene.add(press);
addBox(press, 2.85, 0.42, 1.8, materials.tealDark, 0, 0.28, 0.15);
addBox(press, 2.55, 0.38, 1.55, materials.teal, 0, 0.68, 0.1);
addBox(press, 2.65, 0.28, 1.6, materials.ink, 0, 0.98, 0.1);
[-1.05, 1.05].forEach((x) => {
addBox(press, 0.25, 1.65, 0.38, materials.tealDark, x, 1.83, -0.18);
addBox(press, 0.16, 1.8, 0.95, materials.teal, x, 1.78, 0.18);
});
addBox(press, 2.65, 0.38, 1.55, materials.teal, 0, 2.72, 0.05);
addBox(press, 1.25, 0.15, 0.9, materials.tealLight, 0, 2.96, 0.04);
addCylinder(press, 0.29, 2.25, materials.ink, 0, 2.12, 0.48, 14, "x");
addCylinder(press, 0.25, 2.25, materials.metal, 0, 1.62, 0.48, 14, "x");
addCylinder(press, 0.12, 2.55, materials.orangeDark, 0, 1.88, 0.48, 10, "x");
addBox(press, 1.55, 0.07, 0.74, materials.orange, 0, 1.15, 0.78);
// Two fixed setup plates
[-0.48, 0.48].forEach((x) => {
addBox(press, 0.82, 0.055, 0.58, materials.orange, x, 1.24, 0.82);
addBox(press, 0.12, 0.11, 0.12, materials.ink, x - 0.32, 1.32, 0.62);
addBox(press, 0.12, 0.11, 0.12, materials.ink, x + 0.32, 1.32, 0.62);
});
// Press controls
addBox(press, 0.48, 0.8, 0.38, materials.tealDark, 1.55, 1.45, 0.5);
addBox(press, 0.32, 0.25, 0.06, matte(0x18302f), 1.55, 1.66, 0.71);
addCylinder(press, 0.07, 0.07, materials.coral, 1.43, 1.25, 0.73, 10, "z");
addCylinder(press, 0.07, 0.07, materials.yellow, 1.67, 1.25, 0.73, 10, "z");
// Input table
function addTable(x, z, width, depth, topY = 1.02) {
addBox(scene, width, 0.16, depth, materials.woodLight, x, topY, z);
const legX = width / 2 - 0.16;
const legZ = depth / 2 - 0.16;
[
[x - legX, z - legZ],
[x + legX, z - legZ],
[x - legX, z + legZ],
[x + legX, z + legZ]
].forEach(([lx, lz]) => {
addBox(scene, 0.14, topY - 0.08, 0.14, materials.wood, lx, (topY - 0.08) / 2, lz);
});
}
addTable(-3.0, 0.7, 2.25, 1.65);
// Input paper stack
for (let i = 0; i < 6; i++) {
addBox(
scene,
1.15,
0.025,
0.82,
i % 2 ? materials.paperEdge : materials.paper,
-3.05 + i * 0.018,
1.12 + i * 0.028,
0.62 - i * 0.014
);
}
// Paper bridge into press
addBox(scene, 1.35, 0.025, 0.44, materials.paper, -1.65, 1.17, 0.77);
// Output table and conveyor tray
addTable(3.0, 0.77, 3.5, 2.65);
addBox(scene, 3.22, 0.09, 2.34, materials.tealDark, 3.0, 1.15, 0.77);
addBox(scene, 3.12, 0.035, 2.24, materials.metal, 3.0, 1.21, 0.77);
// Output sheets
const outputSheets = [];
const maxVisibleSheets = 72;
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 9; col++) {
const group = new THREE.Group();
const x = 1.65 + col * 0.37;
const z = -0.28 + row * 0.31;
group.position.set(x, 1.255, z);
group.rotation.y = ((row * 7 + col * 3) % 5 - 2) * 0.012;
scene.add(group);
addBox(group, 0.29, 0.025, 0.24, materials.paper, 0, 0, 0);
addBox(group, 0.12, 0.008, 0.035, materials.tealLight, 0, 0.018, 0.025);
group.scale.setScalar(0.001);
group.visible = false;
outputSheets.push({ group, scale: 0, baseY: 1.255 });
}
}
// Small waste bin
addCylinder(scene, 0.36, 0.72, materials.tealDark, 4.65, 0.36, -1.65, 10);
addCylinder(scene, 0.39, 0.08, materials.teal, 4.65, 0.74, -1.65, 10);
// Hanging lamp
addCylinder(scene, 0.025, 1.05, materials.ink, 0.2, 4.05, 0.1, 8);
const shade = new THREE.Mesh(
new THREE.ConeGeometry(0.58, 0.42, 10, 1, true),
matte(0xe78254, { side: THREE.DoubleSide })
);
shade.position.set(0.2, 3.45, 0.1);
shade.castShadow = true;
scene.add(shade);
// Sign textures
function makeStaticSign() {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#193d39";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#ee8052";
ctx.fillRect(0, 0, 18, canvas.height);
ctx.fillStyle = "#fff8e8";
ctx.font = "900 70px sans-serif";
ctx.fillText("INKSTOCK", 50, 100);
ctx.fillStyle = "#a9c4bc";
ctx.font = "700 25px sans-serif";
ctx.letterSpacing = "5px";
ctx.fillText("PRINT SHOP / COST LAB", 52, 153);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const staticSign = new THREE.Mesh(
new THREE.PlaneGeometry(3.35, 1.15),
new THREE.MeshBasicMaterial({ map: makeStaticSign(), toneMapped: false })
);
staticSign.position.set(-2.8, 2.95, -3.88);
scene.add(staticSign);
const batchCanvas = document.createElement("canvas");
batchCanvas.width = 512;
batchCanvas.height = 220;
const batchContext = batchCanvas.getContext("2d");
const batchTexture = new THREE.CanvasTexture(batchCanvas);
batchTexture.colorSpace = THREE.SRGBColorSpace;
const batchBoard = new THREE.Mesh(
new THREE.PlaneGeometry(2.55, 1.1),
new THREE.MeshBasicMaterial({ map: batchTexture, toneMapped: false })
);
batchBoard.position.set(2.8, 2.93, -3.88);
scene.add(batchBoard);
function updateBatchBoard(state) {
const ctx = batchContext;
ctx.fillStyle = "#fff3db";
ctx.fillRect(0, 0, batchCanvas.width, batchCanvas.height);
ctx.fillStyle = "#193d39";
ctx.fillRect(0, 0, 16, batchCanvas.height);
ctx.fillStyle = "#315753";
ctx.font = "800 24px sans-serif";
ctx.fillText("CURRENT BATCH", 45, 48);
ctx.fillStyle = "#193d39";
ctx.font = "900 62px sans-serif";
ctx.fillText(String(state.orders).padStart(3, "0"), 42, 118);
ctx.fillStyle = "#b45b39";
ctx.font = "900 30px sans-serif";
ctx.fillText(`${state.orders} ORDERS`, 185, 112);
ctx.fillStyle = "#657a73";
ctx.font = "700 19px sans-serif";
ctx.fillText(
`PAPER ${money(state.orders * state.paper, 2)} / SETUP ${money(state.setup)}`,
44,
174
);
batchTexture.needsUpdate = true;
}
let visibleSheetCount = 0;
function updateWorkshop(state) {
visibleSheetCount = Math.min(state.orders, maxVisibleSheets);
updateBatchBoard(state);
}
// Project HTML labels from 3D anchors
const labelAnchors = {
fixedLabel: new THREE.Vector3(-2.8, 3.7, -3.75),
setupLabel: new THREE.Vector3(0, 1.62, 0.95),
paperLabel: new THREE.Vector3(3.0, 1.95, 0.55),
breakEvenLabel: new THREE.Vector3(0, 3.42, 0)
};
const projected = new THREE.Vector3();
function placeLabel(element, anchor) {
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * stage.clientWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * stage.clientHeight}px`;
}
// Resize
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
updateCamera();
// Animation
let previousTime = performance.now();
function animate(time) {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const ease = 1 - Math.exp(-12 * dt);
outputSheets.forEach((sheet, index) => {
const target = index < visibleSheetCount ? 1 : 0;
sheet.scale += (target - sheet.scale) * ease;
sheet.group.visible = sheet.scale > 0.01;
sheet.group.scale.setScalar(Math.max(0.001, sheet.scale));
sheet.group.position.y = sheet.baseY + (1 - sheet.scale) * 0.08;
});
placeLabel(document.querySelector("#fixedLabel"), labelAnchors.fixedLabel);
placeLabel(document.querySelector("#setupLabel"), labelAnchors.setupLabel);
placeLabel(document.querySelector("#paperLabel"), labelAnchors.paperLabel);
placeLabel(
document.querySelector("#breakEvenLabel"),
labelAnchors.breakEvenLabel
);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateModel();
requestAnimationFrame(animate);
</script>
</body>
</html>
```