Prompt specification
Build or customize the Three.js 3D scene "Source Receiver and Traveling Pulse" 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: Source Receiver and Traveling Pulse
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/source-receiver-and-traveling-pulse-x3785
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts finite light-travel time and communication delay. Model a source and receiver separated by a measured path with one moving light-pulse marker. State the schematic speed and distinguish emission from reception events. Low-poly.
Working Three.js Starter (source-receiver-and-traveling-pulse-x3785):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Finite Light-Travel Time</title>
<style>
:root {
--bg: #06101a;
--panel: rgba(7, 18, 30, 0.82);
--border: rgba(132, 205, 220, 0.22);
--text: #e7f4f7;
--muted: #8fa8b2;
--cyan: #62e5ef;
--amber: #ffc857;
--green: #66e6a6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
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;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 42px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.intro p {
margin: 12px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
top: 22px;
right: 22px;
width: 286px;
padding: 17px 18px;
border-radius: 18px;
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 12px;
align-items: baseline;
padding: 10px 0;
border-bottom: 1px solid rgba(132, 205, 220, 0.12);
}
.metric:last-of-type {
border-bottom: 0;
}
.metric-label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric-value {
color: var(--text);
font-size: 17px;
font-variant-numeric: tabular-nums;
font-weight: 750;
white-space: nowrap;
}
.metric-value.amber {
color: var(--amber);
}
.metric-value.green {
color: var(--green);
}
.metric-note {
margin-top: 11px;
padding-top: 12px;
border-top: 1px solid rgba(132, 205, 220, 0.12);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.timeline-panel {
left: 50%;
bottom: 20px;
width: min(820px, calc(100vw - 32px));
padding: 16px 18px 15px;
border-radius: 18px;
transform: translateX(-50%);
}
.timeline-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
margin-bottom: 12px;
}
.timeline-title {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.status-row {
display: flex;
align-items: center;
gap: 12px;
}
.status {
display: flex;
align-items: center;
gap: 7px;
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.status::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 13px currentColor;
content: "";
}
.status.received {
color: var(--green);
}
.status.paused {
color: var(--muted);
}
#clock {
min-width: 88px;
color: var(--text);
font-size: 12px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.track {
position: relative;
height: 6px;
border-radius: 99px;
background: rgba(115, 165, 180, 0.18);
}
#progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--amber), var(--cyan));
box-shadow: 0 0 15px rgba(98, 229, 239, 0.35);
}
.event-dot {
position: absolute;
top: 50%;
width: 12px;
height: 12px;
border: 2px solid var(--bg);
border-radius: 50%;
transform: translate(-50%, -50%);
transition: background 180ms ease, box-shadow 180ms ease;
}
.event-dot.emission {
left: 0;
background: var(--amber);
}
.event-dot.reception {
left: 100%;
background: #48616d;
}
.event-dot.reception.reached {
background: var(--green);
box-shadow: 0 0 14px rgba(102, 230, 166, 0.8);
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.timeline-labels b {
color: var(--text);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.controls {
display: flex;
align-items: center;
gap: 8px;
}
button {
min-width: 78px;
padding: 9px 13px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(98, 229, 239, 0.08);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(98, 229, 239, 0.55);
background: rgba(98, 229, 239, 0.14);
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.world-label {
position: fixed;
z-index: 5;
min-width: 142px;
padding: 8px 11px;
border: 1px solid rgba(132, 205, 220, 0.2);
border-radius: 10px;
background: rgba(5, 14, 23, 0.78);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.22);
opacity: 0.55;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 180ms ease, border-color 180ms ease;
text-align: center;
}
.world-label.active {
opacity: 1;
}
.world-label.emission.active {
border-color: rgba(255, 200, 87, 0.55);
}
.world-label.reception.active {
border-color: rgba(102, 230, 166, 0.65);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.22),
0 0 22px rgba(102, 230, 166, 0.12);
}
.world-label strong {
display: block;
color: var(--amber);
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.world-label.reception strong {
color: var(--green);
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.world-label.path-label {
min-width: 120px;
padding: 6px 10px;
opacity: 0.85;
}
.world-label.path-label strong {
color: var(--cyan);
}
.hint {
position: fixed;
right: 22px;
bottom: 194px;
z-index: 4;
color: rgba(143, 168, 178, 0.72);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.intro p {
display: none;
}
h1 {
font-size: 27px;
}
.metrics {
top: 112px;
right: 12px;
width: 238px;
padding: 11px 14px;
}
.metric {
padding: 7px 0;
}
.metric-value {
font-size: 14px;
}
.metric-note {
display: none;
}
.timeline-panel {
bottom: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
.timeline-top {
align-items: flex-start;
gap: 8px;
}
.status-row {
flex-direction: column-reverse;
align-items: flex-end;
gap: 4px;
}
.timeline-title {
max-width: 100px;
line-height: 1.35;
}
.hint {
display: none;
}
.world-label {
min-width: 116px;
padding: 6px 8px;
}
.world-label strong {
font-size: 8px;
}
.world-label small {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Low-poly scene showing a light pulse traveling between a source and a receiver"
></canvas>
<section class="panel intro">
<div class="eyebrow">Finite propagation time</div>
<h1>Light takes time.</h1>
<p>
One light-pulse marker crosses a measured 12-unit path. The receiver
cannot know that a signal was sent until the pulse physically arrives.
</p>
</section>
<aside class="panel metrics">
<div class="metric">
<span class="metric-label">Measured path</span>
<span class="metric-value">12 units</span>
</div>
<div class="metric">
<span class="metric-label">Schematic light speed</span>
<span class="metric-value amber">c = 3 units/s</span>
</div>
<div class="metric">
<span class="metric-label">One-way delay</span>
<span class="metric-value green">L/c = 4.00 s</span>
</div>
<div class="metric-note">
This is a schematic scale, not a physical spatial scale. A reply cannot
begin at the source until the first signal has reached the receiver.
</div>
</aside>
<div id="source-label" class="world-label emission active">
<strong>Emission event</strong>
<small>Source · t = 0.00 s</small>
</div>
<div id="receiver-label" class="world-label reception">
<strong>Reception event</strong>
<small>Receiver · t = 4.00 s</small>
</div>
<div id="path-label" class="world-label path-label">
<strong>Measured path</strong>
<small>12 schematic units</small>
</div>
<section class="panel timeline-panel">
<div class="timeline-top">
<span class="timeline-title">One-way light-signal timeline</span>
<div class="status-row">
<span id="status" class="status">In transit</span>
<span id="clock" aria-live="polite">t = 0.00 s</span>
</div>
<div class="controls">
<button id="play-pause" type="button">Pause</button>
<button id="reset" type="button">Reset</button>
</div>
</div>
<div class="track" aria-hidden="true">
<div id="progress"></div>
<span id="emission-dot" class="event-dot emission"></span>
<span id="reception-dot" class="event-dot reception"></span>
</div>
<div class="timeline-labels">
<span>
Emission<br>
<b>t = 0 s</b>
</span>
<span style="text-align: right">
Reception<br>
<b>t = 4 s</b>
</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Schematic model
// -------------------------------------------------------------------------
const SOURCE_X = -6;
const RECEIVER_X = 6;
const PATH_LENGTH = 12; // schematic units
const LIGHT_SPEED = 3; // schematic units per second
const TRAVEL_TIME = PATH_LENGTH / LIGHT_SPEED; // exactly 4 seconds
const PATH_Y = 1.3;
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, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06101a);
scene.fog = new THREE.FogExp2(0x06101a, 0.024);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
// -------------------------------------------------------------------------
// Lighting and low-poly environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb9e7ff, 0x101a20, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe0ad, 3.2);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58dce9, 1.8);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x091722,
roughness: 0.96,
metalness: 0.05,
flatShading: true
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.055;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(44, 44, 0x285064, 0x122b38);
grid.position.y = -0.025;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// Sparse static stars, placed only as background geometry.
const starPositions = [];
let seed = 8127;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 150; i++) {
starPositions.push(
(random() - 0.5) * 42,
4 + random() * 15,
-7 - random() * 28
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0x91b9c8,
size: 0.045,
transparent: true,
opacity: 0.5,
sizeAttenuation: true
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Signal path
// -------------------------------------------------------------------------
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(SOURCE_X, PATH_Y, 0),
new THREE.Vector3(RECEIVER_X, PATH_Y, 0)
]);
const pathLine = new THREE.Line(
pathGeometry,
new THREE.LineDashedMaterial({
color: 0x5c91a6,
dashSize: 0.22,
gapSize: 0.16,
transparent: true,
opacity: 0.72
})
);
pathLine.computeLineDistances();
scene.add(pathLine);
// Ground-level measurement bracket.
const bracketMaterial = new THREE.LineBasicMaterial({
color: 0x4f8798,
transparent: true,
opacity: 0.68
});
function lineFromPoints(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
return new THREE.Line(geometry, bracketMaterial);
}
scene.add(
lineFromPoints([
[SOURCE_X, 0.015, 0],
[RECEIVER_X, 0.015, 0]
])
);
scene.add(
lineFromPoints([
[SOURCE_X, 0.015, -0.34],
[SOURCE_X, 0.015, 0.34]
])
);
scene.add(
lineFromPoints([
[RECEIVER_X, 0.015, -0.34],
[RECEIVER_X, 0.015, 0.34]
])
);
// -------------------------------------------------------------------------
// Source: faceted transmitter tower
// -------------------------------------------------------------------------
const sourceGroup = new THREE.Group();
sourceGroup.position.x = SOURCE_X;
scene.add(sourceGroup);
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x314957,
roughness: 0.72,
metalness: 0.38,
flatShading: true
});
const paleMetal = new THREE.MeshStandardMaterial({
color: 0x7295a1,
roughness: 0.58,
metalness: 0.48,
flatShading: true
});
const sourceBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.66, 0.78, 0.18, 8),
darkMetal
);
sourceBase.position.y = 0.09;
sourceBase.castShadow = true;
sourceBase.receiveShadow = true;
sourceGroup.add(sourceBase);
const sourceMast = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.25, 1.03, 6),
paleMetal
);
sourceMast.position.y = 0.67;
sourceMast.castShadow = true;
sourceGroup.add(sourceMast);
const sourceCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.12, 8),
darkMetal
);
sourceCollar.position.y = 1.13;
sourceCollar.castShadow = true;
sourceGroup.add(sourceCollar);
const sourceEmitterMaterial = new THREE.MeshStandardMaterial({
color: 0xffca61,
emissive: 0xff982d,
emissiveIntensity: 2.4,
roughness: 0.34,
metalness: 0.15,
flatShading: true
});
const sourceEmitter = new THREE.Mesh(
new THREE.OctahedronGeometry(0.31, 0),
sourceEmitterMaterial
);
sourceEmitter.position.y = PATH_Y;
sourceEmitter.castShadow = true;
sourceGroup.add(sourceEmitter);
const sourceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.026, 4, 12),
new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0xff9e32,
emissiveIntensity: 0.8,
roughness: 0.5
})
);
sourceRing.rotation.y = Math.PI / 2;
sourceRing.position.y = PATH_Y;
sourceGroup.add(sourceRing);
const sourceLight = new THREE.PointLight(0xffad42, 1.1, 4, 2);
sourceLight.position.y = PATH_Y;
sourceGroup.add(sourceLight);
// -------------------------------------------------------------------------
// Receiver: low-poly sensor and faceted dish
// -------------------------------------------------------------------------
const receiverGroup = new THREE.Group();
receiverGroup.position.x = RECEIVER_X;
scene.add(receiverGroup);
const receiverBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.66, 0.78, 0.18, 8),
darkMetal
);
receiverBase.position.y = 0.09;
receiverBase.castShadow = true;
receiverBase.receiveShadow = true;
receiverGroup.add(receiverBase);
const receiverMast = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.25, 1.03, 6),
paleMetal
);
receiverMast.position.y = 0.67;
receiverMast.castShadow = true;
receiverGroup.add(receiverMast);
const receiverCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.12, 8),
darkMetal
);
receiverCollar.position.y = 1.13;
receiverCollar.castShadow = true;
receiverGroup.add(receiverCollar);
const receiverSensorMaterial = new THREE.MeshStandardMaterial({
color: 0x71dba8,
emissive: 0x1c8d60,
emissiveIntensity: 0.35,
roughness: 0.36,
metalness: 0.2,
flatShading: true
});
const receiverSensor = new THREE.Mesh(
new THREE.OctahedronGeometry(0.32, 0),
receiverSensorMaterial
);
receiverSensor.position.y = PATH_Y;
receiverSensor.castShadow = true;
receiverGroup.add(receiverSensor);
const receiverRing = new THREE.Mesh(
new THREE.TorusGeometry(0.44, 0.026, 4, 12),
new THREE.MeshStandardMaterial({
color: 0x66e6a6,
emissive: 0x2ec27c,
emissiveIntensity: 0.22,
roughness: 0.5
})
);
receiverRing.rotation.y = Math.PI / 2;
receiverRing.position.y = PATH_Y;
receiverGroup.add(receiverRing);
// Faceted dish facing back toward the source.
const dishProfile = [
new THREE.Vector2(0.0, 0.0),
new THREE.Vector2(0.18, 0.04),
new THREE.Vector2(0.42, 0.13),
new THREE.Vector2(0.68, 0.28),
new THREE.Vector2(0.78, 0.34)
];
const dishMaterial = new THREE.MeshStandardMaterial({
color: 0x6f9baa,
roughness: 0.62,
metalness: 0.38,
flatShading: true,
side: THREE.DoubleSide
});
const dish = new THREE.Mesh(
new THREE.LatheGeometry(dishProfile, 10),
dishMaterial
);
dish.position.set(0.58, 1.46, 0);
dish.rotation.z = Math.PI / 2;
dish.castShadow = true;
receiverGroup.add(dish);
const dishSupport = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.02, 0.12),
paleMetal
);
dishSupport.position.set(0.58, 0.72, 0);
dishSupport.castShadow = true;
receiverGroup.add(dishSupport);
const receiverLight = new THREE.PointLight(0x66e6a6, 0, 5, 2);
receiverLight.position.y = PATH_Y;
receiverGroup.add(receiverLight);
// -------------------------------------------------------------------------
// The single moving light-pulse marker
// -------------------------------------------------------------------------
const pulseMaterial = new THREE.MeshStandardMaterial({
color: 0xfff4c4,
emissive: 0xffc857,
emissiveIntensity: 4.8,
roughness: 0.22,
metalness: 0.05,
flatShading: true
});
const pulse = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
pulseMaterial
);
pulse.position.set(SOURCE_X, PATH_Y, 0);
pulse.castShadow = true;
scene.add(pulse);
const pulseLight = new THREE.PointLight(0xffd36b, 3.0, 4.5, 2);
pulse.add(pulseLight);
// Static event flash rings emphasize the two distinct events.
function makeEventRing(color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.36, 0.405, 32),
material
);
ring.rotation.y = Math.PI / 2;
scene.add(ring);
return ring;
}
const emissionFlash = makeEventRing(0xffc857);
emissionFlash.position.set(SOURCE_X, PATH_Y, 0);
const receptionFlash = makeEventRing(0x66e6a6);
receptionFlash.position.set(RECEIVER_X, PATH_Y, 0);
// -------------------------------------------------------------------------
// Simulation state and UI
// -------------------------------------------------------------------------
const playPauseButton = document.getElementById("play-pause");
const resetButton = document.getElementById("reset");
const progressElement = document.getElementById("progress");
const clockElement = document.getElementById("clock");
const statusElement = document.getElementById("status");
const receptionDot = document.getElementById("reception-dot");
const sourceLabel = document.getElementById("source-label");
const receiverLabel = document.getElementById("receiver-label");
let simulationTime = 0;
let running = true;
let visualTime = 0;
let sourceBurstAt = 0;
let receptionBurstAt = null;
function resetSimulation(autoStart = false) {
simulationTime = 0;
running = autoStart;
sourceBurstAt = visualTime;
receptionBurstAt = null;
pulse.visible = true;
pulse.position.set(SOURCE_X, PATH_Y, 0);
receiverSensorMaterial.emissiveIntensity = 0.35;
receiverRing.material.emissiveIntensity = 0.22;
receiverLight.intensity = 0;
updateInterface();
}
function updateInterface() {
const fraction = simulationTime / TRAVEL_TIME;
progressElement.style.width = `${fraction * 100}%`;
clockElement.textContent = `t = ${simulationTime.toFixed(2)} s`;
const received = simulationTime >= TRAVEL_TIME;
receiverLabel.classList.toggle("active", received);
receptionDot.classList.toggle("reached", received);
statusElement.classList.toggle("received", received);
statusElement.classList.toggle("paused", !received && !running);
if (received) {
statusElement.textContent = "Received · 4.00 s delay";
} else if (running) {
statusElement.textContent = "In transit";
} else {
statusElement.textContent = "Paused";
}
if (received) {
playPauseButton.textContent = "Replay";
} else if (running) {
playPauseButton.textContent = "Pause";
} else {
playPauseButton.textContent = "Resume";
}
}
playPauseButton.addEventListener("click", () => {
if (simulationTime >= TRAVEL_TIME) {
resetSimulation(true);
} else {
running = !running;
updateInterface();
}
});
resetButton.addEventListener("click", () => {
resetSimulation(false);
});
// -------------------------------------------------------------------------
// Camera controls implemented directly: orbit, wheel zoom, touch pinch
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const pointers = new Map();
let cameraTheta = 0;
let cameraPhi = 1.12;
let cameraRadius = window.innerWidth < 760 ? 25 : 16.5;
let previousPinchDistance = 0;
function updateCamera() {
const horizontalRadius = cameraRadius * Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + horizontalRadius * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.0045,
0.52,
1.43
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
9,
40
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
9,
40
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playPauseButton.click();
} else if (event.code === "KeyR") {
resetSimulation(false);
} else if (event.code === "ArrowLeft") {
cameraTheta -= 0.08;
} else if (event.code === "ArrowRight") {
cameraTheta += 0.08;
} else if (event.code === "ArrowUp") {
cameraPhi = Math.max(0.52, cameraPhi - 0.06);
} else if (event.code === "ArrowDown") {
cameraPhi = Math.min(1.43, cameraPhi + 0.06);
} else if (event.code === "Equal" || event.code === "NumpadAdd") {
cameraRadius = Math.max(9, cameraRadius - 0.8);
} else if (event.code === "Minus" || event.code === "NumpadSubtract") {
cameraRadius = Math.min(40, cameraRadius + 0.8);
}
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Project DOM labels into the 3D scene
// -------------------------------------------------------------------------
const labelAnchors = [
{
element: sourceLabel,
position: new THREE.Vector3(SOURCE_X, 2.38, 0)
},
{
element: receiverLabel,
position: new THREE.Vector3(RECEIVER_X, 2.38, 0)
},
{
element: document.getElementById("path-label"),
position: new THREE.Vector3(0, 0.34, 0)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of labelAnchors) {
const projected = item.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
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);
});
let previousFrame = performance.now();
function animate(now) {
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
visualTime += delta;
if (running) {
simulationTime = Math.min(
TRAVEL_TIME,
simulationTime + delta
);
if (simulationTime >= TRAVEL_TIME) {
running = false;
receptionBurstAt = visualTime;
}
}
// The pulse's x-position is exactly x(t) = x0 + c*t.
const travelDistance = LIGHT_SPEED * simulationTime;
pulse.position.x = SOURCE_X + travelDistance;
pulse.visible = simulationTime < TRAVEL_TIME;
// Gentle rotation keeps the single marker visually faceted and alive.
pulse.rotation.x += delta * 1.8;
pulse.rotation.y += delta * 2.5;
// Emission event flash.
const sourceAge = visualTime - sourceBurstAt;
if (sourceAge >= 0 && sourceAge < 0.75) {
const t = sourceAge / 0.75;
emissionFlash.scale.setScalar(1 + t * 2.6);
emissionFlash.material.opacity = (1 - t) * 0.8;
} else {
emissionFlash.material.opacity = 0;
}
// Reception event flash.
if (receptionBurstAt !== null) {
const receptionAge = visualTime - receptionBurstAt;
if (receptionAge < 0.9) {
const t = receptionAge / 0.9;
receptionFlash.scale.setScalar(1 + t * 2.8);
receptionFlash.material.opacity = (1 - t) * 0.9;
} else {
receptionFlash.material.opacity = 0;
}
const receivedGlow = Math.max(0, 1 - receptionAge / 0.9);
receiverSensorMaterial.emissiveIntensity = 0.35 + receivedGlow * 3.1;
receiverRing.material.emissiveIntensity = 0.22 + receivedGlow * 2.6;
receiverLight.intensity = receivedGlow * 5.0;
}
updateInterface();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```