Prompt specification
Build or customize the Three.js 3D scene "Sender and sounder exchanging one symbol" 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: Sender and sounder exchanging one symbol
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/sender-and-sounder-exchanging-one-symbol-x2542
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: Sender and sounder exchanging one symbol. Create two telegraph stations linked by a visible wire. Animate a short sourced code sequence and show its timing at both ends with the same clock. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (sender-and-sounder-exchanging-one-symbol-x2542):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Voxel Telegraph — One-Symbol Exchange</title>
<style>
:root {
--bg: #080d18;
--panel: rgba(11, 19, 33, 0.88);
--panel-border: rgba(159, 202, 220, 0.18);
--text: #e7f1f2;
--muted: #8ca4ad;
--cyan: #62e7e2;
--amber: #ffb75b;
--red: #ff6f61;
--green: #8ee08a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
background: var(--bg);
color: var(--muted);
letter-spacing: .18em;
font-size: 12px;
transition: opacity .35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.hud {
position: fixed;
z-index: 4;
pointer-events: none;
}
#brand {
top: 22px;
left: 24px;
max-width: 360px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: .22em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(18px, 2.2vw, 28px);
line-height: 1.05;
letter-spacing: -.04em;
font-weight: 750;
}
#brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#sourceCard {
top: 20px;
right: 22px;
width: min(360px, calc(100vw - 44px));
padding: 13px 15px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: var(--panel);
box-shadow: 0 14px 38px rgba(0,0,0,.25);
backdrop-filter: blur(12px);
pointer-events: auto;
font-size: 10px;
line-height: 1.55;
color: var(--muted);
}
#sourceCard strong {
display: block;
margin-bottom: 4px;
color: var(--text);
font-size: 10px;
letter-spacing: .08em;
}
#sourceCard a {
color: var(--amber);
text-decoration: none;
border-bottom: 1px dotted rgba(255,183,91,.55);
}
.station-label {
position: fixed;
z-index: 3;
min-width: 178px;
padding: 9px 11px 8px;
transform: translate(-50%, -100%);
border: 1px solid var(--panel-border);
border-radius: 8px;
background: rgba(8, 14, 25, .87);
box-shadow: 0 10px 25px rgba(0,0,0,.24);
backdrop-filter: blur(9px);
pointer-events: none;
}
.station-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 1px;
height: 7px;
background: rgba(210,235,240,.38);
}
.station-name {
display: flex;
justify-content: space-between;
gap: 14px;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: .14em;
}
.station-name b {
color: var(--cyan);
}
#sounderLabel .station-name b { color: var(--amber); }
.station-clock {
color: var(--text);
font-size: 18px;
font-variant-numeric: tabular-nums;
letter-spacing: .02em;
}
.clock-tag {
margin-right: 8px;
color: #617984;
font-size: 9px;
letter-spacing: .1em;
}
#transport {
left: 50%;
bottom: 20px;
width: min(760px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 13px 15px 12px;
border: 1px solid var(--panel-border);
border-radius: 11px;
background: rgba(9, 16, 28, .91);
box-shadow: 0 18px 48px rgba(0,0,0,.34);
backdrop-filter: blur(13px);
pointer-events: auto;
}
.transport-top,
.transport-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.transport-top {
margin-bottom: 9px;
}
#status {
min-width: 0;
overflow: hidden;
color: var(--text);
font-size: 10px;
font-weight: 700;
letter-spacing: .09em;
text-overflow: ellipsis;
white-space: nowrap;
}
#masterClock {
flex: 0 0 auto;
color: var(--cyan);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
#track {
position: relative;
height: 22px;
overflow: hidden;
border: 1px solid rgba(151,194,207,.18);
border-radius: 4px;
background:
repeating-linear-gradient(
90deg,
transparent 0,
transparent calc(15.3846% - 1px),
rgba(155,194,205,.12) calc(15.3846% - 1px),
rgba(155,194,205,.12) 15.3846%
),
#111d2c;
}
.window {
position: absolute;
top: 3px;
bottom: 3px;
border-radius: 2px;
}
#sendWindow {
left: 11.538%;
width: 15.385%;
background: rgba(98,231,226,.75);
box-shadow: 0 0 12px rgba(98,231,226,.38);
}
#replyWindow {
left: 73.077%;
width: 15.385%;
background: rgba(255,183,91,.78);
box-shadow: 0 0 12px rgba(255,183,91,.35);
}
#nowLine {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 2px;
background: #fff;
box-shadow: 0 0 8px rgba(255,255,255,.85);
}
.transport-bottom {
margin-top: 9px;
}
.legend {
display: flex;
align-items: center;
gap: 14px;
color: var(--muted);
font-size: 9px;
letter-spacing: .07em;
}
.legend span::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
background: var(--cyan);
}
.legend span:last-child::before { background: var(--amber); }
.controls {
display: flex;
gap: 6px;
}
button {
border: 1px solid rgba(157,201,214,.22);
border-radius: 5px;
padding: 6px 9px;
background: rgba(255,255,255,.045);
color: var(--text);
font: inherit;
font-size: 9px;
font-weight: 700;
letter-spacing: .08em;
cursor: pointer;
}
button:hover {
border-color: rgba(98,231,226,.5);
background: rgba(98,231,226,.08);
}
#controlsHint {
right: 24px;
bottom: 170px;
color: rgba(154,180,190,.62);
font-size: 9px;
line-height: 1.5;
text-align: right;
letter-spacing: .05em;
}
@media (max-width: 760px) {
#sourceCard {
top: auto;
right: 12px;
bottom: 171px;
width: 250px;
font-size: 9px;
}
#brand {
top: 15px;
left: 15px;
}
#brand p { display: none; }
#transport {
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px;
}
.legend { gap: 8px; }
#controlsHint { display: none; }
.station-label { min-width: 145px; }
.station-clock { font-size: 15px; }
}
@media (max-width: 480px) {
#sourceCard { display: none; }
.legend { display: none; }
.transport-bottom { justify-content: flex-end; }
#status { font-size: 9px; }
}
</style>
</head>
<body>
<div id="loading">BUILDING VOXEL LINE…</div>
<header id="brand" class="hud">
<div class="eyebrow">Voxel Telegraph / Line 01</div>
<h1>One symbol, end to end.</h1>
<p>Sender → sounder → acknowledgment. Both stations read from one shared simulation clock.</p>
</header>
<aside id="sourceCard" class="hud">
<strong>CODE SOURCE · ITU-T M.1677-1</strong>
Payload sequence: <b>·</b> (one Morse dot). The standard defines a dot as one timing unit;
the three-unit gap separates characters. The reply is a single acknowledgment dot.
<br><a href="https://www.itu.int/rec/R-REC-M.1677-1/en" target="_blank" rel="noopener">
International Morse code recommendation ↗
</a>
</aside>
<div id="senderLabel" class="station-label">
<div class="station-name"><span>SENDER</span><b>TX / KEY</b></div>
<div class="station-clock"><span class="clock-tag">T+</span><span id="senderClock">00:00.000</span></div>
</div>
<div id="sounderLabel" class="station-label">
<div class="station-name"><span>SOUNDER</span><b>RX / ECHO</b></div>
<div class="station-clock"><span class="clock-tag">T+</span><span id="sounderClock">00:00.000</span></div>
</div>
<section id="transport" class="hud">
<div class="transport-top">
<div id="status">READY · sender armed</div>
<div id="masterClock">00:00.000 / 00:06.500</div>
</div>
<div id="track">
<div id="sendWindow" class="window"></div>
<div id="replyWindow" class="window"></div>
<div id="nowLine"></div>
</div>
<div class="transport-bottom">
<div class="legend">
<span>PAYLOAD DOT</span>
<span>ACK DOT</span>
</div>
<div class="controls">
<button id="playButton" type="button">PAUSE</button>
<button id="replayButton" type="button">REPLAY</button>
<button id="speedButton" type="button">1×</button>
</div>
</div>
</section>
<div id="controlsHint" class="hud">
DRAG TO ORBIT · WHEEL TO ZOOM<br>DOUBLE-CLICK TO RESET VIEW
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const senderClockEl = document.getElementById("senderClock");
const sounderClockEl = document.getElementById("sounderClock");
const masterClockEl = document.getElementById("masterClock");
const statusEl = document.getElementById("status");
const nowLine = document.getElementById("nowLine");
const playButton = document.getElementById("playButton");
const replayButton = document.getElementById("replayButton");
const speedButton = document.getElementById("speedButton");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d18);
scene.fog = new THREE.Fog(0x080d18, 20, 38);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const cameraState = {
yaw: 0.15,
pitch: 0.49,
zoom: 1,
distance: 22
};
const hemi = new THREE.HemisphereLight(0xabcfe4, 0x20283b, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6c0, 3.2);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x5ba7ff, 1.7);
rim.position.set(9, 7, -10);
scene.add(rim);
const palette = {
ground: new THREE.MeshStandardMaterial({ color: 0x182537, roughness: 0.96 }),
ground2: new THREE.MeshStandardMaterial({ color: 0x1c2a3b, roughness: 0.96 }),
groundEdge: new THREE.MeshStandardMaterial({ color: 0x0d1726, roughness: 1 }),
cream: new THREE.MeshStandardMaterial({ color: 0xd8d2b7, roughness: 0.82 }),
pale: new THREE.MeshStandardMaterial({ color: 0xeee5cb, roughness: 0.8 }),
teal: new THREE.MeshStandardMaterial({ color: 0x367b78, roughness: 0.76 }),
tealDark: new THREE.MeshStandardMaterial({ color: 0x214f54, roughness: 0.86 }),
rust: new THREE.MeshStandardMaterial({ color: 0x9b5541, roughness: 0.82 }),
rustDark: new THREE.MeshStandardMaterial({ color: 0x623735, roughness: 0.9 }),
dark: new THREE.MeshStandardMaterial({ color: 0x17212c, roughness: 0.82 }),
black: new THREE.MeshStandardMaterial({ color: 0x090e15, roughness: 0.72 }),
wood: new THREE.MeshStandardMaterial({ color: 0x76513a, roughness: 0.94 }),
woodLight: new THREE.MeshStandardMaterial({ color: 0xa8784e, roughness: 0.9 }),
brass: new THREE.MeshStandardMaterial({
color: 0xb78338, roughness: 0.38, metalness: 0.72, flatShading: true
}),
copper: new THREE.MeshStandardMaterial({
color: 0xc5763f, roughness: 0.36, metalness: 0.68, flatShading: true
}),
copperDark: new THREE.MeshStandardMaterial({
color: 0x5f392b, roughness: 0.48, metalness: 0.55, flatShading: true
}),
red: new THREE.MeshStandardMaterial({ color: 0x9f3e35, roughness: 0.75 }),
green: new THREE.MeshStandardMaterial({ color: 0x5e8a58, roughness: 0.84 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x355e55, roughness: 0.95 }),
leaf2: new THREE.MeshStandardMaterial({ color: 0x416f60, roughness: 0.95 }),
window: new THREE.MeshStandardMaterial({
color: 0x142f3a, roughness: 0.35, metalness: 0.18,
emissive: 0x0a2930, emissiveIntensity: 0.45
})
};
const geometryCache = new Map();
function box(parent, size, position, material, cast = true, receive = true) {
const key = size.join("|");
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(...size));
}
const mesh = new THREE.Mesh(geometryCache.get(key), material);
mesh.position.set(...position);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
// Voxel ground.
box(scene, [19, 0.36, 13], [0, -0.46, 0], palette.groundEdge);
for (let x = -9; x <= 9; x++) {
for (let z = -6; z <= 6; z++) {
const material = (x + z) % 2 === 0 ? palette.ground : palette.ground2;
box(scene, [0.94, 0.11, 0.94], [x, -0.22, z], material, false, true);
}
}
// Small voxel landscaping.
function tree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
box(g, [0.28, 1.45, 0.28], [0, 0.72, 0], palette.wood);
box(g, [1.25, 0.75, 1.15], [0, 1.65, 0], palette.leaf);
box(g, [0.85, 0.7, 0.85], [0.35, 2.22, -0.05], palette.leaf2);
box(g, [0.65, 0.5, 0.65], [-0.38, 2.05, 0.1], palette.leaf);
}
tree(-7.4, -3.7, 1.05);
tree(7.2, -3.9, 0.9);
tree(-7.8, 3.8, 0.75);
tree(7.8, 3.5, 0.82);
for (const [x, z] of [[-6.4, 4.1], [6.4, 4.1], [-6.1, -4.4], [6.0, -4.4]]) {
box(scene, [0.12, 0.55, 0.12], [x, 0.28, z], palette.woodLight);
}
function buildStation(x, role) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const isSender = role === "sender";
const wallMat = isSender ? palette.teal : palette.rust;
const darkMat = isSender ? palette.tealDark : palette.rustDark;
const trimMat = isSender ? palette.tealDark : palette.rustDark;
box(group, [3.75, 0.22, 3.05], [0, 0.0, 0], palette.woodLight);
box(group, [3.45, 0.13, 2.78], [0, 0.16, 0], palette.wood);
box(group, [3.25, 2.45, 0.22], [0, 1.43, -1.02], wallMat);
box(group, [0.22, 2.45, 2.2], [-1.55, 1.43, 0], wallMat);
box(group, [0.22, 2.45, 2.2], [1.55, 1.43, 0], wallMat);
box(group, [3.72, 0.24, 2.65], [0, 2.73, -0.02], darkMat);
box(group, [3.35, 0.20, 2.32], [0, 2.95, -0.08], trimMat);
// Back-wall panels and voxel window.
box(group, [1.15, 0.78, 0.07], [-0.64, 1.85, -0.87], palette.window, false, false);
box(group, [0.08, 0.82, 0.09], [-0.64, 1.85, -0.81], palette.cream, false, false);
box(group, [1.18, 0.08, 0.09], [-0.64, 1.85, -0.81], palette.cream, false, false);
box(group, [0.92, 0.22, 0.08], [0.58, 1.03, -0.86], palette.brass, false, false);
// Workbench.
box(group, [2.55, 0.14, 0.84], [0, 1.18, 0.35], palette.woodLight);
box(group, [0.14, 1.0, 0.62], [-1.02, 0.68, 0.35], palette.wood);
box(group, [0.14, 1.0, 0.62], [1.02, 0.68, 0.35], palette.wood);
const lampMat = new THREE.MeshStandardMaterial({
color: isSender ? 0x64d9c4 : 0xffad5f,
emissive: isSender ? 0x2ebda6 : 0xd46b27,
emissiveIntensity: 0.35,
roughness: 0.42
});
box(group, [0.34, 0.34, 0.34], [1.14, 3.23, -0.15], palette.black);
box(group, [0.24, 0.24, 0.24], [1.14, 3.48, -0.15], lampMat, false, false);
let lever;
if (isSender) {
// Telegraph key.
box(group, [0.93, 0.14, 0.58], [0.57, 1.34, 0.38], palette.black);
box(group, [0.26, 0.12, 0.3], [0.31, 1.45, 0.38], palette.brass);
lever = new THREE.Group();
lever.position.set(0.31, 1.50, 0.38);
group.add(lever);
box(lever, [0.78, 0.09, 0.13], [0.30, 0, 0], palette.brass);
box(lever, [0.18, 0.18, 0.22], [0.72, 0.03, 0], palette.black);
box(lever, [0.17, 0.14, 0.17], [-0.02, 0, 0], palette.copper);
} else {
// Sounder: paired coils, pivot, and audible armature.
box(group, [1.02, 0.16, 0.73], [-0.48, 1.34, 0.38], palette.black);
for (const coilX of [-0.76, -0.22]) {
for (let i = 0; i < 3; i++) {
box(
group,
[0.28, 0.13, 0.34],
[coilX, 1.48 + i * 0.13, 0.38],
i === 1 ? palette.red : palette.cream
);
}
}
lever = new THREE.Group();
lever.position.set(-0.49, 1.78, 0.38);
group.add(lever);
box(lever, [0.76, 0.10, 0.14], [0.19, 0, 0], palette.brass);
box(lever, [0.20, 0.18, 0.20], [0.58, 0.02, 0], palette.black);
// Small reply plunger for the one-dot acknowledgment.
box(group, [0.36, 0.12, 0.4], [0.74, 1.36, 0.38], palette.brass);
box(group, [0.08, 0.25, 0.08], [0.74, 1.51, 0.38], palette.copper);
box(group, [0.26, 0.10, 0.24], [0.74, 1.66, 0.38], palette.black);
}
return { group, lever, lampMat };
}
const sender = buildStation(-4.35, "sender");
const sounder = buildStation(4.35, "sounder");
// Line supports.
const leftSupport = new THREE.Vector3(-2.73, 2.55, 0.60);
const rightSupport = new THREE.Vector3(2.73, 2.55, 0.60);
for (const x of [-2.73, 2.73]) {
box(scene, [0.17, 2.45, 0.17], [x, 1.24, 0.60], palette.dark);
box(scene, [0.42, 0.14, 0.42], [x, 2.42, 0.60], palette.brass);
box(scene, [0.25, 0.19, 0.25], [x, 2.56, 0.60], palette.cream);
box(scene, [0.33, 0.13, 0.33], [x, 2.70, 0.60], palette.copper);
}
const lineCurve = new THREE.QuadraticBezierCurve3(
leftSupport,
new THREE.Vector3(0, 1.48, 0.60),
rightSupport
);
// Build the visible copper wire from many tiny box segments.
const wireSamples = lineCurve.getPoints(110);
const wireUp = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < wireSamples.length - 1; i++) {
const a = wireSamples[i];
const b = wireSamples[i + 1];
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const direction = b.clone().sub(a);
const length = direction.length();
const segment = box(
scene,
[0.065, length * 1.08, 0.065],
midpoint.toArray(),
palette.copper,
false,
false
);
segment.quaternion.setFromUnitVectors(wireUp, direction.normalize());
}
function cableBetween(points, material = palette.copperDark) {
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = b.clone().sub(a);
const count = Math.max(1, Math.ceil(direction.length() / 0.11));
for (let j = 0; j < count; j++) {
const p0 = a.clone().lerp(b, j / count);
const p1 = a.clone().lerp(b, (j + 1) / count);
const midpoint = p0.clone().add(p1).multiplyScalar(0.5);
const length = p0.distanceTo(p1);
const segment = box(
scene,
[0.055, length * 1.12, 0.055],
midpoint.toArray(),
material,
false,
false
);
segment.quaternion.setFromUnitVectors(wireUp, p1.clone().sub(p0).normalize());
}
}
}
cableBetween([
new THREE.Vector3(-3.78, 1.46, 0.38),
new THREE.Vector3(-3.42, 1.62, 0.42),
new THREE.Vector3(-3.07, 2.19, 0.55),
leftSupport
]);
cableBetween([
rightSupport,
new THREE.Vector3(3.07, 2.19, 0.55),
new THREE.Vector3(3.45, 1.61, 0.42),
new THREE.Vector3(3.75, 1.44, 0.38)
], palette.copperDark);
// Signal pulse and its square voxel trail.
const pulseGroup = new THREE.Group();
scene.add(pulseGroup);
const pulseMaterials = [];
for (let i = 0; i < 7; i++) {
const material = new THREE.MeshStandardMaterial({
color: i === 0 ? 0xdffffb : 0x62e7e2,
emissive: 0x39dcd6,
emissiveIntensity: i === 0 ? 3.8 : 1.8,
transparent: true,
opacity: i === 0 ? 1 : 0.66 - i * 0.07,
roughness: 0.28,
depthWrite: false
});
pulseMaterials.push(material);
const size = i === 0 ? 0.22 : 0.15;
const cube = box(
pulseGroup,
[size, size, size],
[0, 0, 0],
material,
false,
false
);
cube.visible = false;
}
const pulseLight = new THREE.PointLight(0x62e7e2, 0, 4.5, 2);
scene.add(pulseLight);
// Shared simulation clock. Every displayed clock is derived from simTime.
const DURATION = 6.5;
const SEND_START = 0.75;
const SEND_END = 1.75; // One Morse timing unit.
const REPLY_START = 4.75; // Three-unit gap after the payload character.
const REPLY_END = 5.75;
let elapsed = 0;
let simTime = 0;
let playing = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let completed = false;
let speed = 1;
const speeds = [0.5, 1, 1.5, 2];
function formatClock(t) {
const minutes = Math.floor(t / 60);
const seconds = Math.floor(t % 60);
const millis = Math.floor((t % 1) * 1000);
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(millis).padStart(3, "0")}`;
}
function getStatus(t) {
if (t < SEND_START) return "READY · sender armed";
if (t < SEND_END) return "TX · one dot traveling toward the sounder";
if (t < REPLY_START) return "RX · sounder received the payload dot";
if (t < REPLY_END) return "ACK · one acknowledgment dot returning";
return "COMPLETE · one symbol exchanged in both directions";
}
function updateClock() {
const formatted = formatClock(simTime);
senderClockEl.textContent = formatted;
sounderClockEl.textContent = formatted;
masterClockEl.textContent = `${formatted} / ${formatClock(DURATION)}`;
nowLine.style.left = `${(simTime / DURATION) * 100}%`;
statusEl.textContent = getStatus(simTime);
}
function setPlaying(value) {
playing = value;
completed = false;
playButton.textContent = playing ? "PAUSE" : "PLAY";
}
playButton.addEventListener("click", () => {
if (completed || elapsed >= DURATION) {
elapsed = 0;
completed = false;
setPlaying(true);
} else {
setPlaying(!playing);
}
});
replayButton.addEventListener("click", () => {
elapsed = 0;
completed = false;
setPlaying(true);
});
speedButton.addEventListener("click", () => {
const index = speeds.indexOf(speed);
speed = speeds[(index + 1) % speeds.length];
speedButton.textContent = `${speed}×`;
});
function animateSignal(t) {
let active = false;
let direction = 1;
let progress = 0;
if (t >= SEND_START && t < SEND_END) {
active = true;
direction = 1;
progress = (t - SEND_START) / (SEND_END - SEND_START);
} else if (t >= REPLY_START && t < REPLY_END) {
active = true;
direction = -1;
progress = (t - REPLY_START) / (REPLY_END - REPLY_START);
}
pulseGroup.visible = active;
pulseLight.intensity = active ? 2.6 : 0;
if (active) {
const currentU = direction === 1 ? progress : 1 - progress;
pulseGroup.children.forEach((cube, i) => {
const trailU = direction === 1
? currentU - i * 0.032
: currentU + i * 0.032;
cube.visible = trailU >= 0 && trailU <= 1;
if (!cube.visible) return;
cube.position.copy(lineCurve.getPointAt(THREE.MathUtils.clamp(trailU, 0, 1)));
const scale = i === 0 ? 1 : 0.85 - i * 0.08;
cube.scale.setScalar(scale);
});
const glowPosition = lineCurve.getPointAt(currentU);
pulseLight.position.copy(glowPosition);
pulseLight.color.set(direction === 1 ? 0x62e7e2 : 0xffb75b);
}
}
function animateMechanisms(t) {
// Sender key travels down during the one-unit payload.
if (t >= SEND_START && t < SEND_END) {
const p = (t - SEND_START) / (SEND_END - SEND_START);
sender.lever.rotation.z = -0.20 * Math.sin(Math.PI * p);
} else {
sender.lever.rotation.z *= 0.82;
}
// Sounder armature clicks at receipt.
const receiveAge = t - SEND_END;
const receiveClick = receiveAge >= 0 && receiveAge < 0.30
? Math.exp(-receiveAge * 13) * Math.sin(receiveAge * 58)
: 0;
sounder.lever.rotation.z = -0.16 * receiveClick;
// Reply plunger moves for the returned acknowledgment.
if (t >= REPLY_START && t < REPLY_END) {
const p = (t - REPLY_START) / (REPLY_END - REPLY_START);
sounder.lever.rotation.z += 0.08 * Math.sin(Math.PI * p);
}
// Sounder lamp flashes on receipt.
const receiveFlash = receiveAge >= 0 && receiveAge < 0.55
? Math.exp(-receiveAge * 7)
: 0;
sounder.lampMat.emissiveIntensity = 0.35 + receiveFlash * 4.2;
// Sender lamp flashes when the acknowledgment arrives.
const replyAge = t - REPLY_END;
const replyFlash = replyAge >= 0 && replyAge < 0.65
? Math.exp(-replyAge * 6)
: 0;
sender.lampMat.emissiveIntensity = 0.35 + replyFlash * 4.8;
}
// Camera controls are implemented directly here, without Three.js addons.
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.005, 0.18, 1.05);
});
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.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.8
);
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraState.yaw = 0.15;
cameraState.pitch = 0.49;
cameraState.zoom = 1;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
const aspect = width / height;
const halfHeight = Math.max(5.0, 7.2 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function updateCamera() {
const { yaw, pitch, zoom, distance } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
const senderAnchor = new THREE.Vector3(-4.35, 3.85, -0.05);
const sounderAnchor = new THREE.Vector3(4.35, 3.85, -0.05);
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.display = projected.z > 1 ? "none" : "block";
}
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed = Math.min(DURATION, elapsed + dt * speed);
if (elapsed >= DURATION) {
playing = false;
completed = true;
playButton.textContent = "PLAY";
}
}
simTime = elapsed;
updateClock();
animateSignal(simTime);
animateMechanisms(simTime);
updateCamera();
positionLabel(document.getElementById("senderLabel"), senderAnchor);
positionLabel(document.getElementById("sounderLabel"), sounderAnchor);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
});
</script>
</body>
</html>
```