Prompt specification
Build or customize the Three.js 3D scene "Composing and replacing a single word" 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: Composing and replacing a single word
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/composing-and-replacing-a-single-word-x2514
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows reusable movable type for printing. Animate a printer arranging a short original phrase from type blocks. Replace one word while preserving surrounding blocks to demonstrate editing through reusable components. Low-poly.
Working Three.js Starter (composing-and-replacing-a-single-word-x2514):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Movable Type — Reusable Components</title>
<style>
:root {
--ink: #263238;
--paper: #f3ead4;
--accent: #d76249;
--gold: #d9a441;
--green: #6da26d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e5d8bd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(38, 50, 56, 0.22);
border-radius: 3px 18px 3px 18px;
background: rgba(246, 238, 219, 0.9);
box-shadow: 0 14px 40px rgba(54, 43, 25, 0.13);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 8px;
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(29px, 4vw, 43px);
font-weight: 700;
letter-spacing: -0.035em;
line-height: 0.95;
}
.title-card p {
margin: 12px 0 0;
max-width: 330px;
color: rgba(38, 50, 56, 0.75);
font-size: 12px;
line-height: 1.55;
}
.metrics {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
}
.metric {
min-width: 108px;
padding: 11px 13px;
border: 1px solid rgba(38, 50, 56, 0.2);
border-radius: 12px;
background: rgba(246, 238, 219, 0.86);
box-shadow: 0 10px 28px rgba(54, 43, 25, 0.1);
backdrop-filter: blur(10px);
}
.metric strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
line-height: 1;
}
.metric span {
display: block;
margin-top: 5px;
color: rgba(38, 50, 56, 0.65);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control-card {
position: absolute;
right: 24px;
bottom: 24px;
width: min(500px, calc(100vw - 48px));
padding: 16px;
border: 1px solid rgba(38, 50, 56, 0.22);
border-radius: 16px 3px 16px 3px;
background: rgba(246, 238, 219, 0.92);
box-shadow: 0 16px 45px rgba(54, 43, 25, 0.16);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.stage-row {
display: grid;
grid-template-columns: 35px 1fr auto;
align-items: center;
gap: 11px;
}
.stage-number {
display: grid;
width: 32px;
height: 32px;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: var(--paper);
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
}
#stage-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 700;
}
#clock {
color: rgba(38, 50, 56, 0.58);
font-size: 10px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.08em;
}
#stage-detail {
min-height: 30px;
margin: 9px 0 11px 43px;
color: rgba(38, 50, 56, 0.72);
font-size: 11px;
line-height: 1.45;
}
.progress-track {
height: 4px;
overflow: hidden;
border-radius: 999px;
background: rgba(38, 50, 56, 0.13);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), var(--gold));
transition: width 80ms linear;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 13px;
flex-wrap: wrap;
}
button {
appearance: none;
border: 0;
border-radius: 8px;
padding: 10px 12px;
background: var(--ink);
color: var(--paper);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.045em;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
background: #3a4b52;
transform: translateY(-1px);
}
button.accent {
background: var(--accent);
}
button.accent:hover {
background: #b94e38;
}
button.ghost {
border: 1px solid rgba(38, 50, 56, 0.2);
background: transparent;
color: var(--ink);
}
.camera-hint {
position: absolute;
bottom: 27px;
left: 25px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(38, 50, 56, 0.78);
color: rgba(255, 255, 255, 0.88);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e5d8bd;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-mark {
text-align: center;
}
.loading-mark strong {
display: block;
margin-bottom: 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
}
.loading-mark span {
color: rgba(38, 50, 56, 0.65);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.title-card p {
display: none;
}
.metrics {
top: 116px;
right: 14px;
}
.metric {
min-width: auto;
padding: 8px 10px;
}
.metric strong {
font-size: 17px;
}
.metric span {
font-size: 7px;
}
.control-card {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.camera-hint {
display: none;
}
#stage-detail {
margin-left: 0;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated low-poly movable type printer"></canvas>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Procedural printing study</div>
<h1>Movable Type</h1>
<p>
A compositor arranges reusable letter blocks, prints an original phrase,
then replaces one word without disturbing the surrounding type.
</p>
</section>
<div class="metrics" aria-label="Animation statistics">
<div class="metric">
<strong>13</strong>
<span>Type blocks</span>
</div>
<div class="metric">
<strong>5</strong>
<span>Word replaced</span>
</div>
<div class="metric">
<strong>8</strong>
<span>Blocks preserved</span>
</div>
</div>
<section class="control-card">
<div class="stage-row">
<div class="stage-number" id="stage-number">1</div>
<h2 id="stage-title">Loading the type case</h2>
<div id="clock">00:00</div>
</div>
<div id="stage-detail">
Preparing the compositor and reusable type components.
</div>
<div class="progress-track">
<div id="progress"></div>
</div>
<div class="buttons">
<button id="replay" class="accent">Replay full sequence</button>
<button id="replay-edit">Replay word edit</button>
<button id="pause">Pause</button>
<button id="reset-view" class="ghost">Reset view</button>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
</div>
<div id="loading">
<div class="loading-mark">
<strong>Movable Type</strong>
<span>Preparing the press</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
const background = new THREE.Color("#e5d8bd");
scene.background = background;
scene.fog = new THREE.Fog(background, 19, 39);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.25, 1.55, 0);
const cameraState = {
yaw: 0.53,
polar: 1.04,
radius: 14.2
};
function updateCamera() {
const { yaw, polar, radius } = cameraState;
const horizontal = radius * Math.sin(polar);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(yaw),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + horizontal * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(8.2, 14.9 / aspect);
camera.left = -viewHeight * aspect * 0.5;
camera.right = viewHeight * aspect * 0.5;
camera.top = viewHeight * 0.5;
camera.bottom = -viewHeight * 0.5;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Direct camera controls: no examples/addons are used.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - deltaY * 0.0045,
0.48,
1.34
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9.5,
23
);
updateCamera();
}, { passive: false });
// Lighting.
const hemisphere = new THREE.HemisphereLight("#fff4d5", "#6c786b", 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight("#8fc4c0", 1.1);
rim.position.set(8, 5, -7);
scene.add(rim);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.05,
flatShading: true,
...options
});
}
const materials = {
floor: standard("#cdbb94"),
bed: standard("#24464a"),
bedTop: standard("#386166"),
frame: standard("#d19a3d", { metalness: 0.18 }),
dark: standard("#263238", { metalness: 0.12 }),
typeBody: standard("#343b3a"),
typeShoulder: standard("#b9822e", { metalness: 0.2 }),
glyph: standard("#f0bd62", {
metalness: 0.08,
roughness: 0.65
}),
accent: standard("#d76249"),
green: standard("#6da26d", {
emissive: "#244d2d",
emissiveIntensity: 0.3
}),
paperEdge: standard("#eadcbd"),
ink: standard("#28363a"),
black: standard("#1f292d")
};
function box(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radiusTop, radiusBottom, height, segments, material,
x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and press structure.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.01;
floor.receiveShadow = true;
scene.add(floor);
box(8.4, 0.36, 4.05, materials.bed, 0, 0.82, 0);
box(8.25, 0.08, 3.9, materials.bedTop, 0, 1.02, 0);
for (const x of [-3.45, 3.45]) {
for (const z of [-1.45, 1.45]) {
box(0.28, 0.72, 0.28, materials.dark, x, 0.34, z);
}
}
// A narrow composing rail beneath the blocks.
box(7.25, 0.07, 0.64, materials.dark, -0.2, 1.10, -0.55);
// Type cases.
box(2.75, 0.22, 1.75, materials.dark, 5.35, 0.14, -0.85);
box(2.75, 0.07, 1.75, materials.frame, 5.35, 0.275, -0.85);
box(2.75, 0.22, 0.9, materials.dark, 4.85, 0.14, 1.42);
box(2.75, 0.07, 0.9, materials.frame, 4.85, 0.275, 1.42);
// Reclaim bin for the removed word.
box(1.65, 0.18, 1.25, materials.dark, -5.18, 0.16, 1.38);
for (const x of [-5.9, -4.46]) {
box(0.12, 0.48, 1.25, materials.accent, x, 0.38, 1.38);
}
box(1.55, 0.48, 0.12, materials.accent, -5.18, 0.38, 1.97);
// Overhead XY-style compositor gantry.
for (const z of [-1.65, 1.85]) {
box(12.25, 0.18, 0.18, materials.frame, 0.4, 4.17, z);
}
for (const x of [-5.55, 6.35]) {
box(0.25, 4.05, 0.25, materials.dark, x, 2.02, 0.1);
box(0.28, 0.22, 3.7, materials.frame, x, 4.17, 0.1);
box(0.65, 0.18, 0.65, materials.dark, x, 0.12, 0.1);
}
const bridge = new THREE.Group();
bridge.position.set(0, 4.17, 0);
scene.add(bridge);
box(0.28, 0.25, 3.72, materials.dark, 0, 0, 0.1, bridge);
box(0.46, 0.12, 3.5, materials.frame, 0, 0.16, 0.1, bridge);
const carriage = new THREE.Group();
bridge.add(carriage);
box(0.62, 0.4, 0.62, materials.accent, 0, -0.16, 0, carriage);
box(0.34, 0.17, 0.38, materials.dark, 0, -0.42, 0, carriage);
const gripperRoot = new THREE.Group();
scene.add(gripperRoot);
const telescopingRod = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 1, 8),
materials.dark
);
telescopingRod.castShadow = true;
gripperRoot.add(telescopingRod);
const claw = new THREE.Group();
gripperRoot.add(claw);
box(0.24, 0.12, 0.24, materials.frame, 0, 0, 0, claw);
box(0.08, 0.24, 0.10, materials.accent, -0.16, -0.08, 0, claw);
box(0.08, 0.24, 0.10, materials.accent, 0.16, -0.08, 0, claw);
box(0.12, 0.08, 0.30, materials.dark, 0, -0.20, 0, claw);
// Paper and platen.
box(7.55, 0.035, 1.95, materials.paperEdge, 0, 1.095, 0.76);
const paperCanvas = document.createElement("canvas");
paperCanvas.width = 1200;
paperCanvas.height = 300;
const paperContext = paperCanvas.getContext("2d");
const paperTexture = new THREE.CanvasTexture(paperCanvas);
paperTexture.colorSpace = THREE.SRGBColorSpace;
paperTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const paperMaterial = new THREE.MeshStandardMaterial({
map: paperTexture,
roughness: 0.98,
metalness: 0,
side: THREE.DoubleSide
});
const paper = new THREE.Mesh(
new THREE.PlaneGeometry(7.5, 1.9),
paperMaterial
);
paper.rotation.x = -Math.PI / 2;
paper.position.set(0, 1.115, 0.76);
paper.receiveShadow = true;
scene.add(paper);
for (const x of [-3.78, 3.78]) {
box(0.16, 3.12, 0.16, materials.frame, x, 2.62, 0.76);
}
const platen = new THREE.Group();
platen.position.set(0, 2.3, 0.76);
scene.add(platen);
box(7.32, 0.16, 1.72, materials.dark, 0, 0, 0, platen);
box(6.95, 0.10, 1.48, materials.accent, 0, 0.12, 0, platen);
cylinder(0.08, 0.08, 1.15, 8, materials.frame, 0, 0.66, 0, platen);
box(0.95, 0.12, 0.14, materials.dark, 0, 1.18, 0, platen);
// Low-poly ink pot and brush.
cylinder(0.32, 0.39, 0.48, 10, materials.accent, -5.08, 0.31, -0.85);
cylinder(0.27, 0.27, 0.035, 10, materials.ink, -5.08, 0.57, -0.85);
const brush = cylinder(0.035, 0.05, 1.25, 6, materials.frame,
-5.45, 0.75, -0.65);
brush.rotation.z = -0.42;
// Pixel-style 5×7 glyph definitions, converted to raised low-poly geometry.
const glyphPatterns = {
A: ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
E: ["11111", "10000", "10000", "11110", "10000", "10000", "11111"],
G: ["01110", "10001", "10000", "10111", "10001", "10001", "01110"],
H: ["10001", "10001", "10001", "11111", "10001", "10001", "10001"],
I: ["11111", "00100", "00100", "00100", "00100", "00100", "11111"],
K: ["10001", "10010", "10100", "11000", "10100", "10010", "10001"],
L: ["10000", "10000", "10000", "10000", "10000", "10000", "11111"],
M: ["10001", "11011", "10101", "10101", "10001", "10001", "10001"],
O: ["01110", "10001", "10001", "10001", "10001", "10001", "01110"],
R: ["11110", "10001", "10001", "11110", "10100", "10010", "10001"],
S: ["01111", "10000", "10000", "01110", "00001", "00001", "11110"],
T: ["11111", "00100", "00100", "00100", "00100", "00100", "00100"],
V: ["10001", "10001", "10001", "10001", "10001", "01010", "00100"],
W: ["10001", "10001", "10001", "10101", "10101", "11011", "10001"]
};
function createGlyphGeometry(letter) {
const pattern = glyphPatterns[letter];
const cell = 0.055;
const pixelGeometry = new THREE.BoxGeometry(
cell * 0.84,
cell * 0.84,
0.07
);
const geometry = pixelGeometry.index
? pixelGeometry.toNonIndexed()
: pixelGeometry;
const sourcePosition = geometry.getAttribute("position");
const sourceNormal = geometry.getAttribute("normal");
const positions = [];
const normals = [];
for (let row = 0; row < pattern.length; row++) {
for (let column = 0; column < pattern[row].length; column++) {
if (pattern[row][column] !== "1") continue;
const offsetX = (column - 2) * cell;
const offsetY = (3 - row) * cell;
const offsetZ = 0.26;
for (let vertex = 0; vertex < sourcePosition.count; vertex++) {
positions.push(
sourcePosition.getX(vertex) + offsetX,
sourcePosition.getY(vertex) + offsetY,
sourcePosition.getZ(vertex) + offsetZ
);
normals.push(
sourceNormal.getX(vertex),
sourceNormal.getY(vertex),
sourceNormal.getZ(vertex)
);
}
}
}
const result = new THREE.BufferGeometry();
result.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
result.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
result.computeBoundingSphere();
if (geometry !== pixelGeometry) geometry.dispose();
pixelGeometry.dispose();
return result;
}
const glyphGeometries = {};
for (const letter of Object.keys(glyphPatterns)) {
glyphGeometries[letter] = createGlyphGeometry(letter);
}
const typeBodyGeometry = new THREE.BoxGeometry(0.46, 0.52, 0.46);
const typeShoulderGeometry = new THREE.BoxGeometry(0.5, 0.07, 0.5);
const typeNotchGeometry = new THREE.BoxGeometry(0.15, 0.025, 0.045);
function createTypeBlock(letter) {
const group = new THREE.Group();
const body = new THREE.Mesh(typeBodyGeometry, materials.typeBody);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const shoulder = new THREE.Mesh(
typeShoulderGeometry,
materials.typeShoulder
);
shoulder.position.y = -0.28;
shoulder.castShadow = true;
group.add(shoulder);
const glyph = new THREE.Mesh(
glyphGeometries[letter],
materials.glyph
);
glyph.castShadow = true;
group.add(glyph);
const notch = new THREE.Mesh(
typeNotchGeometry,
materials.black
);
notch.position.set(0, 0.266, 0.05);
group.add(notch);
group.userData.letter = letter;
scene.add(group);
return group;
}
const ORIGINAL_PHRASE = "MAKE WORDS MOVE";
const EDITED_PHRASE = "MAKE LIGHT MOVE";
const ORIGINAL_CHARS = [...("MAKE" + "WORDS" + "MOVE")];
const REPLACEMENT_CHARS = [...("LIGHT")];
const BLOCK_WIDTH = 0.46;
const WORD_GAP = 0.34;
const DEST_Y = 1.38;
const DEST_Z = -0.55;
function makeDestination(words) {
const totalWidth =
words.reduce((sum, word) => sum + word.length * BLOCK_WIDTH, 0) +
(words.length - 1) * WORD_GAP;
let cursor = -totalWidth * 0.5;
const result = [];
words.forEach((word, wordIndex) => {
for (let i = 0; i < word.length; i++) {
result.push({
x: cursor + BLOCK_WIDTH * 0.5,
y: DEST_Y,
z: DEST_Z
});
cursor += BLOCK_WIDTH;
}
if (wordIndex < words.length - 1) cursor += WORD_GAP;
});
return result;
}
const originalDestination = makeDestination(["MAKE", "WORDS", "MOVE"]);
const editedDestination = makeDestination(["MAKE", "LIGHT", "MOVE"]);
const sourcePositions = [];
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 5; column++) {
if (sourcePositions.length >= ORIGINAL_CHARS.length) break;
sourcePositions.push({
x: 4.15 + column * 0.5,
y: 0.57,
z: -1.35 + row * 0.5
});
}
}
const replacementPositions = REPLACEMENT_CHARS.map((_, index) => ({
x: 3.85 + index * 0.5,
y: 0.57,
z: 1.42
}));
const reclaimPositions = [
{ x: -5.75, y: 0.62, z: 1.08 },
{ x: -5.20, y: 0.62, z: 1.08 },
{ x: -4.65, y: 0.62, z: 1.08 },
{ x: -5.48, y: 0.62, z: 1.62 },
{ x: -4.92, y: 0.62, z: 1.62 }
];
const originalBlocks = ORIGINAL_CHARS.map((letter, index) => {
const block = createTypeBlock(letter);
block.position.set(
sourcePositions[index].x,
sourcePositions[index].y,
sourcePositions[index].z
);
return block;
});
const replacementBlocks = REPLACEMENT_CHARS.map((letter, index) => {
const block = createTypeBlock(letter);
block.position.set(
replacementPositions[index].x,
replacementPositions[index].y,
replacementPositions[index].z
);
return block;
});
// Green rails emphasize that MAKE and MOVE remain locked during editing.
const preservationGroup = new THREE.Group();
scene.add(preservationGroup);
const leftPreserved = originalDestination.slice(0, 4);
const rightPreserved = originalDestination.slice(9);
function preservationBar(blocks) {
const minX = Math.min(...blocks.map(block => block.x)) - 0.29;
const maxX = Math.max(...blocks.map(block => block.x)) + 0.29;
const centerX = (minX + maxX) * 0.5;
box(
maxX - minX,
0.025,
0.095,
materials.green,
centerX,
1.085,
-0.22,
preservationGroup
);
for (const x of [minX, maxX]) {
box(
0.055,
0.12,
0.095,
materials.green,
x,
1.11,
-0.22,
preservationGroup
);
}
}
preservationBar(leftPreserved);
preservationBar(rightPreserved);
preservationGroup.visible = false;
// A low-poly ring marks the component currently handled by the gripper.
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.025, 6, 18),
new THREE.MeshBasicMaterial({
color: "#f4c95d",
transparent: true,
opacity: 0.9
})
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.visible = false;
scene.add(selectionRing);
function makeTag(text, x, y, z) {
const tagCanvas = document.createElement("canvas");
tagCanvas.width = 512;
tagCanvas.height = 96;
const context = tagCanvas.getContext("2d");
context.fillStyle = "rgba(38, 50, 56, 0.9)";
context.fillRect(0, 0, 512, 96);
context.fillStyle = "#f3ead4";
context.font = "800 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 50);
const texture = new THREE.CanvasTexture(tagCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({ map: texture })
);
sprite.position.set(x, y, z);
sprite.scale.set(1.55, 0.29, 1);
scene.add(sprite);
}
makeTag("ORIGINAL TYPE", 5.25, 0.50, 0.12);
makeTag("LIGHT TYPE", 4.75, 0.50, 1.96);
makeTag("RECLAIM", -5.15, 0.58, 2.00);
// Timeline.
const INTRO_END = 1.4;
const ASSEMBLY_START = 1.4;
const ASSEMBLY_ACTION = 0.68;
const ASSEMBLY_END =
ASSEMBLY_START + originalBlocks.length * ASSEMBLY_ACTION;
const PRINT_ONE_START = 10.3;
const PRINT_ONE_END = 12.1;
const REMOVE_START = 12.2;
const REMOVE_ACTION = 0.62;
const INSERT_START = 15.4;
const INSERT_ACTION = 0.72;
const INSERT_END =
INSERT_START + replacementBlocks.length * INSERT_ACTION;
const PRINT_TWO_START = 19.1;
const PRINT_TWO_END = 20.4;
const TOTAL_TIME = 21.0;
let time = 0;
let playing = true;
let paperVersion = 0;
const clamp01 = value => Math.max(0, Math.min(1, value));
const smooth = value => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
const lerp = (a, b, t) => a + (b - a) * t;
function copyPosition(position) {
return { x: position.x, y: position.y, z: position.z };
}
function setObjectPosition(object, position) {
object.position.set(position.x, position.y, position.z);
}
/*
One reusable pick-and-place motion:
approach → descend → lift → travel → place → release.
*/
function actionState(localTime, duration, from, to) {
const p = clamp01(localTime / duration);
const high = 2.78;
const carryBlockY = 2.25;
const carryGripY = 2.64;
const sourceGripY = from.y + 0.39;
const destinationGripY = to.y + 0.39;
const grip = { x: from.x, y: high, z: from.z };
const block = copyPosition(from);
if (p < 0.16) {
// High-level approach.
} else if (p < 0.28) {
// Descend to the source.
grip.y = lerp(high, sourceGripY, smooth((p - 0.16) / 0.12));
} else if (p < 0.40) {
// Grab and lift.
grip.y = lerp(
sourceGripY,
carryGripY,
smooth((p - 0.28) / 0.12)
);
block.y = lerp(
from.y,
carryBlockY,
smooth((p - 0.28) / 0.12)
);
} else if (p < 0.60) {
// Carry to the destination.
grip.x = lerp(from.x, to.x, smooth((p - 0.40) / 0.20));
grip.z = lerp(from.z, to.z, smooth((p - 0.40) / 0.20));
grip.y = carryGripY;
block.x = lerp(from.x, to.x, smooth((p - 0.40) / 0.20));
block.z = lerp(from.z, to.z, smooth((p - 0.40) / 0.20));
block.y = carryBlockY;
} else if (p < 0.76) {
// Lower into the composing position.
grip.x = to.x;
grip.z = to.z;
grip.y = lerp(
carryGripY,
destinationGripY,
smooth((p - 0.60) / 0.16)
);
block.x = to.x;
block.z = to.z;
block.y = lerp(
carryBlockY,
to.y,
smooth((p - 0.60) / 0.16)
);
} else if (p < 0.88) {
// Release and withdraw.
grip.x = to.x;
grip.z = to.z;
grip.y = lerp(
destinationGripY,
high,
smooth((p - 0.76) / 0.12)
);
block.x = to.x;
block.y = to.y;
block.z = to.z;
} else {
grip.x = to.x;
grip.z = to.z;
grip.y = high;
block.x = to.x;
block.y = to.y;
block.z = to.z;
}
return { grip, block };
}
function drawPaper(phrase, impressionNumber = 0) {
const context = paperContext;
const width = paperCanvas.width;
const height = paperCanvas.height;
context.clearRect(0, 0, width, height);
context.fillStyle = "#f4ead2";
context.fillRect(0, 0, width, height);
// Deterministic paper fibers.
let seed = 8431;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
for (let i = 0; i < 1900; i++) {
const alpha = 0.018 + random() * 0.035;
context.fillStyle = `rgba(73, 58, 36, ${alpha})`;
const size = random() > 0.9 ? 2 : 1;
context.fillRect(
random() * width,
random() * height,
size,
size
);
}
context.strokeStyle = "rgba(58, 51, 39, 0.15)";
context.lineWidth = 2;
context.strokeRect(18, 18, width - 36, height - 36);
context.fillStyle = "rgba(48, 58, 58, 0.58)";
context.font = "700 18px ui-monospace, monospace";
context.textAlign = "left";
context.fillText(
`COMPOSITOR / IMPRESSION ${String(impressionNumber).padStart(2, "0")}`,
48,
58
);
if (!phrase) return;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 89px Georgia, serif";
const characters = [...phrase];
const spacing = 3;
const widths = characters.map(character =>
context.measureText(character).width
);
const totalWidth =
widths.reduce((sum, value) => sum + value, 0) +
spacing * (characters.length - 1);
let x = (width - totalWidth) * 0.5;
const y = 165;
characters.forEach((character, index) => {
const jitter = ((index * 17) % 7 - 3) * 0.35;
context.fillStyle = "rgba(35, 48, 51, 0.91)";
context.fillText(character, x + widths[index] * 0.5, y + jitter);
x += widths[index] + spacing;
});
context.fillStyle = "rgba(48, 58, 58, 0.46)";
context.font = "600 14px ui-monospace, monospace";
context.fillText(
"REUSABLE COMPONENTS / EDITABLE COMPOSITION",
width * 0.5,
252
);
paperTexture.needsUpdate = true;
}
drawPaper("");
function printMotion(start) {
const duration = 1.3;
const p = (time - start) / duration;
if (p < 0 || p > 1) return 2.3;
if (p < 0.36) {
return lerp(2.3, 1.21, smooth(p / 0.36));
}
if (p < 0.70) {
return 1.21;
}
return lerp(1.21, 2.3, smooth((p - 0.70) / 0.30));
}
let activeState = null;
let activeBlockPosition = null;
function updateBlocks() {
activeState = null;
activeBlockPosition = null;
// Original blocks: assemble, then reclaim only the five WORDS blocks.
originalBlocks.forEach((block, index) => {
const assemblyStart =
ASSEMBLY_START + index * ASSEMBLY_ACTION;
const removalStart =
REMOVE_START + (index - 4) * REMOVE_ACTION;
if (time < REMOVE_START) {
if (time < assemblyStart) {
setObjectPosition(block, sourcePositions[index]);
} else if (time < assemblyStart + ASSEMBLY_ACTION) {
const state = actionState(
time - assemblyStart,
ASSEMBLY_ACTION,
sourcePositions[index],
originalDestination[index]
);
setObjectPosition(block, state.block);
activeState = state;
activeBlockPosition = state.block;
} else {
setObjectPosition(block, originalDestination[index]);
}
} else if (index >= 4 && index <= 8) {
if (time < removalStart + REMOVE_ACTION) {
const state = actionState(
time - removalStart,
REMOVE_ACTION,
originalDestination[index],
reclaimPositions[index - 4]
);
setObjectPosition(block, state.block);
activeState = state;
activeBlockPosition = state.block;
} else {
setObjectPosition(block, reclaimPositions[index - 4]);
}
} else {
// MAKE and MOVE never move again.
setObjectPosition(block, originalDestination[index]);
}
});
// Replacement LIGHT components come from their own reusable case.
replacementBlocks.forEach((block, index) => {
const insertionStart =
INSERT_START + index * INSERT_ACTION;
if (time < insertionStart) {
setObjectPosition(block, replacementPositions[index]);
} else if (time < insertionStart + INSERT_ACTION) {
const state = actionState(
time - insertionStart,
INSERT_ACTION,
replacementPositions[index],
editedDestination[index + 4]
);
setObjectPosition(block, state.block);
activeState = state;
activeBlockPosition = state.block;
} else {
setObjectPosition(block, editedDestination[index + 4]);
}
});
// Update the gantry from the currently active pick operation.
let grip;
if (activeState) {
grip = activeState.grip;
} else if (time < INTRO_END) {
grip = { x: 0, y: 2.78, z: DEST_Z };
} else if (time < REMOVE_START) {
grip = {
x: originalDestination[originalDestination.length - 1].x,
y: 2.78,
z: DEST_Z
};
} else if (time < INSERT_START) {
grip = {
x: reclaimPositions[reclaimPositions.length - 1].x,
y: 2.78,
z: reclaimPositions[reclaimPositions.length - 1].z
};
} else {
grip = {
x: editedDestination[8].x,
y: 2.78,
z: DEST_Z
};
}
bridge.position.x = grip.x;
carriage.position.z = grip.z - 0.1;
gripperRoot.position.set(grip.x, 0, grip.z);
claw.position.y = grip.y;
const rodTop = 4.04;
const rodLength = Math.max(0.2, rodTop - grip.y);
telescopingRod.scale.y = rodLength;
telescopingRod.position.y = (rodTop + grip.y) * 0.5;
selectionRing.visible = Boolean(activeBlockPosition);
if (activeBlockPosition) {
selectionRing.position.set(
activeBlockPosition.x,
activeBlockPosition.y - 0.33,
activeBlockPosition.z
);
selectionRing.rotation.z = time * 1.5;
}
preservationGroup.visible =
time >= REMOVE_START - 0.04 &&
time <= INSERT_END + 0.04;
}
function updatePaper() {
if (time < PRINT_ONE_START && paperVersion !== 0) {
paperVersion = 0;
drawPaper("");
}
if (time >= PRINT_ONE_START && paperVersion === 0) {
paperVersion = 1;
drawPaper(ORIGINAL_PHRASE, 1);
}
if (time >= PRINT_TWO_START && paperVersion === 1) {
paperVersion = 2;
drawPaper(EDITED_PHRASE, 2);
}
}
function updatePlaten() {
if (
time >= PRINT_ONE_START &&
time < PRINT_ONE_START + 1.3
) {
platen.position.y = printMotion(PRINT_ONE_START);
} else if (
time >= PRINT_TWO_START &&
time < PRINT_TWO_START + 1.3
) {
platen.position.y = printMotion(PRINT_TWO_START);
} else {
platen.position.y = 2.3;
}
}
// Interface.
const stageNumber = document.getElementById("stage-number");
const stageTitle = document.getElementById("stage-title");
const stageDetail = document.getElementById("stage-detail");
const progress = document.getElementById("progress");
const clock = document.getElementById("clock");
const pauseButton = document.getElementById("pause");
function formatTime(value) {
const seconds = Math.floor(value);
return `${String(Math.floor(seconds / 60)).padStart(2, "0")}:` +
`${String(seconds % 60).padStart(2, "0")}`;
}
function updateInterface() {
let number = 0;
let title = "";
let detail = "";
if (time < INTRO_END) {
number = 1;
title = "Loading the type case";
detail =
"Thirteen original components and five replacement components are ready.";
} else if (time < ASSEMBLY_END) {
number = 1;
title = "Composing the phrase";
const index = Math.min(
originalBlocks.length - 1,
Math.floor((time - ASSEMBLY_START) / ASSEMBLY_ACTION)
);
title = `Composing “${originalBlocks[index].userData.letter}”`;
detail =
`The gripper is placing reusable type block ${index + 1} of ` +
`${originalBlocks.length}.`;
} else if (time < PRINT_ONE_START) {
number = 2;
title = "The line is locked";
detail =
"MAKE WORDS MOVE is complete and ready for its first impression.";
} else if (time < PRINT_ONE_END) {
number = 2;
title = "First impression";
detail =
"The platen transfers the composed phrase onto the paper.";
} else if (time < INSERT_START) {
number = 3;
title = `Reclaiming “${originalBlocks[
Math.min(8, 4 + Math.floor((time - REMOVE_START) / REMOVE_ACTION))
].userData.letter}”`;
detail =
"Only the five components in WORDS are removed. MAKE and MOVE stay locked.";
} else if (time < INSERT_END) {
number = 3;
const index = Math.min(
replacementBlocks.length - 1,
Math.floor((time - INSERT_START) / INSERT_ACTION)
);
title = `Replacing with “${replacementBlocks[index].userData.letter}”`;
detail =
"A reusable LIGHT component is placed into the vacated word position.";
} else if (time < PRINT_TWO_END) {
number = 4;
title = "Second impression";
detail =
"The edited composition prints as MAKE LIGHT MOVE.";
} else {
number = 4;
title = "The edit holds";
detail =
"Eight surrounding blocks never moved; the replaced word remains editable.";
}
stageNumber.textContent = number;
stageTitle.textContent = title;
stageDetail.textContent = detail;
progress.style.width = `${Math.min(100, time / TOTAL_TIME * 100)}%`;
clock.textContent = formatTime(time);
pauseButton.textContent = playing ? "Pause" : "Resume";
}
document.getElementById("replay").addEventListener("click", () => {
time = 0;
paperVersion = 0;
drawPaper("");
playing = true;
});
document.getElementById("replay-edit").addEventListener("click", () => {
time = ASSEMBLY_END;
paperVersion = 0;
drawPaper("");
playing = true;
});
pauseButton.addEventListener("click", () => {
if (time >= TOTAL_TIME) {
time = 0;
paperVersion = 0;
drawPaper("");
}
playing = !playing;
});
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.yaw = 0.53;
cameraState.polar = 1.04;
cameraState.radius = 14.2;
updateCamera();
});
const clock3D = new THREE.Clock();
function animate() {
const delta = Math.min(clock3D.getDelta(), 0.05);
if (playing) {
time = Math.min(TOTAL_TIME, time + delta);
if (time >= TOTAL_TIME) playing = false;
}
updateBlocks();
updatePaper();
updatePlaten();
updateInterface();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```