Prompt specification
Build or customize the Three.js 3D scene "Compare movable type with a carved whole page" 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: Compare movable type with a carved whole page
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-movable-type-with-a-carved-whole-page-x2516
Scene Description Prompt:
Edit one symbol in voxel movable-type and carved-page printing setups; compare replaced pieces while preserving identical final text. Three.js from cdnjs, one HTML file.
Working Three.js Starter (compare-movable-type-with-a-carved-whole-page-x2516):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Matched Impressions — Voxel & Carved Printing</title>
<style>
:root {
--ink: #171815;
--panel: #20211d;
--panel-2: #292a25;
--line: rgba(255, 255, 255, 0.11);
--paper: #eee8d9;
--muted: #a7a89e;
--orange: #ed7444;
--orange-soft: #ffb08b;
--teal: #73b6aa;
--green: #a7d7a5;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button {
border: 1px solid var(--line);
color: var(--paper);
background: rgba(255, 255, 255, 0.045);
border-radius: 10px;
padding: 10px 12px;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.27);
background: rgba(255, 255, 255, 0.08);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
button.primary {
color: #201712;
border-color: transparent;
background: var(--orange);
font-weight: 800;
}
button.primary:hover { background: #fa8759; }
button.active {
border-color: var(--orange);
color: var(--orange-soft);
background: rgba(237, 116, 68, 0.12);
}
button:disabled {
opacity: 0.4;
cursor: default;
transform: none;
}
#app {
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: #191a17;
z-index: 2;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-3deg);
}
.brand-mark i {
display: block;
background: var(--orange);
border-radius: 2px;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
background: var(--paper);
}
.brand-copy {
display: flex;
align-items: baseline;
gap: 12px;
min-width: 0;
}
.brand-copy strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
letter-spacing: -0.02em;
white-space: nowrap;
}
.brand-copy span {
color: var(--muted);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.sync {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.sync::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px rgba(167, 215, 165, 0.55);
}
main {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 38%, rgba(118, 98, 67, 0.13), transparent 45%),
#151612;
}
#viewport canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.scene-heading {
position: absolute;
left: 24px;
top: 22px;
pointer-events: none;
max-width: 380px;
text-shadow: 0 2px 20px #111;
}
.eyebrow {
color: var(--orange-soft);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.scene-heading h1 {
margin: 7px 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-weight: 500;
font-size: clamp(24px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.035em;
}
.scene-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.scene-help {
position: absolute;
left: 22px;
bottom: 18px;
display: flex;
gap: 8px;
align-items: center;
pointer-events: none;
color: #c3c2b7;
font-size: 10px;
letter-spacing: 0.04em;
}
.scene-help span {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 7px;
background: rgba(15, 16, 13, 0.72);
backdrop-filter: blur(8px);
}
#toast {
position: absolute;
left: 50%;
bottom: 22px;
transform: translate(-50%, 14px);
padding: 11px 16px;
border: 1px solid rgba(237, 116, 68, 0.35);
border-radius: 10px;
background: rgba(26, 26, 22, 0.93);
color: var(--paper);
opacity: 0;
pointer-events: none;
transition: 220ms ease;
font-size: 12px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
white-space: nowrap;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 22px;
border-left: 1px solid var(--line);
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #484940 transparent;
}
.section {
padding-bottom: 21px;
margin-bottom: 21px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
border-bottom: 0;
padding-bottom: 0;
margin-bottom: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.section-title h2 {
margin: 0;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
color: #d3d2c7;
}
.section-title small {
color: var(--muted);
font-size: 10px;
}
#phrase {
width: 100%;
padding: 13px 14px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
outline: none;
color: var(--paper);
background: #171815;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#phrase:focus {
border-color: var(--orange);
box-shadow: 0 0 0 3px rgba(237, 116, 68, 0.1);
}
#charStrip {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 12px;
}
.char-button {
width: 29px;
height: 29px;
padding: 0;
border-radius: 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
}
.char-button.selected {
color: #241811;
border-color: var(--orange);
background: var(--orange);
font-weight: 800;
}
.selection-card {
display: grid;
grid-template-columns: 74px 1fr;
gap: 12px;
align-items: stretch;
}
#selectedChar {
display: grid;
place-items: center;
min-height: 74px;
border: 1px solid rgba(237, 116, 68, 0.38);
border-radius: 12px;
background:
linear-gradient(145deg, rgba(237, 116, 68, 0.17), rgba(237, 116, 68, 0.035));
color: var(--orange-soft);
font-family: Georgia, "Times New Roman", serif;
font-size: 44px;
line-height: 1;
}
.selection-fields {
display: flex;
flex-direction: column;
justify-content: center;
gap: 7px;
}
.field-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 9px 10px;
color: var(--paper);
background: #171815;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 8px;
outline: none;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.actions .wide { grid-column: 1 / -1; }
.note {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.proof-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.proof-card {
min-width: 0;
padding: 13px 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 11px;
background: #e9e2d2;
color: #26251f;
box-shadow: inset 0 0 30px rgba(76, 55, 28, 0.07);
}
.proof-card .proof-label {
color: #7c7464;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.proof-text {
margin-top: 12px;
min-height: 43px;
overflow-wrap: anywhere;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 800;
line-height: 1.3;
letter-spacing: 0.025em;
text-transform: uppercase;
}
.proof-text .selected {
color: #b94f29;
text-decoration: underline;
text-decoration-thickness: 2px;
text-underline-offset: 3px;
}
.parity {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
padding: 9px 10px;
border: 1px solid rgba(167, 215, 165, 0.18);
border-radius: 8px;
background: rgba(167, 215, 165, 0.06);
color: var(--green);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.utility-row {
display: flex;
gap: 8px;
margin-top: 11px;
}
.utility-row button { flex: 1; font-size: 11px; }
@media (max-width: 900px) {
#app { grid-template-rows: 62px minmax(0, 1fr); }
header { padding: 0 15px; }
.brand-copy span { display: none; }
main {
grid-template-columns: 1fr;
grid-template-rows: minmax(280px, 1fr) minmax(260px, 38%);
}
aside {
border-left: 0;
border-top: 1px solid var(--line);
padding: 16px;
}
.scene-heading { left: 16px; top: 15px; }
.scene-heading p { display: none; }
.scene-help { left: 12px; bottom: 10px; }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<strong>Matched Impressions</strong>
<span>Movable type / carved page</span>
</div>
</div>
<div class="sync">Proofs synchronized</div>
</header>
<main>
<section id="viewport" aria-label="Interactive three-dimensional printing comparison">
<div class="scene-heading">
<div class="eyebrow">Interactive print study · 01</div>
<h1>One symbol.<br>Two traditions.</h1>
<p>
Edit one character and apply it simultaneously to a voxel type assembly
and a carved page matrix.
</p>
</div>
<div class="scene-help">
<span>Drag to orbit</span>
<span>Scroll to zoom</span>
<span>Click a glyph to select</span>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside>
<section class="section">
<div class="section-title">
<h2>Final text</h2>
<small id="charCount">10 characters</small>
</div>
<input id="phrase" value="PRINT / 26" maxlength="14"
aria-label="Final printed text" spellcheck="false">
<div id="charStrip" aria-label="Select a character"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Symbol replacement</h2>
<small id="positionLabel">Position 03</small>
</div>
<div class="selection-card">
<div id="selectedChar">R</div>
<div class="selection-fields">
<div class="field-label">Replacement matrix</div>
<select id="replacement" aria-label="Replacement symbol"></select>
</div>
</div>
<div class="actions">
<button id="apply" class="primary wide">Apply to both setups</button>
<button id="compare" aria-pressed="false">Compare pieces</button>
<button id="undo">Undo</button>
</div>
<p class="note">
The selected symbol is replaced in both workflows. Both final proofs
remain character-for-character identical.
</p>
</section>
<section class="section">
<div class="section-title">
<h2>Matched proofs</h2>
<small>Live output</small>
</div>
<div class="proof-grid">
<div class="proof-card">
<div class="proof-label">Voxel impression</div>
<div id="voxelProof" class="proof-text"></div>
</div>
<div class="proof-card">
<div class="proof-label">Carved page</div>
<div id="carvedProof" class="proof-text"></div>
</div>
</div>
<div class="parity">
<span>Text parity</span>
<span>Identical ✓</span>
</div>
<div class="utility-row">
<button id="resetCamera">Reset camera</button>
<button id="resetEdit">Reset edit</button>
</div>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -------------------------------------------------------------------------- */
/* State and glyph data */
/* -------------------------------------------------------------------------- */
const DEFAULT_PHRASE = "PRINT / 26";
const GLYPHS = {
" ": ["00000","00000","00000","00000","00000","00000","00000"],
"A": ["01110","10001","10001","11111","10001","10001","10001"],
"B": ["11110","10001","10001","11110","10001","10001","11110"],
"C": ["01111","10000","10000","10000","10000","10000","01111"],
"D": ["11110","10001","10001","10001","10001","10001","11110"],
"E": ["11111","10000","10000","11110","10000","10000","11111"],
"F": ["11111","10000","10000","11110","10000","10000","10000"],
"G": ["01111","10000","10000","10111","10001","10001","01111"],
"H": ["10001","10001","10001","11111","10001","10001","10001"],
"I": ["11111","00100","00100","00100","00100","00100","11111"],
"J": ["00111","00010","00010","00010","10010","10010","01100"],
"K": ["10001","10010","10100","11000","10100","10010","10001"],
"L": ["10000","10000","10000","10000","10000","10000","11111"],
"M": ["10001","11011","10101","10101","10001","10001","10001"],
"N": ["10001","11001","10101","10011","10001","10001","10001"],
"O": ["01110","10001","10001","10001","10001","10001","01110"],
"P": ["11110","10001","10001","11110","10000","10000","10000"],
"Q": ["01110","10001","10001","10001","10101","10010","01101"],
"R": ["11110","10001","10001","11110","10100","10010","10001"],
"S": ["01111","10000","10000","01110","00001","00001","11110"],
"T": ["11111","00100","00100","00100","00100","00100","00100"],
"U": ["10001","10001","10001","10001","10001","10001","01110"],
"V": ["10001","10001","10001","10001","10001","01010","00100"],
"W": ["10001","10001","10001","10101","10101","11011","10001"],
"X": ["10001","10001","01010","00100","01010","10001","10001"],
"Y": ["10001","10001","01010","00100","00100","00100","00100"],
"Z": ["11111","00001","00010","00100","01000","10000","11111"],
"0": ["01110","10001","10011","10101","11001","10001","01110"],
"1": ["00100","01100","00100","00100","00100","00100","01110"],
"2": ["01110","10001","00001","00010","00100","01000","11111"],
"3": ["11110","00001","00001","01110","00001","00001","11110"],
"4": ["00010","00110","01010","10010","11111","00010","00010"],
"5": ["11111","10000","10000","11110","00001","00001","11110"],
"6": ["01110","10000","10000","11110","10001","10001","01110"],
"7": ["11111","00001","00010","00100","01000","01000","01000"],
"8": ["01110","10001","10001","01110","10001","10001","01110"],
"9": ["01110","10001","10001","01111","00001","00001","01110"],
"/": ["00001","00010","00010","00100","01000","01000","10000"],
"-": ["00000","00000","00000","11111","00000","00000","00000"],
".": ["00000","00000","00000","00000","00000","00110","00110"],
"!": ["00100","00100","00100","00100","00100","00000","00100"],
"?": ["01110","10001","00001","00010","00100","00000","00100"],
"&": ["01100","10010","10100","01000","10101","10010","01101"],
":": ["00000","00110","00110","00000","00110","00110","00000"]
};
const state = {
phrase: DEFAULT_PHRASE,
selected: 2,
replacement: "R",
compare: false,
swapOld: "R",
swapNew: "R",
history: [],
sceneWidth: 17
};
const viewport = document.querySelector("#viewport");
const phraseInput = document.querySelector("#phrase");
const charStrip = document.querySelector("#charStrip");
const replacementSelect = document.querySelector("#replacement");
const selectedChar = document.querySelector("#selectedChar");
const positionLabel = document.querySelector("#positionLabel");
const charCount = document.querySelector("#charCount");
const applyButton = document.querySelector("#apply");
const compareButton = document.querySelector("#compare");
const undoButton = document.querySelector("#undo");
const voxelProof = document.querySelector("#voxelProof");
const carvedProof = document.querySelector("#carvedProof");
const toast = document.querySelector("#toast");
function cleanPhrase(value) {
return value
.toUpperCase()
.replace(/[^A-Z0-9\s/.\-&!?:]/g, " ")
.slice(0, 14);
}
function patternFor(char) {
return GLYPHS[char] || GLYPHS["?"];
}
function populateReplacementSelect() {
const groups = [
["Letters", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"],
["Numbers", "0123456789"],
["Marks", "/-&!?:."],
["Spacing", " "]
];
for (const [name, chars] of groups) {
const group = document.createElement("optgroup");
group.label = name;
for (const char of chars) {
const option = document.createElement("option");
option.value = char;
option.textContent = char === " " ? "Space" : char;
group.appendChild(option);
}
replacementSelect.appendChild(group);
}
}
populateReplacementSelect();
/* -------------------------------------------------------------------------- */
/* Three.js setup */
/* -------------------------------------------------------------------------- */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x151612);
scene.fog = new THREE.Fog(0x151612, 21, 42);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf2e7d2, 0x25342f, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe5bc, 4.2);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7fb5b6, 2.4);
rimLight.position.set(9, 6, -8);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8b52, 28, 15, 2);
warmLight.position.set(0, 4, 5);
scene.add(warmLight);
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#9a673c";
ctx.fillRect(0, 0, 256, 256);
let seed = 9127;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let i = 0; i < 180; i++) {
const y = random() * 256;
ctx.strokeStyle = random() > 0.5
? "rgba(55,28,12,0.11)"
: "rgba(255,220,155,0.09)";
ctx.lineWidth = 0.5 + random() * 2;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.bezierCurveTo(
65, y + random() * 12 - 6,
170, y + random() * 14 - 7,
256, y + random() * 8 - 4
);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.4, 1.4);
return texture;
}
const woodTexture = makeWoodTexture();
const materials = {
wood: new THREE.MeshStandardMaterial({
color: 0xb07a49,
map: woodTexture,
roughness: 0.72,
metalness: 0.02
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x5b3926,
map: woodTexture,
roughness: 0.8
}),
ink: new THREE.MeshStandardMaterial({
color: 0x173635,
roughness: 0.48,
metalness: 0.18
}),
accent: new THREE.MeshStandardMaterial({
color: 0xed7444,
roughness: 0.44,
metalness: 0.12,
emissive: 0x351208,
emissiveIntensity: 0.35
}),
cavity: new THREE.MeshStandardMaterial({
color: 0x171a17,
roughness: 0.94
}),
brass: new THREE.MeshStandardMaterial({
color: 0xbda26a,
roughness: 0.42,
metalness: 0.65
}),
floor: new THREE.MeshStandardMaterial({
color: 0x1b1d19,
roughness: 0.96,
metalness: 0
})
};
const floor = new THREE.Mesh(new THREE.PlaneGeometry(70, 45), materials.floor);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.09;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(50, 50, 0x3c4038, 0x292c26);
grid.position.y = -0.075;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const leftGroup = new THREE.Group();
const rightGroup = new THREE.Group();
const comparisonGroup = new THREE.Group();
scene.add(leftGroup, rightGroup, comparisonGroup);
let pickables = [];
let pulseLines = [];
let selectedFrame = null;
/* -------------------------------------------------------------------------- */
/* Small scene utilities */
/* -------------------------------------------------------------------------- */
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, scope = "main", width = 3.6, accent = false) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 6, 6, 756, 148, 28);
ctx.fillStyle = accent ? "rgba(237,116,68,0.92)" : "rgba(23,24,21,0.88)";
ctx.fill();
ctx.strokeStyle = accent ? "rgba(255,190,153,0.7)" : "rgba(255,255,255,0.14)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = accent ? "#241711" : "#eee8d9";
ctx.font = "700 49px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 84);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.userData.scope = scope;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 160 / 768, 1);
sprite.renderOrder = 20;
return sprite;
}
function disposeGroup(group, scope) {
group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const objectMaterials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of objectMaterials) {
if (material.map?.userData?.scope === scope) {
material.map.dispose();
material.dispose();
}
}
}
});
while (group.children.length) group.remove(group.children[0]);
}
function box(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;
return mesh;
}
function makeSelectionFrame(width, depth, y) {
const points = [
new THREE.Vector3(-width / 2, y, -depth / 2),
new THREE.Vector3( width / 2, y, -depth / 2),
new THREE.Vector3( width / 2, y, depth / 2),
new THREE.Vector3(-width / 2, y, depth / 2)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0xff9869,
transparent: true,
opacity: 0.95
});
const frame = new THREE.LineLoop(geometry, material);
frame.renderOrder = 8;
pulseLines.push(frame);
return frame;
}
/* -------------------------------------------------------------------------- */
/* Voxel movable type */
/* -------------------------------------------------------------------------- */
function createVoxelBlock(char, index, selected, mirrored = true) {
const group = new THREE.Group();
const baseWidth = 0.74;
const baseDepth = 0.78;
const pixel = 0.087;
const base = box(baseWidth, 0.22, baseDepth, materials.wood, 0, 0.11, 0);
base.userData.index = index;
group.add(base);
pickables.push(base);
if (selected) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(base.geometry),
new THREE.LineBasicMaterial({ color: 0xff9869 })
);
edges.position.copy(base.position);
group.add(edges);
}
const pattern = patternFor(char);
const voxelMaterial = selected ? materials.accent : materials.ink;
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (pattern[row][col] !== "1") continue;
const localX = mirrored ? -(col - 2) * pixel : (col - 2) * pixel;
const localZ = (row - 3) * pixel;
const voxel = box(
pixel * 0.82,
0.14,
pixel * 0.82,
voxelMaterial,
localX,
0.29,
localZ
);
group.add(voxel);
}
}
return group;
}
function buildMovableType() {
disposeGroup(leftGroup, "main");
pickables = [];
const chars = Array.from(state.phrase);
const slotWidth = 0.82;
const rowWidth = chars.length * slotWidth;
const railWidth = rowWidth + 0.58;
const rail = box(railWidth, 0.13, 1.12, materials.darkWood, 0, 0.02, 0);
leftGroup.add(rail);
leftGroup.add(box(railWidth, 0.11, 0.08, materials.brass, 0, 0.11, -0.54));
leftGroup.add(box(railWidth, 0.11, 0.08, materials.brass, 0, 0.11, 0.54));
chars.forEach((char, index) => {
const block = createVoxelBlock(char, index, index === state.selected);
block.position.x = (index - (chars.length - 1) / 2) * slotWidth;
leftGroup.add(block);
});
const label = makeLabel("01 VOXEL COMPOSITOR", "main", 4.0);
label.position.set(0, 2.35, -0.15);
leftGroup.add(label);
return railWidth;
}
/* -------------------------------------------------------------------------- */
/* Carved page matrix */
/* -------------------------------------------------------------------------- */
function buildCarvedPage() {
disposeGroup(rightGroup, "main");
const chars = Array.from(state.phrase);
const cellWidth = 0.68;
const pixel = 0.083;
const boardWidth = chars.length * cellWidth + 0.54;
const boardDepth = 0.82;
const topY = 0.43;
const bed = box(boardWidth + 0.5, 0.16, 1.38, materials.darkWood, 0, 0.02, 0);
rightGroup.add(bed);
const backing = box(boardWidth, 0.08, boardDepth, materials.cavity, 0, 0.13, 0);
rightGroup.add(backing);
const shape = new THREE.Shape();
shape.moveTo(-boardWidth / 2, -boardDepth / 2);
shape.lineTo( boardWidth / 2, -boardDepth / 2);
shape.lineTo( boardWidth / 2, boardDepth / 2);
shape.lineTo(-boardWidth / 2, boardDepth / 2);
shape.closePath();
const floorPieces = [];
const selectedSlot = { x: 0, z: 0 };
chars.forEach((char, index) => {
const pattern = patternFor(char);
// The entire line is mirrored, as required on a printing matrix.
const charCenterX = -((index - (chars.length - 1) / 2) * cellWidth);
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (pattern[row][col] !== "1") continue;
const cx = charCenterX - (col - 2) * pixel;
const cy = (3 - row) * pixel;
const half = pixel * 0.405;
const hole = new THREE.Path();
hole.moveTo(cx - half, cy - half);
hole.lineTo(cx - half, cy + half);
hole.lineTo(cx + half, cy + half);
hole.lineTo(cx + half, cy - half);
hole.closePath();
shape.holes.push(hole);
floorPieces.push({ x: cx, z: -cy });
}
}
if (index === state.selected) {
selectedSlot.x = charCenterX;
selectedSlot.z = 0;
}
});
const carvedGeometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.28,
steps: 1,
bevelEnabled: false,
curveSegments: 1
});
carvedGeometry.rotateX(-Math.PI / 2);
const carvedBoard = new THREE.Mesh(carvedGeometry, materials.wood);
carvedBoard.position.y = 0.14;
carvedBoard.castShadow = true;
carvedBoard.receiveShadow = true;
rightGroup.add(carvedBoard);
for (const piece of floorPieces) {
const cavity = new THREE.Mesh(
new THREE.PlaneGeometry(pixel * 0.80, pixel * 0.80),
materials.cavity
);
cavity.rotation.x = -Math.PI / 2;
cavity.position.set(piece.x, 0.173, piece.z);
rightGroup.add(cavity);
}
const frame = makeSelectionFrame(cellWidth * 0.72, 0.63, topY + 0.025);
frame.position.x = selectedSlot.x;
frame.position.z = selectedSlot.z;
rightGroup.add(frame);
selectedFrame = frame;
// Invisible character hit areas let the user select directly on the page.
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
chars.forEach((char, index) => {
const centerX = -((index - (chars.length - 1) / 2) * cellWidth);
const hit = new THREE.Mesh(
new THREE.BoxGeometry(cellWidth * 0.76, 0.14, 0.65),
hitMaterial
);
hit.position.set(centerX, topY + 0.07, 0);
hit.userData.index = index;
rightGroup.add(hit);
pickables.push(hit);
});
// A simplified traditional press frame behind the matrix.
const postX = boardWidth / 2 + 0.15;
rightGroup.add(box(0.18, 1.75, 0.2, materials.darkWood, -postX, 0.95, -0.88));
rightGroup.add(box(0.18, 1.75, 0.2, materials.darkWood, postX, 0.95, -0.88));
rightGroup.add(box(boardWidth + 0.55, 0.2, 0.28, materials.wood, 0, 1.85, -0.88));
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 1.15, 18),
materials.brass
);
screw.position.set(0, 1.32, -0.88);
screw.castShadow = true;
rightGroup.add(screw);
const handle = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.78, 14),
materials.brass
);
handle.rotation.z = Math.PI / 2;
handle.position.set(0, 1.91, -0.88);
rightGroup.add(handle);
const label = makeLabel("02 CARVED PAGE MATRIX", "main", 4.25);
label.position.set(0, 2.5, -0.4);
rightGroup.add(label);
return boardWidth;
}
/* -------------------------------------------------------------------------- */
/* Before / after comparison pieces */
/* -------------------------------------------------------------------------- */
function createMiniVoxel(char, colorMaterial) {
const group = new THREE.Group();
const pixel = 0.066;
group.add(box(0.64, 0.12, 0.64, materials.wood, 0, 0.06, 0));
const pattern = patternFor(char);
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (pattern[row][col] !== "1") continue;
group.add(
box(
pixel * 0.8,
0.12,
pixel * 0.8,
colorMaterial,
-(col - 2) * pixel,
0.18,
(row - 3) * pixel
)
);
}
}
return group;
}
function createMiniCarved(char, after = false) {
const group = new THREE.Group();
const pixel = 0.067;
const size = 0.62;
group.add(box(size, 0.07, size, materials.cavity, 0, 0.035, 0));
const shape = new THREE.Shape();
shape.moveTo(-size / 2, -size / 2);
shape.lineTo(size / 2, -size / 2);
shape.lineTo(size / 2, size / 2);
shape.lineTo(-size / 2, size / 2);
shape.closePath();
const floors = [];
const pattern = patternFor(char);
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (pattern[row][col] !== "1") continue;
const cx = -(col - 2) * pixel;
const cy = (3 - row) * pixel;
const half = pixel * 0.39;
const hole = new THREE.Path();
hole.moveTo(cx - half, cy - half);
hole.lineTo(cx - half, cy + half);
hole.lineTo(cx + half, cy + half);
hole.lineTo(cx + half, cy - half);
hole.closePath();
shape.holes.push(hole);
floors.push({ x: cx, z: -cy });
}
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.15,
steps: 1,
bevelEnabled: false,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
const top = new THREE.Mesh(geometry, materials.wood);
top.position.y = 0.075;
top.castShadow = true;
group.add(top);
const floorMaterial = after ? materials.accent : materials.cavity;
for (const piece of floors) {
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(pixel * 0.76, pixel * 0.76),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(piece.x, 0.073, piece.z);
group.add(floor);
}
return group;
}
function buildComparison() {
disposeGroup(comparisonGroup, "compare");
comparisonGroup.add(box(4.8, 0.11, 1.12, materials.darkWood, 0, 0.0, 0));
const oldMaterial = new THREE.MeshStandardMaterial({
color: 0x73b6aa,
roughness: 0.48,
metalness: 0.12
});
const newMaterial = new THREE.MeshStandardMaterial({
color: 0xed7444,
roughness: 0.44,
metalness: 0.12
});
const pieces = [
{ x: -1.8, label: "BEFORE · VOXEL", object: createMiniVoxel(state.swapOld, oldMaterial) },
{ x: -0.6, label: "AFTER · VOXEL", object: createMiniVoxel(state.swapNew, newMaterial) },
{ x: 0.6, label: "BEFORE · CARVED", object: createMiniCarved(state.swapOld, false) },
{ x: 1.8, label: "AFTER · CARVED", object: createMiniCarved(state.swapNew, true) }
];
for (const piece of pieces) {
piece.object.position.set(piece.x, 0.06, 0);
comparisonGroup.add(piece.object);
const label = makeLabel(piece.label, "compare", 1.35, piece.label.startsWith("AFTER"));
label.position.set(piece.x, 0.83, 0);
comparisonGroup.add(label);
}
comparisonGroup.position.set(0, 0.03, 4.15);
comparisonGroup.visible = state.compare;
}
/* -------------------------------------------------------------------------- */
/* UI and scene rebuild */
/* -------------------------------------------------------------------------- */
function updateCharStrip() {
charStrip.replaceChildren();
Array.from(state.phrase).forEach((char, index) => {
const button = document.createElement("button");
button.className = "char-button" + (index === state.selected ? " selected" : "");
button.textContent = char === " " ? "␣" : char;
button.setAttribute("aria-label", `Select character ${index + 1}: ${char}`);
button.setAttribute("aria-pressed", String(index === state.selected));
button.addEventListener("click", () => selectCharacter(index));
charStrip.appendChild(button);
});
}
function updateProof(target) {
target.replaceChildren();
Array.from(state.phrase).forEach((char, index) => {
const span = document.createElement("span");
span.textContent = char === " " ? "\u00a0" : char;
if (index === state.selected) span.className = "selected";
target.appendChild(span);
});
}
function updateControls() {
const chars = Array.from(state.phrase);
const current = chars[state.selected] ?? " ";
selectedChar.textContent = current === " " ? "␣" : current;
positionLabel.textContent = `Position ${String(state.selected + 1).padStart(2, "0")}`;
charCount.textContent = `${chars.length} character${chars.length === 1 ? "" : "s"}`;
if ([...replacementSelect.options].some(option => option.value === state.replacement)) {
replacementSelect.value = state.replacement;
}
applyButton.disabled = current === state.replacement;
undoButton.disabled = state.history.length === 0;
compareButton.classList.toggle("active", state.compare);
compareButton.setAttribute("aria-pressed", String(state.compare));
compareButton.textContent = state.compare ? "Hide comparison" : "Compare pieces";
updateCharStrip();
updateProof(voxelProof);
updateProof(carvedProof);
}
function rebuildAll() {
pulseLines = [];
selectedFrame = null;
const leftWidth = buildMovableType();
const rightWidth = buildCarvedPage();
const gap = 1.2;
const total = leftWidth + gap + rightWidth;
state.sceneWidth = total;
leftGroup.position.x = -total / 2 + leftWidth / 2;
rightGroup.position.x = -total / 2 + leftWidth + gap + rightWidth / 2;
buildComparison();
updateControls();
}
function selectCharacter(index) {
state.selected = Math.max(0, Math.min(index, Array.from(state.phrase).length - 1));
const current = Array.from(state.phrase)[state.selected] ?? " ";
state.replacement = current;
state.swapOld = current;
state.swapNew = current;
rebuildAll();
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => toast.classList.remove("show"), 2700);
}
function applyReplacement() {
const chars = Array.from(state.phrase);
const oldChar = chars[state.selected];
const newChar = state.replacement;
if (oldChar === newChar) return;
state.history.push({
phrase: state.phrase,
selected: state.selected
});
chars[state.selected] = newChar;
state.phrase = chars.join("");
phraseInput.value = state.phrase;
state.swapOld = oldChar;
state.swapNew = newChar;
state.compare = true;
rebuildAll();
showToast(`Symbol ${state.selected + 1} replaced in both setups · proofs still match`);
}
function undoEdit() {
const previous = state.history.pop();
if (!previous) return;
state.phrase = previous.phrase;
state.selected = previous.selected;
const current = Array.from(state.phrase)[state.selected] ?? " ";
state.replacement = current;
state.swapOld = current;
state.swapNew = current;
phraseInput.value = state.phrase;
rebuildAll();
showToast("Last symbol edit undone");
}
/* -------------------------------------------------------------------------- */
/* Camera controls implemented without add-ons */
/* -------------------------------------------------------------------------- */
const cameraState = {
target: new THREE.Vector3(0, 0.65, 0.35),
radius: 20,
theta: -0.04,
phi: 1.02
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.radius = Math.max(17, state.sceneWidth * 1.02 + 3.8);
cameraState.theta = -0.04;
cameraState.phi = 1.02;
cameraState.target.set(0, 0.65, 0.35);
updateCamera();
}
const pointer = {
down: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
id: null
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
pointer.down = true;
pointer.moved = false;
pointer.startX = pointer.lastX = event.clientX;
pointer.startY = pointer.lastY = event.clientY;
pointer.id = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.down) {
renderer.domElement.style.cursor = hitTest(event.clientX, event.clientY) ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
if (Math.hypot(event.clientX - pointer.startX, event.clientY - pointer.startY) > 4) {
pointer.moved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.005, 0.48, 1.36);
cameraState.theta = THREE.MathUtils.clamp(cameraState.theta, -1.15, 1.15);
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointer.moved) {
const hit = hitTest(event.clientX, event.clientY);
if (hit) selectCharacter(hit.object.userData.index);
}
pointer.down = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
31
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
function hitTest(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0] : null;
}
/* -------------------------------------------------------------------------- */
/* UI events */
/* -------------------------------------------------------------------------- */
phraseInput.addEventListener("input", () => {
const cleaned = cleanPhrase(phraseInput.value);
phraseInput.value = cleaned;
state.phrase = cleaned || " ";
state.selected = Math.min(
state.selected,
Math.max(0, Array.from(state.phrase).length - 1)
);
const current = Array.from(state.phrase)[state.selected] ?? " ";
state.replacement = current;
state.swapOld = current;
state.swapNew = current;
rebuildAll();
});
replacementSelect.addEventListener("change", () => {
state.replacement = replacementSelect.value;
state.swapNew = state.replacement;
buildComparison();
updateControls();
});
applyButton.addEventListener("click", applyReplacement);
undoButton.addEventListener("click", undoEdit);
compareButton.addEventListener("click", () => {
state.compare = !state.compare;
comparisonGroup.visible = state.compare;
updateControls();
});
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
document.querySelector("#resetEdit").addEventListener("click", () => {
state.phrase = DEFAULT_PHRASE;
state.selected = 2;
state.replacement = "R";
state.swapOld = "R";
state.swapNew = "R";
state.history = [];
phraseInput.value = DEFAULT_PHRASE;
rebuildAll();
resetCamera();
showToast("Print study reset");
});
/* -------------------------------------------------------------------------- */
/* Resize and animation */
/* -------------------------------------------------------------------------- */
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
rebuildAll();
resetCamera();
resize();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
for (const line of pulseLines) {
if (line.material) {
line.material.opacity = 0.72 + Math.sin(elapsed * 3.3) * 0.22;
}
}
if (state.compare) {
comparisonGroup.position.y = 0.03 + Math.sin(elapsed * 1.7) * 0.018;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```