Prompt specification
Build or customize the Three.js 3D scene "Movable type line in a composing stick" 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: Movable type line in a composing stick
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/movable-type-line-in-a-composing-stick-x2337
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows movable type for early printed news sheets. Build a short line of mirrored type blocks held in a composing stick. Use neutral letters and expose how separate pieces combine into one printable line. Stylized solid forms.
Working Three.js Starter (movable-type-line-in-a-composing-stick-x2337):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Movable Type — The Composing Stick</title>
<style>
:root {
--ink: #252b29;
--muted: #66675f;
--paper: #eee6d4;
--panel: rgba(247, 241, 225, 0.88);
--line: rgba(37, 43, 41, 0.18);
--accent: #a45e35;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7deca;
color: var(--ink);
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.story {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4vw, 58px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.story p {
max-width: 340px;
margin: 17px 0 0;
color: #55584f;
font-size: 13px;
line-height: 1.65;
}
.controls {
position: fixed;
z-index: 6;
top: 28px;
right: 28px;
width: 282px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 5px;
background: var(--panel);
box-shadow:
0 18px 55px rgba(53, 44, 30, 0.12),
inset 0 0 0 1px rgba(37, 43, 41, 0.05);
backdrop-filter: blur(13px);
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 18px;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
}
.control-heading strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
.control-heading span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
font-size: 11px;
font-weight: 700;
}
output {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0 0 17px;
accent-color: var(--accent);
cursor: pointer;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 39px;
padding: 9px 11px;
border: 1px solid rgba(37, 43, 41, 0.2);
border-radius: 3px;
background: rgba(255, 255, 255, 0.38);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: var(--ink);
color: #f5eddb;
transform: translateY(-1px);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
button.primary {
border-color: var(--ink);
background: var(--ink);
color: #f5eddb;
}
button.primary:hover {
background: var(--accent);
border-color: var(--accent);
}
.reset-button {
width: 100%;
min-height: 32px;
margin-top: 8px;
border-color: transparent;
background: transparent;
color: var(--muted);
}
.legend {
position: fixed;
z-index: 5;
left: 34px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 9px;
max-width: min(660px, calc(100vw - 68px));
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(37, 43, 41, 0.11);
border-radius: 3px;
background: rgba(246, 239, 222, 0.78);
color: #5e6159;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
backdrop-filter: blur(8px);
}
.legend-item b {
color: var(--accent);
font-size: 9px;
letter-spacing: 0.12em;
}
.world-label {
position: fixed;
z-index: 4;
padding: 6px 8px;
border: 1px solid rgba(37, 43, 41, 0.15);
border-radius: 2px;
background: rgba(244, 236, 216, 0.8);
color: #51564f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(5px);
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 24px;
background: rgba(37, 43, 41, 0.35);
}
.world-label::before {
content: "";
position: absolute;
top: calc(100% + 23px);
left: calc(50% - 2px);
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
}
#hint {
position: fixed;
z-index: 5;
right: 30px;
bottom: 29px;
max-width: 330px;
color: #64675e;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
text-align: right;
pointer-events: none;
}
@media (max-width: 820px) {
.story {
top: 20px;
left: 20px;
max-width: 250px;
}
.story p {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
width: 240px;
padding: 13px;
}
.legend {
display: none;
}
#hint {
right: auto;
bottom: 18px;
left: 20px;
max-width: 180px;
text-align: left;
}
.world-label {
display: none;
}
}
@media (max-width: 520px) {
h1 {
font-size: 34px;
}
.controls {
width: calc(100vw - 28px);
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional model of movable type in a composing stick"
></canvas>
<header class="story">
<div class="eyebrow">Object Study · Movable Type</div>
<h1>News, set<br />by hand.</h1>
<p>
Each cast-metal sort carries a reversed face. Set the separate pieces
into a composing stick, then transfer the assembled line to the sheet.
</p>
</header>
<section class="controls" aria-label="Scene controls">
<div class="control-heading">
<strong>Composing stick</strong>
<span>Four sorts</span>
</div>
<label class="range-label" for="separation">
<span>Separate the pieces</span>
<output id="separationValue">0%</output>
</label>
<input
id="separation"
type="range"
min="0"
max="100"
value="0"
aria-label="Separate the individual type blocks"
/>
<div class="button-row">
<button id="topView" type="button">Top view</button>
<button id="printLine" class="primary" type="button">Make impression</button>
</div>
<button id="reset" class="reset-button" type="button">Reset arrangement</button>
</section>
<div class="legend" aria-hidden="true">
<div class="legend-item"><b>01</b> Drag the blocks to reorder</div>
<div class="legend-item"><b>02</b> Examine the reversed faces</div>
<div class="legend-item"><b>03</b> Make a readable impression</div>
</div>
<div id="mirrorLabel" class="world-label">Mirrored relief</div>
<div id="proofLabel" class="world-label">Readable impression</div>
<div id="hint">Drag the type blocks · drag the background to orbit · scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const separationInput = document.querySelector("#separation");
const separationValue = document.querySelector("#separationValue");
const topViewButton = document.querySelector("#topView");
const printButton = document.querySelector("#printLine");
const resetButton = document.querySelector("#reset");
const hint = document.querySelector("#hint");
const mirrorLabel = document.querySelector("#mirrorLabel");
const proofLabel = document.querySelector("#proofLabel");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7deca);
scene.fog = new THREE.Fog(0xe7deca, 18, 34);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0.35, 0.15, 0);
const cameraDesired = {
theta: 0.43,
phi: 0.83,
radius: 14.1
};
const cameraActual = {
theta: 0.43,
phi: 0.83,
radius: 14.1
};
const hemisphere = new THREE.HemisphereLight(0xfff7e6, 0x776b58, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd2, 3.3);
keyLight.position.set(-4, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9cad7, 1.25);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const tableMaterial = new THREE.MeshStandardMaterial({
color: 0xd5c6aa,
roughness: 0.98,
metalness: 0
});
const table = new THREE.Mesh(
new THREE.PlaneGeometry(34, 26),
tableMaterial
);
table.rotation.x = -Math.PI / 2;
table.position.y = -0.12;
table.receiveShadow = true;
scene.add(table);
function makeBox(width, height, depth, material, x, y, z, parent) {
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;
}
// -------------------------------------------------------------------------
// Composing stick
// -------------------------------------------------------------------------
const composingStick = new THREE.Group();
scene.add(composingStick);
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x454b4d,
roughness: 0.66,
metalness: 0.48
});
const darkSteelMaterial = new THREE.MeshStandardMaterial({
color: 0x292f30,
roughness: 0.72,
metalness: 0.5
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb18a4d,
roughness: 0.44,
metalness: 0.72
});
// Main bed.
makeBox(6.1, 0.24, 1.58, steelMaterial, -1.7, 0.03, 0, composingStick);
// Inset track on the bed.
makeBox(5.55, 0.035, 0.68, darkSteelMaterial, -1.62, 0.165, 0, composingStick);
// Side walls that keep the sorts in a channel.
makeBox(5.75, 0.2, 0.11, steelMaterial, -1.72, 0.22, -0.735, composingStick);
makeBox(5.75, 0.2, 0.11, steelMaterial, -1.72, 0.22, 0.735, composingStick);
// Fixed back wall.
makeBox(0.18, 0.72, 1.48, steelMaterial, -4.47, 0.43, 0, composingStick);
makeBox(0.24, 0.08, 1.54, darkSteelMaterial, -4.47, 0.79, 0, composingStick);
// Sliding end stop.
const endStop = new THREE.Group();
composingStick.add(endStop);
makeBox(0.16, 0.58, 1.33, steelMaterial, 0, 0.39, 0, endStop);
makeBox(0.22, 0.07, 1.4, darkSteelMaterial, 0, 0.69, 0, endStop);
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.31, 20),
brassMaterial
);
screw.rotation.x = Math.PI / 2;
screw.position.set(0, 0.35, -0.82);
screw.castShadow = true;
endStop.add(screw);
const knob = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.2, 24),
brassMaterial
);
knob.rotation.x = Math.PI / 2;
knob.position.set(0, 0.35, -0.99);
knob.castShadow = true;
endStop.add(knob);
// Small indexing marks on the near rail.
const indexMarkMaterial = new THREE.MeshStandardMaterial({
color: 0xc2b48f,
roughness: 0.65,
metalness: 0.35
});
for (let i = 0; i < 9; i++) {
makeBox(
0.025,
0.018,
i % 2 === 0 ? 0.15 : 0.09,
indexMarkMaterial,
-3.95 + i * 0.53,
0.329,
0.737,
composingStick
);
}
// -------------------------------------------------------------------------
// Type sorts
// -------------------------------------------------------------------------
const patterns = {
N: [
"10001",
"11001",
"11001",
"10101",
"10011",
"10011",
"10001"
],
E: [
"11111",
"10000",
"10000",
"11110",
"10000",
"10000",
"11111"
],
W: [
"10001",
"10001",
"10001",
"10101",
"10101",
"11011",
"01010"
],
S: [
"01111",
"10000",
"10000",
"01110",
"00001",
"00001",
"11110"
]
};
const reliefGeometry = new THREE.BoxGeometry(0.071, 0.055, 0.071);
const reliefMaterial = new THREE.MeshStandardMaterial({
color: 0x969b94,
roughness: 0.58,
metalness: 0.52
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xd5d2c4,
transparent: true,
opacity: 0.22
});
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const blocks = [];
const hitboxes = [];
function addPixelLetter(parent, character, cellSize, y, zCenter, mirrored) {
const pattern = patterns[character];
for (let row = 0; row < pattern.length; row++) {
for (let column = 0; column < pattern[row].length; column++) {
if (pattern[row][column] !== "1") continue;
const xOffset = (column - 2) * cellSize;
const pixel = new THREE.Mesh(reliefGeometry, reliefMaterial);
pixel.position.set(
mirrored ? -xOffset : xOffset,
y,
zCenter - (3 - row) * cellSize
);
pixel.castShadow = true;
pixel.receiveShadow = true;
parent.add(pixel);
}
}
}
function createBlock(character, index) {
const group = new THREE.Group();
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: [0x505657, 0x595e5d, 0x484e50, 0x626664][index],
roughness: 0.76,
metalness: 0.38
});
const body = makeBox(
0.76,
0.4,
0.78,
bodyMaterial,
0,
0.35,
0,
group
);
const bodyEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
edgeMaterial
);
body.add(bodyEdges);
const shoulder = makeBox(
0.66,
0.1,
0.68,
bodyMaterial,
0,
0.6,
0,
group
);
const shoulderEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(shoulder.geometry),
edgeMaterial
);
shoulder.add(shoulderEdges);
// A small groove on the visible side indicates the base of the type.
makeBox(
0.38,
0.026,
0.025,
darkSteelMaterial,
0,
0.225,
0.399,
group
);
// Relief is mirrored horizontally.
addPixelLetter(group, character, 0.083, 0.678, 0, true);
const hitbox = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 0.72, 0.84),
hitMaterial
);
hitbox.position.set(0, 0.39, 0);
group.add(hitbox);
const block = {
character,
group,
hitbox,
slot: index,
targetX: 0
};
hitbox.userData.block = block;
blocks.push(block);
hitboxes.push(hitbox);
return block;
}
["N", "E", "W", "S"].forEach(createBlock);
// -------------------------------------------------------------------------
// Newspaper proof sheet
// -------------------------------------------------------------------------
function createPaperTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 1024;
textureCanvas.height = 1280;
const context = textureCanvas.getContext("2d");
context.fillStyle = "#efe5cd";
context.fillRect(0, 0, 1024, 1280);
// Deterministic paper grain.
let seed = 1729;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 4200; i++) {
const alpha = 0.018 + random() * 0.025;
context.fillStyle = `rgba(75, 58, 36, ${alpha})`;
const size = random() * 2.2 + 0.4;
context.fillRect(
random() * 1024,
random() * 1280,
size,
size
);
}
// Fine border.
context.strokeStyle = "rgba(59, 51, 38, 0.48)";
context.lineWidth = 3;
context.strokeRect(43, 42, 938, 1196);
context.lineWidth = 1;
context.strokeRect(53, 52, 918, 1176);
// Restrained folio marks.
context.fillStyle = "rgba(45, 40, 31, 0.35)";
context.fillRect(760, 84, 170, 3);
context.fillRect(760, 94, 125, 2);
context.strokeStyle = "rgba(54, 48, 37, 0.36)";
context.lineWidth = 2;
context.beginPath();
context.moveTo(82, 302);
context.lineTo(942, 302);
context.stroke();
// Three columns of generic old-news texture.
const columnWidth = 240;
const columnGap = 50;
for (let column = 0; column < 3; column++) {
const x = 92 + column * (columnWidth + columnGap);
context.fillStyle = "rgba(40, 36, 29, 0.68)";
context.fillRect(x, 345, columnWidth, 11);
for (let y = 391; y < 1162; y += 17) {
const length = 70 + random() * (columnWidth - 28);
context.fillStyle = `rgba(54, 49, 39, ${0.22 + random() * 0.12})`;
context.fillRect(x, y, length, 3);
}
// Small broken column divisions.
if (column < 2) {
context.fillStyle = "rgba(55, 49, 38, 0.12)";
context.fillRect(x + columnWidth + 18, 340, 2, 815);
}
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const paper = new THREE.Group();
paper.position.set(3.7, -0.02, 0.05);
paper.rotation.y = -0.075;
scene.add(paper);
const paperMaterial = new THREE.MeshStandardMaterial({
color: 0xeee3ca,
roughness: 1,
metalness: 0
});
const paperBody = makeBox(
5.15,
0.08,
6.05,
paperMaterial,
0,
0,
0,
paper
);
paperBody.castShadow = false;
const printedPaperMaterial = new THREE.MeshStandardMaterial({
map: createPaperTexture(),
roughness: 1,
metalness: 0,
polygonOffset: true,
polygonOffsetFactor: -1
});
const printedPaper = new THREE.Mesh(
new THREE.PlaneGeometry(5.0, 5.9),
printedPaperMaterial
);
printedPaper.rotation.x = -Math.PI / 2;
printedPaper.position.y = 0.041;
printedPaper.receiveShadow = true;
paper.add(printedPaper);
const proofGroup = new THREE.Group();
paper.add(proofGroup);
const proofMaterial = new THREE.MeshStandardMaterial({
color: 0x24231e,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.18
});
const proofPixelGeometry = new THREE.BoxGeometry(0.084, 0.016, 0.084);
function addReadableLetter(parent, character, letterIndex, totalLetters) {
const letter = new THREE.Group();
const spacing = 0.62;
const cellSize = 0.084;
const startX =
(letterIndex - (totalLetters - 1) / 2) * spacing;
for (let row = 0; row < patterns[character].length; row++) {
for (let column = 0; column < patterns[character][row].length; column++) {
if (patterns[character][row][column] !== "1") continue;
const pixel = new THREE.Mesh(proofPixelGeometry, proofMaterial);
pixel.position.set(
startX + (column - 2) * cellSize,
0.057,
-2.17 - (3 - row) * cellSize
);
letter.add(pixel);
}
}
parent.add(letter);
}
let proofOpacity = 0.18;
function rebuildProof() {
proofGroup.clear();
const orderedBlocks = [...blocks].sort((a, b) => a.slot - b.slot);
orderedBlocks.forEach((block, index) => {
addReadableLetter(
proofGroup,
block.character,
index,
orderedBlocks.length
);
});
proofMaterial.opacity = proofOpacity;
}
rebuildProof();
const proofAnchor = new THREE.Object3D();
proofAnchor.position.set(0, 0.12, -2.08);
paper.add(proofAnchor);
// -------------------------------------------------------------------------
// Type placement and interaction
// -------------------------------------------------------------------------
let separation = 0;
let draggingBlock = null;
let orbiting = false;
let previousPointer = { x: 0, y: 0 };
let dragOffset = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.66);
const dragPoint = new THREE.Vector3();
function updatePointer(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function updateBlockTargets() {
for (const block of blocks) {
const centeredSlot = block.slot - 1.5;
block.targetX =
-2 +
centeredSlot * 0.88 +
centeredSlot * 0.35 * separation;
}
}
updateBlockTargets();
function beginBlockDrag(block, event) {
draggingBlock = block;
canvas.setPointerCapture(event.pointerId);
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
dragOffset = block.group.position.x - dragPoint.x;
}
hint.textContent =
"Release the sort to settle it into the composing line.";
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
updatePointer(event);
const hits = raycaster.intersectObjects(hitboxes, false);
if (hits.length > 0) {
beginBlockDrag(hits[0].object.userData.block, event);
} else {
orbiting = true;
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointermove", event => {
if (draggingBlock) {
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
draggingBlock.group.position.x = THREE.MathUtils.clamp(
dragPoint.x + dragOffset,
-4.08,
0.12
);
}
} else if (orbiting) {
const deltaX = event.clientX - previousPointer.x;
const deltaY = event.clientY - previousPointer.y;
cameraDesired.theta = THREE.MathUtils.clamp(
cameraDesired.theta - deltaX * 0.005,
-1.25,
1.25
);
cameraDesired.phi = THREE.MathUtils.clamp(
cameraDesired.phi - deltaY * 0.005,
0.18,
1.32
);
previousPointer = { x: event.clientX, y: event.clientY };
}
});
function finishPointerInteraction(event) {
if (draggingBlock) {
const orderedBlocks = [...blocks].sort(
(a, b) => a.group.position.x - b.group.position.x
);
orderedBlocks.forEach((block, index) => {
block.slot = index;
});
draggingBlock = null;
updateBlockTargets();
rebuildProof();
hint.textContent =
"The separate sorts now form one line · make an impression to read it forward";
}
orbiting = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", finishPointerInteraction);
canvas.addEventListener("pointercancel", finishPointerInteraction);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraDesired.radius = THREE.MathUtils.clamp(
cameraDesired.radius * Math.exp(event.deltaY * 0.001),
9,
21
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraDesired.theta = 0.43;
cameraDesired.phi = 0.83;
cameraDesired.radius = 14.1;
});
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
separationInput.addEventListener("input", () => {
separation = Number(separationInput.value) / 100;
separationValue.textContent = `${separationInput.value}%`;
updateBlockTargets();
});
let isTopView = false;
topViewButton.addEventListener("click", () => {
isTopView = !isTopView;
if (isTopView) {
cameraDesired.theta = 0;
cameraDesired.phi = 0.19;
cameraDesired.radius = 13.2;
topViewButton.textContent = "Oblique view";
} else {
cameraDesired.theta = 0.43;
cameraDesired.phi = 0.83;
cameraDesired.radius = 14.1;
topViewButton.textContent = "Top view";
}
});
let printElapsed = 1;
let printStartOpacity = proofOpacity;
let printing = false;
printButton.addEventListener("click", () => {
printStartOpacity = proofOpacity;
printElapsed = 0;
printing = true;
printButton.textContent = "Printing…";
hint.textContent =
"The reversed type faces transfer as a forward-reading impression.";
});
resetButton.addEventListener("click", () => {
separation = 0;
separationInput.value = 0;
separationValue.textContent = "0%";
["N", "E", "W", "S"].forEach((character, index) => {
blocks.find(block => block.character === character).slot = index;
});
updateBlockTargets();
rebuildProof();
proofOpacity = 0.18;
proofMaterial.opacity = proofOpacity;
printing = false;
printElapsed = 1;
printButton.textContent = "Make impression";
cameraDesired.theta = 0.43;
cameraDesired.phi = 0.83;
cameraDesired.radius = 14.1;
isTopView = false;
topViewButton.textContent = "Top view";
hint.textContent =
"Drag the type blocks · drag the background to orbit · scroll to zoom";
});
// -------------------------------------------------------------------------
// Camera and animation
// -------------------------------------------------------------------------
function updateCamera(delta) {
cameraActual.theta = THREE.MathUtils.damp(
cameraActual.theta,
cameraDesired.theta,
8,
delta
);
cameraActual.phi = THREE.MathUtils.damp(
cameraActual.phi,
cameraDesired.phi,
8,
delta
);
cameraActual.radius = THREE.MathUtils.damp(
cameraActual.radius,
cameraDesired.radius,
8,
delta
);
const sinPhi = Math.sin(cameraActual.phi);
camera.position.set(
cameraTarget.x +
cameraActual.radius * sinPhi * Math.sin(cameraActual.theta),
cameraTarget.y + cameraActual.radius * Math.cos(cameraActual.phi),
cameraTarget.z +
cameraActual.radius * sinPhi * Math.cos(cameraActual.theta)
);
camera.lookAt(cameraTarget);
}
const projected = new THREE.Vector3();
function placeWorldLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight - 34}px`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
for (const block of blocks) {
if (draggingBlock !== block) {
block.group.position.x = THREE.MathUtils.damp(
block.group.position.x,
block.targetX,
8.5,
delta
);
}
block.group.position.y = THREE.MathUtils.damp(
block.group.position.y,
draggingBlock === block ? 0.12 : 0,
10,
delta
);
block.group.position.z = THREE.MathUtils.damp(
block.group.position.z,
0,
9,
delta
);
block.group.rotation.y = THREE.MathUtils.damp(
block.group.rotation.y,
0,
9,
delta
);
}
// The adjustable end stop follows the right edge of the composed line.
const rightEdge = Math.max(
...blocks.map(block => block.group.position.x + 0.38)
);
endStop.position.x = THREE.MathUtils.damp(
endStop.position.x,
rightEdge + 0.39,
8,
delta
);
if (printing) {
printElapsed = Math.min(printElapsed + delta / 1.15, 1);
const eased = 1 - Math.pow(1 - printElapsed, 3);
proofOpacity = THREE.MathUtils.lerp(
printStartOpacity,
1,
eased
);
proofMaterial.opacity = proofOpacity;
proofGroup.position.y =
-Math.sin(printElapsed * Math.PI) * 0.012;
if (printElapsed >= 1) {
printing = false;
printButton.textContent = "Print again";
hint.textContent =
"Impression made · each separate, reversed sort now reads forward";
}
}
placeWorldLabel(
mirrorLabel,
blocks[0].group.position.clone().add(
new THREE.Vector3(0, 0.93, 0)
)
);
const proofWorld = proofAnchor.getWorldPosition(
new THREE.Vector3()
);
placeWorldLabel(proofLabel, proofWorld);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
animate();
</script>
</body>
</html>
```