Prompt specification
Build or customize the Three.js 3D scene "Misregistration changes a multicolor image" 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: Misregistration changes a multicolor image
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/misregistration-changes-a-multicolor-image-x2344
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Edo-period Japanese woodblock printing. Let users offset one printing block before applying its color. Compare the resulting overlap with a correctly aligned print and make the geometric cause of the error visible. Low-poly.
Working Three.js Starter (misregistration-changes-a-multicolor-image-x2344):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Edo Registration — A Woodblock Printing Study</title>
<style>
:root {
--paper: #f3ead6;
--paper-deep: #e3d6bd;
--ink: #202522;
--muted: #716e64;
--line: rgba(32, 37, 34, 0.18);
--vermilion: #d84c35;
--teal: #167d78;
--black: #202522;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7ddc8;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hero {
position: fixed;
z-index: 5;
top: 26px;
left: 30px;
width: min(520px, calc(100vw - 410px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: #5d5c54;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 1px;
content: "";
background: var(--vermilion);
}
h1 {
margin: 0;
font-size: clamp(31px, 3.5vw, 54px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.045em;
}
.hero p {
max-width: 440px;
margin: 13px 0 0;
color: #67655d;
font-size: 14px;
line-height: 1.55;
}
.seal {
position: fixed;
z-index: 4;
top: 28px;
right: 28px;
display: grid;
width: 55px;
height: 55px;
place-items: center;
border: 2px solid var(--vermilion);
color: var(--vermilion);
font-size: 29px;
line-height: 1;
transform: rotate(3deg);
pointer-events: none;
}
.seal::after {
position: absolute;
inset: 4px;
border: 1px solid rgba(216, 76, 53, 0.55);
content: "";
}
.panel {
position: fixed;
z-index: 10;
top: 103px;
right: 28px;
width: 340px;
max-height: calc(100vh - 130px);
overflow: auto;
padding: 21px;
border: 1px solid rgba(40, 42, 37, 0.18);
background: rgba(246, 239, 222, 0.94);
box-shadow:
0 18px 60px rgba(62, 47, 30, 0.12),
inset 0 1px rgba(255, 255, 255, 0.65);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
.panel::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
content: "";
background: var(--vermilion);
}
.plate {
display: flex;
align-items: center;
gap: 13px;
padding-bottom: 17px;
border-bottom: 1px solid var(--line);
}
.swatch {
position: relative;
flex: 0 0 auto;
width: 47px;
height: 47px;
border-radius: 50%;
background: var(--vermilion);
box-shadow: inset -5px -4px rgba(95, 23, 13, 0.15);
}
.swatch::after {
position: absolute;
inset: 6px;
border: 1px solid rgba(255, 222, 192, 0.55);
border-radius: 50%;
content: "";
}
.plate small {
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
}
.plate h2 {
margin: 3px 0 1px;
font-size: 21px;
font-weight: 400;
}
.plate p {
margin: 0;
color: var(--muted);
font-size: 12px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin: 15px 0 19px;
color: #66645c;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #c79546;
box-shadow: 0 0 0 4px rgba(199, 149, 70, 0.13);
}
.status.pulled .status-dot {
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 125, 120, 0.13);
}
.status.working .status-dot {
background: var(--vermilion);
box-shadow: 0 0 0 4px rgba(216, 76, 53, 0.13);
animation: pulse 0.8s infinite alternate;
}
@keyframes pulse {
to {
opacity: 0.35;
}
}
.control-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.control-title h3 {
margin: 0;
font-size: 14px;
font-weight: 400;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 5px 9px;
border: 1px solid rgba(22, 125, 120, 0.35);
border-radius: 999px;
background: rgba(22, 125, 120, 0.08);
color: var(--teal);
cursor: pointer;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.toggle::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
content: "";
}
.toggle.off {
border-color: rgba(32, 37, 34, 0.17);
background: rgba(32, 37, 34, 0.04);
color: var(--muted);
}
.toggle.off::before {
background: #98948a;
}
.range-row {
margin: 0 0 16px;
}
.range-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 6px;
}
.range-heading label {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
output {
color: var(--vermilion);
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 8px 0 0;
border-radius: 0;
appearance: none;
background: linear-gradient(
to right,
var(--vermilion) 0,
var(--vermilion) var(--fill, 50%),
rgba(32, 37, 34, 0.14) var(--fill, 50%),
rgba(32, 37, 34, 0.14) 100%
);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid var(--paper);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]:disabled {
cursor: not-allowed;
opacity: 0.45;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #989287;
font-family: Arial, Helvetica, sans-serif;
font-size: 8px;
}
.hint {
margin: -2px 0 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.action-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
.primary {
min-height: 43px;
border: 0;
background: var(--black);
color: #f8f0dd;
cursor: pointer;
font-size: 13px;
letter-spacing: 0.02em;
transition: background 0.18s, transform 0.18s;
}
.primary:hover:not(:disabled) {
background: #3a403b;
transform: translateY(-1px);
}
.primary:disabled {
cursor: wait;
opacity: 0.65;
}
.secondary {
min-height: 43px;
padding: 0 13px;
border: 1px solid var(--line);
background: transparent;
cursor: pointer;
color: #56564f;
font-size: 11px;
}
.secondary:hover {
background: rgba(32, 37, 34, 0.05);
}
.text-button {
display: block;
margin: 9px auto 0;
padding: 2px;
border: 0;
border-bottom: 1px solid rgba(32, 37, 34, 0.3);
background: transparent;
color: #737068;
cursor: pointer;
font-size: 10px;
}
.geometry {
margin-top: 19px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.equation {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--teal);
font-size: 21px;
font-style: italic;
}
.geometry p {
margin: 0;
color: #66645d;
font-size: 11px;
line-height: 1.55;
}
.focus-title {
margin: 17px 0 8px;
color: #888278;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.focus-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.focus-row button {
min-height: 34px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.23);
cursor: pointer;
color: #5e5c55;
font-size: 10px;
}
.focus-row button.active {
border-color: var(--teal);
background: rgba(22, 125, 120, 0.08);
color: var(--teal);
}
.proof-key {
position: fixed;
z-index: 7;
left: 30px;
bottom: 27px;
display: flex;
gap: 1px;
border: 1px solid rgba(40, 42, 37, 0.16);
background: rgba(246, 239, 222, 0.88);
box-shadow: 0 10px 35px rgba(62, 47, 30, 0.08);
backdrop-filter: blur(10px);
pointer-events: none;
}
.proof {
min-width: 158px;
padding: 12px 15px;
}
.proof + .proof {
border-left: 1px solid var(--line);
}
.proof-label {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 5px;
color: #77736a;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.proof-label::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
content: "";
}
.proof.offset .proof-label::before {
background: var(--vermilion);
}
.proof strong {
font-size: 15px;
font-weight: 400;
}
.navigation {
position: fixed;
z-index: 6;
right: 388px;
bottom: 29px;
color: rgba(32, 37, 34, 0.58);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
}
.navigation span {
color: var(--vermilion);
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
top: 25px;
padding: 10px 16px;
border: 1px solid rgba(32, 37, 34, 0.16);
background: rgba(248, 241, 225, 0.96);
color: #55544d;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
opacity: 0;
transform: translate(-50%, -12px);
transition: opacity 0.25s, transform 0.25s;
pointer-events: none;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
.hero {
width: calc(100vw - 390px);
}
.navigation {
display: none;
}
.proof-key {
bottom: 22px;
}
}
@media (max-width: 720px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 90px);
}
.hero p {
display: none;
}
h1 {
font-size: 31px;
}
.seal {
top: 18px;
right: 17px;
width: 45px;
height: 45px;
font-size: 24px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 42vh;
padding: 16px;
}
.plate {
padding-bottom: 11px;
}
.plate h2 {
font-size: 18px;
}
.status {
margin: 11px 0 13px;
}
.geometry,
.focus-title,
.focus-row {
display: none;
}
.proof-key {
top: 102px;
bottom: auto;
left: 18px;
}
.proof {
min-width: 125px;
padding: 9px 11px;
}
.proof strong {
font-size: 13px;
}
.toast {
top: 76px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive Edo woodblock printing workshop"></canvas>
<header class="hero">
<div class="eyebrow">Edo press · registration study</div>
<h1>The Space<br />Between Colors</h1>
<p>
Shift one carved block before it meets the paper. The reference pull stays
locked, revealing exactly how a rigid translation changes registration.
</p>
</header>
<div class="seal" aria-hidden="true">摺</div>
<aside class="panel" aria-label="Printing controls">
<div class="plate">
<div class="swatch" aria-hidden="true"></div>
<div>
<small>Plate 03 · adjustable</small>
<h2>Shu · Vermilion</h2>
<p>Sun medallion / 日の形</p>
</div>
</div>
<div class="status" id="status">
<span class="status-dot"></span>
<span id="statusText">Block raised · ready to pull</span>
</div>
<div class="control-title">
<h3>Registration offset</h3>
<button
class="toggle"
id="offsetToggle"
type="button"
aria-pressed="true"
>
Error on
</button>
</div>
<div class="range-row">
<div class="range-heading">
<label for="offsetX">X · across page</label>
<output id="offsetXValue" for="offsetX">+4.8 mm</output>
</div>
<input
id="offsetX"
type="range"
min="-8"
max="8"
step="0.1"
value="4.8"
/>
<div class="range-scale"><span>−8</span><span>0</span><span>+8</span></div>
</div>
<div class="range-row">
<div class="range-heading">
<label for="offsetY">Y · up page</label>
<output id="offsetYValue" for="offsetY">−2.6 mm</output>
</div>
<input
id="offsetY"
type="range"
min="-8"
max="8"
step="0.1"
value="-2.6"
/>
<div class="range-scale"><span>−8</span><span>0</span><span>+8</span></div>
</div>
<p class="hint">
The translucent disk is an ink ghost. Pull the plate to compare the
centered reference with the displaced proof.
</p>
<div class="action-row">
<button class="primary" id="applyButton" type="button">Pull vermilion plate</button>
<button class="secondary" id="clearButton" type="button">Clear</button>
</div>
<button class="text-button" id="resetButton" type="button">Reset offset</button>
<section class="geometry">
<div class="equation">p′ − p = t</div>
<p>
A registration error is a rigid translation. Every carved point moves by
the same vector <strong>t</strong>; size and shape do not change. The
teal arrow shows that vector on the proof.
</p>
</section>
<div class="focus-title">View</div>
<div class="focus-row">
<button class="active" id="compareButton" type="button">Compare both</button>
<button id="inspectButton" type="button">Inspect overlap</button>
</div>
</aside>
<div class="proof-key" aria-live="polite">
<div class="proof">
<div class="proof-label">Reference / 正位</div>
<strong id="correctMetric">Δ 0.0 mm</strong>
</div>
<div class="proof offset">
<div class="proof-label">Shifted proof / すれ</div>
<strong id="offsetMetric">Δ 5.5 mm</strong>
</div>
</div>
<div class="navigation">
Drag to orbit · scroll to zoom · <span>shift-drag</span> to pan
</div>
<div class="toast" 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";
/* ------------------------------------------------------------------
Application state
------------------------------------------------------------------ */
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ddc8);
scene.fog = new THREE.Fog(0xe7ddc8, 18, 36);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
80
);
const orbit = {
target: new THREE.Vector3(0.65, 1.0, -0.05),
distance: 15.2,
theta: 0.28,
phi: 0.98
};
const state = {
offsetX: 4.8,
offsetY: -2.6,
offsetEnabled: true,
stamping: false,
stampStart: 0,
revealed: false,
pulled: false,
inspect: false,
toastTimer: 0
};
const MM_TO_WORLD = 0.018;
const PAPER_WIDTH = 2.70;
const PAPER_HEIGHT = 3.35;
const ART_WIDTH = 768;
const ART_HEIGHT = 1024;
const ART_X = 384;
const ART_Y = 300;
// Paper-plane coordinates use X across the page and Y up the page.
const targetLocalX = (ART_X / ART_WIDTH - 0.5) * PAPER_WIDTH;
const targetLocalZ =
-(0.5 - ART_Y / ART_HEIGHT) * PAPER_HEIGHT;
const stationLeft = -3.35;
const stationRight = 3.35;
const hoverY = 2.62;
const pressY = 1.155;
const ui = {
status: document.querySelector("#status"),
statusText: document.querySelector("#statusText"),
x: document.querySelector("#offsetX"),
y: document.querySelector("#offsetY"),
xValue: document.querySelector("#offsetXValue"),
yValue: document.querySelector("#offsetYValue"),
toggle: document.querySelector("#offsetToggle"),
apply: document.querySelector("#applyButton"),
clear: document.querySelector("#clearButton"),
reset: document.querySelector("#resetButton"),
compare: document.querySelector("#compareButton"),
inspect: document.querySelector("#inspectButton"),
correctMetric: document.querySelector("#correctMetric"),
offsetMetric: document.querySelector("#offsetMetric"),
toast: document.querySelector("#toast")
};
/* ------------------------------------------------------------------
Lights and materials
------------------------------------------------------------------ */
const hemisphere = new THREE.HemisphereLight(0xfff6df, 0x777063, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.0);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd5d2, 0.65);
fill.position.set(8, 5, -5);
scene.add(fill);
const material = {
floor: new THREE.MeshStandardMaterial({
color: 0xcdbd9f,
roughness: 1,
flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x5a3c27,
roughness: 0.92,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x9b7148,
roughness: 0.9,
flatShading: true
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xb18a5d,
roughness: 0.9,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe9dfc7,
roughness: 1,
flatShading: true
}),
black: new THREE.MeshStandardMaterial({
color: 0x252723,
roughness: 0.8,
flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0xc94631,
roughness: 0.9,
flatShading: true
})
};
/* ------------------------------------------------------------------
Deterministic canvas artwork
------------------------------------------------------------------ */
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makeCanvasTexture(canvas, srgb = true) {
const texture = new THREE.CanvasTexture(canvas);
if (srgb) texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function drawPaperArtwork() {
const c = document.createElement("canvas");
c.width = ART_WIDTH;
c.height = ART_HEIGHT;
const ctx = c.getContext("2d");
const random = seededRandom(8417);
ctx.fillStyle = "#f1e7d0";
ctx.fillRect(0, 0, c.width, c.height);
// Washi fibers and paper flecks.
for (let i = 0; i < 1300; i++) {
const x = random() * c.width;
const y = random() * c.height;
const alpha = 0.018 + random() * 0.045;
ctx.fillStyle = `rgba(65, 52, 35, ${alpha})`;
ctx.fillRect(x, y, 1 + random() * 2, 1);
}
// Subtle deckle-like edge.
ctx.strokeStyle = "rgba(67, 55, 39, 0.14)";
ctx.lineWidth = 3;
ctx.strokeRect(19, 19, c.width - 38, c.height - 38);
// Indigo mountain layer.
ctx.fillStyle = "#344d59";
ctx.beginPath();
ctx.moveTo(76, 660);
ctx.lineTo(286, 456);
ctx.lineTo(367, 522);
ctx.lineTo(511, 396);
ctx.lineTo(698, 660);
ctx.closePath();
ctx.fill();
ctx.fillStyle = "rgba(239, 227, 201, 0.82)";
ctx.beginPath();
ctx.moveTo(286, 456);
ctx.lineTo(367, 522);
ctx.lineTo(330, 505);
ctx.lineTo(299, 523);
ctx.closePath();
ctx.fill();
// Water bands.
ctx.strokeStyle = "#344d59";
ctx.lineWidth = 10;
for (let row = 0; row < 5; row++) {
const y = 704 + row * 47;
ctx.beginPath();
ctx.moveTo(55, y);
ctx.bezierCurveTo(150, y - 28, 235, y + 28, 340, y);
ctx.bezierCurveTo(452, y - 29, 550, y + 25, 712, y - 4);
ctx.stroke();
}
// Black key block: the intended sun center and circular keyline.
ctx.strokeStyle = "#222722";
ctx.lineWidth = 9;
ctx.beginPath();
ctx.arc(ART_X, ART_Y, 145, 0, Math.PI * 2);
ctx.stroke();
ctx.lineWidth = 4;
ctx.beginPath();
ctx.arc(ART_X, ART_Y, 156, -0.18, 0.48);
ctx.stroke();
// Small registration cross at the geometric center.
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(ART_X - 17, ART_Y);
ctx.lineTo(ART_X + 17, ART_Y);
ctx.moveTo(ART_X, ART_Y - 17);
ctx.lineTo(ART_X, ART_Y + 17);
ctx.stroke();
// Marginal calligraphic marks.
ctx.fillStyle = "#282a26";
ctx.font = "38px serif";
ctx.fillText("東", 64, 135);
ctx.fillText("都", 64, 181);
ctx.font = "18px serif";
ctx.fillText("摺", 670, 972);
return makeCanvasTexture(c);
}
function drawVermilionLayer() {
const c = document.createElement("canvas");
c.width = ART_WIDTH;
c.height = ART_HEIGHT;
const ctx = c.getContext("2d");
const random = seededRandom(2903);
ctx.clearRect(0, 0, c.width, c.height);
ctx.save();
// Slightly irregular carved circle.
const radius = 125;
ctx.beginPath();
for (let i = 0; i <= 96; i++) {
const angle = (i / 96) * Math.PI * 2;
const r = radius + Math.sin(angle * 13) * 1.3 + (random() - 0.5) * 1.7;
const x = ART_X + Math.cos(angle) * r;
const y = ART_Y + Math.sin(angle) * r;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
ctx.fillStyle = "#d84c35";
ctx.fill();
ctx.clip();
// Uneven pigment and woodgrain transfer.
for (let i = 0; i < 900; i++) {
const x = ART_X - radius + random() * radius * 2;
const y = ART_Y - radius + random() * radius * 2;
ctx.fillStyle = `rgba(95, 25, 14, ${random() * 0.12})`;
ctx.fillRect(x, y, 1 + random() * 3, 1);
}
for (let i = 0; i < 22; i++) {
ctx.strokeStyle = `rgba(255, 211, 171, ${0.025 + random() * 0.05})`;
ctx.lineWidth = 1 + random() * 2;
const y = ART_Y - radius + random() * radius * 2;
ctx.beginPath();
ctx.moveTo(ART_X - radius, y);
ctx.lineTo(ART_X + radius, y + random() * 8 - 4);
ctx.stroke();
}
ctx.restore();
return makeCanvasTexture(c);
}
function drawBlockArtwork() {
const c = document.createElement("canvas");
c.width = ART_WIDTH;
c.height = ART_HEIGHT;
const ctx = c.getContext("2d");
const random = seededRandom(1171);
ctx.fillStyle = "#9a7046";
ctx.fillRect(0, 0, c.width, c.height);
for (let i = 0; i < 95; i++) {
const y = random() * c.height;
ctx.strokeStyle = `rgba(65, 35, 19, ${0.025 + random() * 0.07})`;
ctx.lineWidth = 1 + random() * 4;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.bezierCurveTo(
190, y + random() * 18 - 9,
530, y + random() * 18 - 9,
c.width, y + random() * 10 - 5
);
ctx.stroke();
}
ctx.strokeStyle = "rgba(53, 31, 18, 0.7)";
ctx.lineWidth = 9;
ctx.strokeRect(17, 17, c.width - 34, c.height - 34);
// Carved image and residual red pigment.
ctx.strokeStyle = "rgba(46, 28, 18, 0.85)";
ctx.lineWidth = 10;
ctx.beginPath();
ctx.arc(ART_X, ART_Y, 131, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "rgba(195, 61, 39, 0.86)";
ctx.beginPath();
ctx.arc(ART_X, ART_Y, 115, 0, Math.PI * 2);
ctx.fill();
// Registration crosses cut into the block.
ctx.strokeStyle = "rgba(38, 26, 19, 0.85)";
ctx.lineWidth = 4;
for (const [x, y] of [[70, 70], [698, 70], [70, 954], [698, 954]]) {
ctx.beginPath();
ctx.moveTo(x - 17, y);
ctx.lineTo(x + 17, y);
ctx.moveTo(x, y - 17);
ctx.lineTo(x, y + 17);
ctx.stroke();
}
return makeCanvasTexture(c);
}
const paperTexture = drawPaperArtwork();
const vermilionTexture = drawVermilionLayer();
const blockTexture = drawBlockArtwork();
/* ------------------------------------------------------------------
Geometry helpers
------------------------------------------------------------------ */
function makeBox(
width,
height,
depth,
mat,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeHorizontalPlane(
width,
height,
mat,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), mat);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makePlaque(title, subtitle, accent) {
const c = document.createElement("canvas");
c.width = 900;
c.height = 230;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(244, 235, 214, 0.96)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "rgba(38, 40, 35, 0.35)";
ctx.lineWidth = 4;
ctx.strokeRect(8, 8, c.width - 16, c.height - 16);
ctx.fillStyle = accent;
ctx.fillRect(28, 34, 10, 160);
ctx.fillStyle = "#242824";
ctx.font = "46px Georgia";
ctx.fillText(title, 67, 92);
ctx.fillStyle = "#777269";
ctx.font = "24px Arial";
ctx.fillText(subtitle, 69, 143);
const texture = makeCanvasTexture(c);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(3.25, 0.83, 1);
sprite.renderOrder = 30;
return sprite;
}
function makeDeltaLabel() {
const c = document.createElement("canvas");
c.width = 512;
c.height = 150;
const ctx = c.getContext("2d");
const texture = makeCanvasTexture(c);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(1.62, 0.48, 1);
sprite.renderOrder = 31;
function update(text) {
ctx.clearRect(0, 0, c.width, c.height);
ctx.fillStyle = "rgba(22, 125, 120, 0.95)";
ctx.fillRect(0, 20, c.width, 110);
ctx.fillStyle = "#f7efd9";
ctx.font = "42px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, 75);
texture.needsUpdate = true;
}
update("0.0 mm");
return { sprite, update };
}
function makeCrossMarker(color, radius = 0.08) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-radius, 0, 0),
new THREE.Vector3(radius, 0, 0),
new THREE.Vector3(0, 0, -radius),
new THREE.Vector3(0, 0, radius)
]);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
line.renderOrder = 24;
return line;
}
/* ------------------------------------------------------------------
Workshop environment
------------------------------------------------------------------ */
const floor = makeHorizontalPlane(
34,
25,
material.floor,
0,
-0.012,
0
);
floor.receiveShadow = true;
// A subtle dark floor runner under the two presses.
makeHorizontalPlane(
11.5,
6.1,
new THREE.MeshStandardMaterial({
color: 0x67594a,
roughness: 1
}),
0,
0.001,
0.2
);
// Shoji-style back wall.
const screenGroup = new THREE.Group();
scene.add(screenGroup);
for (let i = -1; i <= 1; i++) {
const panelX = i * 3.55;
makeBox(3.25, 4.0, 0.10, material.cream, panelX, 2.12, -5.15, screenGroup);
makeBox(0.12, 4.15, 0.16, material.darkWood, panelX - 1.69, 2.12, -5.08, screenGroup);
makeBox(0.12, 4.15, 0.16, material.darkWood, panelX + 1.69, 2.12, -5.08, screenGroup);
makeBox(3.48, 0.12, 0.16, material.darkWood, panelX, 4.20, -5.08, screenGroup);
makeBox(3.48, 0.12, 0.16, material.darkWood, panelX, 0.08, -5.08, screenGroup);
makeBox(0.07, 3.85, 0.13, material.woodLight, panelX, 2.12, -5.06, screenGroup);
}
// A small vermilion emblem on the back wall.
const emblem = new THREE.Mesh(
new THREE.CircleGeometry(0.43, 24),
material.red
);
emblem.position.set(0, 3.13, -5.045);
scene.add(emblem);
// Low-poly decorative stones at the far left.
const stoneMat = new THREE.MeshStandardMaterial({
color: 0x8b887c,
roughness: 1,
flatShading: true
});
const stoneA = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.58, 0),
stoneMat
);
stoneA.position.set(-6.2, 0.42, 1.7);
stoneA.scale.set(1.25, 0.65, 1);
stoneA.castShadow = true;
scene.add(stoneA);
const stoneB = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.33, 0),
stoneMat
);
stoneB.position.set(-5.65, 0.92, 1.75);
stoneB.castShadow = true;
scene.add(stoneB);
/* ------------------------------------------------------------------
Press stations, paper, and blocks
------------------------------------------------------------------ */
function createStation(x, label, subtitle, accent, isOffset) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
// Low wooden worktable.
makeBox(3.62, 0.24, 4.28, material.wood, 0, 0.83, 0, group);
makeBox(3.72, 0.10, 4.38, material.darkWood, 0, 0.67, 0, group);
for (const legX of [-1.52, 1.52]) {
for (const legZ of [-1.82, 1.82]) {
makeBox(0.20, 0.76, 0.20, material.darkWood, legX, 0.38, legZ, group);
}
}
makeBox(0.15, 0.16, 3.55, material.woodLight, -1.52, 0.35, 0, group);
makeBox(0.15, 0.16, 3.55, material.woodLight, 1.52, 0.35, 0, group);
// Rear roller and wooden supports.
const roller = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 3.45, 10),
material.darkWood
);
roller.rotation.z = Math.PI / 2;
roller.position.set(0, 1.13, -1.95);
roller.castShadow = true;
group.add(roller);
makeBox(0.18, 0.45, 0.18, material.darkWood, -1.72, 0.98, -1.95, group);
makeBox(0.18, 0.45, 0.18, material.darkWood, 1.72, 0.98, -1.95, group);
// Paper stack and printed base.
makeBox(
PAPER_WIDTH + 0.05,
0.045,
PAPER_HEIGHT + 0.05,
material.cream,
0,
0.978,
0,
group
);
const paperMaterial = new THREE.MeshStandardMaterial({
map: paperTexture,
roughness: 1,
metalness: 0
});
const paper = makeHorizontalPlane(
PAPER_WIDTH,
PAPER_HEIGHT,
paperMaterial,
0,
1.006,
0,
group
);
paper.receiveShadow = true;
// L-shaped corner registration marks around the sheet.
const cornerMaterial = new THREE.LineBasicMaterial({
color: isOffset ? 0xb94734 : 0x187a74,
transparent: true,
opacity: 0.75
});
const cornerPoints = [];
const w = PAPER_WIDTH / 2 + 0.08;
const h = PAPER_HEIGHT / 2 + 0.08;
const l = 0.22;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const px = sx * w;
const pz = sz * h;
cornerPoints.push(
new THREE.Vector3(px, 1.025, pz),
new THREE.Vector3(px - sx * l, 1.025, pz),
new THREE.Vector3(px, 1.025, pz),
new THREE.Vector3(px, 1.025, pz - sz * l)
);
}
}
const cornerGeometry = new THREE.BufferGeometry().setFromPoints(cornerPoints);
group.add(new THREE.LineSegments(cornerGeometry, cornerMaterial));
// The floating woodblock.
const blockGroup = new THREE.Group();
group.add(blockGroup);
const blockBody = makeBox(
PAPER_WIDTH - 0.12,
0.24,
PAPER_HEIGHT - 0.12,
material.woodLight,
0,
0,
0,
blockGroup
);
const blockFaceMaterial = new THREE.MeshStandardMaterial({
map: blockTexture,
roughness: 0.92,
flatShading: true
});
const blockFace = makeHorizontalPlane(
PAPER_WIDTH - 0.15,
PAPER_HEIGHT - 0.15,
blockFaceMaterial,
0,
0.126,
0,
blockGroup
);
blockFace.receiveShadow = true;
// Ink preview and final color layer.
const previewMaterial = new THREE.MeshBasicMaterial({
map: vermilionTexture,
transparent: true,
opacity: 0.19,
depthWrite: false,
alphaTest: 0.01,
side: THREE.DoubleSide,
toneMapped: false
});
const solidMaterial = new THREE.MeshBasicMaterial({
map: vermilionTexture,
transparent: true,
opacity: 1,
depthWrite: false,
alphaTest: 0.01,
side: THREE.DoubleSide,
toneMapped: false
});
const preview = makeHorizontalPlane(
PAPER_WIDTH,
PAPER_HEIGHT,
previewMaterial,
0,
1.022,
0,
group
);
preview.renderOrder = 5;
const solid = makeHorizontalPlane(
PAPER_WIDTH,
PAPER_HEIGHT,
solidMaterial,
0,
1.030,
0,
group
);
solid.renderOrder = 6;
solid.visible = false;
const plaque = makePlaque(label, subtitle, accent);
plaque.position.set(0, 3.57, -0.72);
group.add(plaque);
// Small ink dish and brush on the side of the table.
const dish = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.24, 0.09, 12),
material.black
);
dish.position.set(1.51, 1.00, 1.43);
dish.castShadow = true;
group.add(dish);
const brush = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.028, 1.05, 7),
material.darkWood
);
brush.rotation.z = Math.PI / 2;
brush.rotation.y = -0.30;
brush.position.set(1.48, 1.09, 1.18);
brush.castShadow = true;
group.add(brush);
return {
group,
blockGroup,
preview,
solid,
paper
};
}
const leftStation = createStation(
stationLeft,
"CORRECT REGISTRATION",
"正位 / reference pull",
"#167d78",
false
);
const rightStation = createStation(
stationRight,
"BLOCK OFFSET",
"すれ / registration error",
"#d84c35",
true
);
leftStation.blockGroup.position.set(0, hoverY, 0);
rightStation.blockGroup.position.set(0, hoverY, 0);
/* ------------------------------------------------------------------
Geometric registration vector
------------------------------------------------------------------ */
const targetWorld = new THREE.Vector3(
stationRight + targetLocalX,
1.056,
targetLocalZ
);
const vectorArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
targetWorld,
0.2,
0x167d78,
0.12,
0.075
);
vectorArrow.line.material.transparent = true;
vectorArrow.line.material.opacity = 0.95;
vectorArrow.line.material.depthTest = false;
vectorArrow.cone.material.transparent = true;
vectorArrow.cone.material.opacity = 0.95;
vectorArrow.cone.material.depthTest = false;
vectorArrow.line.renderOrder = 22;
vectorArrow.cone.renderOrder = 22;
scene.add(vectorArrow);
const intendedMarker = makeCrossMarker(0x167d78, 0.095);
intendedMarker.position.copy(targetWorld);
scene.add(intendedMarker);
const actualMarker = makeCrossMarker(0xd84c35, 0.075);
scene.add(actualMarker);
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
targetWorld.clone(),
targetWorld.clone()
]);
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x167d78,
dashSize: 0.085,
gapSize: 0.055,
transparent: true,
opacity: 0.78,
depthTest: false,
depthWrite: false
});
const guideLine = new THREE.Line(guideGeometry, guideMaterial);
guideLine.computeLineDistances();
guideLine.renderOrder = 23;
scene.add(guideLine);
const deltaLabel = makeDeltaLabel();
scene.add(deltaLabel.sprite);
/* ------------------------------------------------------------------
Offset state and UI
------------------------------------------------------------------ */
function effectiveOffset() {
if (!state.offsetEnabled) {
return { x: 0, z: 0, mmX: 0, mmY: 0, length: 0 };
}
const mmX = state.offsetX;
const mmY = state.offsetY;
const x = mmX * MM_TO_WORLD;
// Positive page-Y points away from the viewer in world coordinates.
const z = -mmY * MM_TO_WORLD;
return {
x,
z,
mmX,
mmY,
length: Math.hypot(mmX, mmY)
};
}
function signed(value) {
return `${value >= 0 ? "+" : ""}${value.toFixed(1)}`;
}
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateOffset() {
const offset = effectiveOffset();
// Offset station's woodblock and proof layers.
rightStation.blockGroup.position.x = offset.x;
rightStation.blockGroup.position.z = offset.z;
rightStation.preview.position.x = offset.x;
rightStation.preview.position.z = offset.z;
rightStation.solid.position.x = offset.x;
rightStation.solid.position.z = offset.z;
// Reference stays exactly centered.
leftStation.preview.position.set(0, 1.022, 0);
leftStation.solid.position.set(0, 1.030, 0);
const end = new THREE.Vector3(
targetWorld.x + offset.x,
targetWorld.y,
targetWorld.z + offset.z
);
actualMarker.position.copy(end);
if (offset.length > 0.015) {
const direction = end.clone().sub(targetWorld).normalize();
vectorArrow.setDirection(direction);
vectorArrow.setLength(Math.max(offset.length * MM_TO_WORLD, 0.001), 0.12, 0.075);
vectorArrow.visible = true;
} else {
vectorArrow.visible = false;
}
deltaLabel.sprite.position.set(
(targetWorld.x + end.x) / 2,
1.63,
(targetWorld.z + end.z) / 2
);
deltaLabel.update(`${offset.length.toFixed(1)} mm`);
ui.xValue.textContent = `${signed(state.offsetX)} mm`;
ui.yValue.textContent = `${signed(state.offsetY)} mm`;
ui.offsetMetric.textContent = `Δ ${offset.length.toFixed(1)} mm`;
ui.correctMetric.textContent = "Δ 0.0 mm";
updateRangeFill(ui.x);
updateRangeFill(ui.y);
if (state.pulled && !state.stamping) {
setStatus("Proof follows block · pull to re-ink", "pulled");
}
}
function setStatus(text, kind = "") {
ui.statusText.textContent = text;
ui.status.className = "status";
if (kind) ui.status.classList.add(kind);
}
function showToast(message) {
ui.toast.textContent = message;
ui.toast.classList.add("visible");
clearTimeout(state.toastTimer);
state.toastTimer = setTimeout(() => {
ui.toast.classList.remove("visible");
}, 1800);
}
ui.x.addEventListener("input", () => {
state.offsetX = Number(ui.x.value);
updateOffset();
});
ui.y.addEventListener("input", () => {
state.offsetY = Number(ui.y.value);
updateOffset();
});
ui.toggle.addEventListener("click", () => {
state.offsetEnabled = !state.offsetEnabled;
ui.toggle.classList.toggle("off", !state.offsetEnabled);
ui.toggle.setAttribute("aria-pressed", String(state.offsetEnabled));
ui.toggle.textContent = state.offsetEnabled ? "Error on" : "Locked";
updateOffset();
showToast(state.offsetEnabled ? "Registration error enabled" : "Reference alignment locked");
});
ui.reset.addEventListener("click", () => {
state.offsetX = 4.8;
state.offsetY = -2.6;
state.offsetEnabled = true;
ui.x.value = String(state.offsetX);
ui.y.value = String(state.offsetY);
ui.toggle.classList.remove("off");
ui.toggle.setAttribute("aria-pressed", "true");
ui.toggle.textContent = "Error on";
updateOffset();
});
ui.clear.addEventListener("click", () => {
state.stamping = false;
state.revealed = false;
state.pulled = false;
leftStation.solid.visible = false;
rightStation.solid.visible = false;
leftStation.preview.visible = true;
rightStation.preview.visible = true;
ui.apply.disabled = false;
ui.apply.textContent = "Pull vermilion plate";
setStatus("Block raised · ready to pull");
});
ui.apply.addEventListener("click", () => {
if (state.stamping) return;
state.stamping = true;
state.stampStart = performance.now();
state.revealed = false;
state.pulled = false;
leftStation.solid.visible = false;
rightStation.solid.visible = false;
leftStation.preview.visible = false;
rightStation.preview.visible = false;
ui.apply.disabled = true;
ui.apply.textContent = "Pulling plate…";
ui.x.disabled = true;
ui.y.disabled = true;
setStatus("Pressing two synchronized proofs", "working");
});
/* ------------------------------------------------------------------
Camera: implemented directly without external controls
------------------------------------------------------------------ */
let cameraTween = null;
function beginCameraTween(target, distance, theta, phi) {
cameraTween = {
start: performance.now(),
duration: 950,
from: {
target: orbit.target.clone(),
distance: orbit.distance,
theta: orbit.theta,
phi: orbit.phi
},
to: {
target: target.clone(),
distance,
theta,
phi
}
};
}
function setCompareView() {
state.inspect = false;
leftStation.blockGroup.visible = true;
rightStation.blockGroup.visible = true;
ui.compare.classList.add("active");
ui.inspect.classList.remove("active");
beginCameraTween(
new THREE.Vector3(0.65, 1.0, -0.05),
15.2,
0.28,
0.98
);
showToast("Comparing reference and offset proofs");
}
function setInspectView() {
state.inspect = true;
leftStation.blockGroup.visible = false;
rightStation.blockGroup.visible = false;
ui.inspect.classList.add("active");
ui.compare.classList.remove("active");
beginCameraTween(
new THREE.Vector3(stationRight, 1.05, targetLocalZ),
6.3,
0.16,
0.71
);
showToast("Inspecting the geometric overlap");
}
ui.compare.addEventListener("click", setCompareView);
ui.inspect.addEventListener("click", setInspectView);
const pointers = new Map();
let lastPointer = null;
let previousPinchDistance = 0;
let dragButton = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
lastPointer = { x: event.clientX, y: event.clientY };
dragButton = event.button;
previousPinchDistance = pointerDistance();
cameraTween = null;
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
orbit.distance *= previousPinchDistance / distance;
orbit.distance = THREE.MathUtils.clamp(orbit.distance, 4.4, 24);
}
previousPinchDistance = distance;
return;
}
if (!lastPointer) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
if (event.shiftKey || dragButton === 2) {
const scale = orbit.distance * 0.00135;
orbit.target.x -= dx * Math.cos(orbit.theta) * scale;
orbit.target.z += dx * Math.sin(orbit.theta) * scale;
orbit.target.y = THREE.MathUtils.clamp(
orbit.target.y + dy * scale,
0.25,
4.0
);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.30, 1.42);
}
lastPointer = { x: event.clientX, y: event.clientY };
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
lastPointer = null;
} else {
const first = [...pointers.values()][0];
lastPointer = { x: first.x, y: first.y };
}
previousPinchDistance = pointerDistance();
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
orbit.distance *= Math.exp(event.deltaY * 0.001);
orbit.distance = THREE.MathUtils.clamp(orbit.distance, 4.4, 24);
},
{ passive: false }
);
canvas.addEventListener("dblclick", setCompareView);
function updateCamera(now) {
if (cameraTween) {
const raw = Math.min(1, (now - cameraTween.start) / cameraTween.duration);
const t = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
orbit.target.lerpVectors(
cameraTween.from.target,
cameraTween.to.target,
t
);
orbit.distance = THREE.MathUtils.lerp(
cameraTween.from.distance,
cameraTween.to.distance,
t
);
orbit.theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
t
);
orbit.phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
t
);
if (raw >= 1) cameraTween = null;
}
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.distance * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.distance * Math.cos(orbit.phi),
orbit.target.z + orbit.distance * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
/* ------------------------------------------------------------------
Stamp animation and frame loop
------------------------------------------------------------------ */
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function updateStamp(now) {
if (!state.stamping) return;
const elapsed = (now - state.stampStart) / 1000;
let blockY;
if (elapsed < 0.52) {
blockY = THREE.MathUtils.lerp(
hoverY,
pressY,
easeOutCubic(elapsed / 0.52)
);
} else if (elapsed < 0.92) {
blockY = pressY;
} else if (elapsed < 1.55) {
blockY = THREE.MathUtils.lerp(
pressY,
hoverY,
easeInOutCubic((elapsed - 0.92) / 0.63)
);
} else {
blockY = hoverY;
state.stamping = false;
state.revealed = true;
state.pulled = true;
leftStation.solid.visible = true;
rightStation.solid.visible = true;
ui.apply.disabled = false;
ui.apply.textContent = "Pull another proof";
ui.x.disabled = false;
ui.y.disabled = false;
setStatus("Two proofs pulled · compare registration", "pulled");
showToast("The shifted disk exposes the registration error");
}
leftStation.blockGroup.position.y = blockY;
rightStation.blockGroup.position.y = blockY;
if (!state.revealed && elapsed >= 0.59) {
state.revealed = true;
leftStation.solid.visible = true;
rightStation.solid.visible = true;
}
}
function updateGuide() {
const offset = effectiveOffset();
const start = targetWorld.clone();
const end = new THREE.Vector3(
stationRight + offset.x,
rightStation.blockGroup.position.y + 0.14,
targetLocalZ + offset.z
);
const positions = guideGeometry.attributes.position;
positions.setXYZ(0, start.x, start.y, start.z);
positions.setXYZ(1, end.x, end.y, end.z);
positions.needsUpdate = true;
guideGeometry.computeBoundingSphere();
guideLine.computeLineDistances();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
updateOffset();
updateCamera(performance.now());
renderer.setAnimationLoop((now) => {
updateCamera(now);
updateStamp(now);
updateGuide();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```