Prompt specification
Build or customize the Three.js 3D scene "Wave arrival station explorer" 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: Wave arrival station explorer
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wave-arrival-station-explorer-x1184
Scene Description Prompt:
Animate faster and slower seismic waves reaching low-poly stations around a schematic source at consistent speeds. Three.js from cdnjs, one HTML file.
Working Three.js Starter (wave-arrival-station-explorer-x1184):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seismic Wave Propagation</title>
<style>
:root {
--bg: #050b13;
--panel: rgba(8, 17, 29, 0.78);
--border: rgba(139, 190, 220, 0.16);
--text: #e7f3fb;
--muted: #7890a5;
--p: #4fe7ff;
--s: #ffb45e;
}
* {
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;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 20px 22px 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #8ca7bc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--p);
box-shadow: 0 0 12px var(--p);
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 370px;
margin: 12px 0 16px;
color: #91a6b8;
font-size: 12px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
min-width: 145px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: #a9bac8;
font-size: 10px;
}
.legend-item strong {
display: block;
color: var(--text);
font-size: 12px;
}
.swatch {
width: 8px;
height: 28px;
flex: 0 0 auto;
border-radius: 5px;
background: var(--p);
box-shadow: 0 0 12px color-mix(in srgb, var(--p), transparent 45%);
}
.swatch.s {
background: var(--s);
box-shadow: 0 0 12px color-mix(in srgb, var(--s), transparent 45%);
}
.controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 7px;
}
button {
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.045);
color: #c9d8e5;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:hover {
border-color: rgba(79, 231, 255, 0.35);
background: rgba(79, 231, 255, 0.08);
}
button:active {
transform: translateY(1px);
}
.station-panel {
top: 82px;
right: 22px;
width: 318px;
padding: 16px;
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-heading span {
color: var(--muted);
font-size: 9px;
}
.station-list {
display: grid;
gap: 5px;
}
.station-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 9px;
border: 1px solid transparent;
border-radius: 8px;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease;
}
.station-row:hover,
.station-row.selected {
border-color: rgba(79, 231, 255, 0.15);
background: rgba(79, 231, 255, 0.045);
}
.station-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #42566a;
transition: background 120ms ease, box-shadow 120ms ease;
}
.station-name strong {
display: block;
color: #d8e6f0;
font-size: 11px;
}
.station-name small {
color: #71889b;
font-size: 9px;
}
.station-status {
color: #657c90;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.station-times {
grid-column: 2 / 4;
color: #61798d;
font-size: 9px;
}
.trace-panel {
right: 22px;
bottom: 22px;
width: 318px;
padding: 15px 16px 13px;
}
.trace-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 9px;
}
.trace-heading strong {
font-size: 11px;
}
.trace-heading span {
color: #71889b;
font-size: 9px;
}
#trace {
display: block;
width: 100%;
height: 105px;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 8px;
background: rgba(0, 0, 0, 0.12);
}
.trace-legend {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #71889b;
font-size: 9px;
}
.trace-legend b {
color: var(--p);
font-weight: 700;
}
.trace-legend b:last-child {
color: var(--s);
}
.status-card {
left: 22px;
bottom: 22px;
width: 285px;
padding: 14px 16px;
pointer-events: none;
}
.status-row {
display: flex;
justify-content: space-between;
gap: 10px;
color: #92a7b8;
font-size: 10px;
}
.status-row strong {
color: #e4f0f8;
font-variant-numeric: tabular-nums;
}
.progress-track {
height: 3px;
margin-top: 11px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.07);
}
.progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--p), var(--s));
box-shadow: 0 0 10px rgba(79, 231, 255, 0.45);
}
.hint {
margin-top: 9px;
color: #526b80;
font-size: 9px;
line-height: 1.45;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px;
}
.subtitle {
display: none;
}
.legend-item {
min-width: 135px;
}
.controls {
top: 145px;
right: 12px;
}
.station-panel {
top: 195px;
right: 12px;
width: 242px;
max-height: 43vh;
overflow: auto;
}
.trace-panel {
display: none;
}
.status-card {
left: 12px;
bottom: 12px;
width: 235px;
}
}
@media (max-height: 620px) {
.trace-panel,
.station-panel {
display: none;
}
}
</style>
</head>
<body>
<div
id="viewport"
role="img"
aria-label="Interactive three-dimensional visualization of P and S seismic waves reaching monitoring stations"
></div>
<section class="panel title-card">
<div class="eyebrow">
<span class="live-dot"></span>
Seismic propagation model
</div>
<h1>WAVE ARRIVAL LAB</h1>
<p class="subtitle">
A schematic source emits a fast compression wave and a slower shear wave.
Both travel radially at constant speed through the surrounding medium.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
<span><strong>P wave · 6.0 km/s</strong>Fast compression wave</span>
</div>
<div class="legend-item">
<span class="swatch s"></span>
<span><strong>S wave · 3.0 km/s</strong>Slower shear wave</span>
</div>
</div>
</section>
<nav class="panel controls" aria-label="Animation controls">
<button id="pauseButton" type="button">Pause</button>
<button id="resetButton" type="button">Reset waves</button>
<button id="cameraButton" type="button">Reset camera</button>
</nav>
<aside class="panel station-panel">
<div class="panel-heading">
<h2>Station arrivals</h2>
<span>P arrival / S arrival</span>
</div>
<div id="stationList" class="station-list"></div>
</aside>
<section class="panel trace-panel">
<div class="trace-heading">
<strong id="traceTitle">Synthetic station trace</strong>
<span>6.4 s window</span>
</div>
<canvas id="trace" width="560" height="210"></canvas>
<div class="trace-legend">
<span><b>P</b> compression arrival</span>
<span><b>S</b> shear arrival</span>
</div>
</section>
<section class="panel status-card">
<div class="status-row">
<span>Source state</span>
<strong id="sourceState">EMITTING</strong>
</div>
<div class="status-row" style="margin-top: 6px">
<span>Cycle time</span>
<strong id="cycleTime">T + 0.00 s</strong>
</div>
<div class="progress-track">
<div id="progressFill" class="progress-fill"></div>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom · Space to pause<br />
Click a station to inspect its trace.
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const SOURCE = new THREE.Vector3(0, -4.5, 0);
const P_SPEED = 6.0;
const S_SPEED = 3.0;
const CYCLE_DURATION = 6.4;
const TAU = Math.PI * 2;
const P_COLOR = 0x4fe7ff;
const S_COLOR = 0xffb45e;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050b13);
scene.fog = new THREE.FogExp2(0x050b13, 0.009);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Orbitable seismic wave visualization"
);
viewport.appendChild(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0x9ed7ff, 0x09111b, 1.8));
const keyLight = new THREE.DirectionalLight(0xd8efff, 2.7);
keyLight.position.set(14, 24, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -24;
keyLight.shadow.camera.right = 24;
keyLight.shadow.camera.top = 24;
keyLight.shadow.camera.bottom = -24;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 70;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x317ca8, 1.2);
rimLight.position.set(-18, 5, -16);
scene.add(rimLight);
// Schematic medium and surface grid
const surfaceMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1c29,
roughness: 0.95,
metalness: 0.05,
flatShading: true,
transparent: true,
opacity: 0.7,
depthWrite: false
});
const surface = new THREE.Mesh(
new THREE.CylinderGeometry(20, 20, 0.24, 40),
surfaceMaterial
);
surface.position.y = -0.12;
surface.receiveShadow = true;
scene.add(surface);
const mediumMaterial = new THREE.MeshBasicMaterial({
color: 0x15364d,
transparent: true,
opacity: 0.07,
side: THREE.DoubleSide,
depthWrite: false
});
const medium = new THREE.Mesh(
new THREE.CylinderGeometry(20, 20, 4.5, 40, 1, true),
mediumMaterial
);
medium.position.y = -2.35;
scene.add(medium);
const gridMaterial = new THREE.LineBasicMaterial({
color: 0x35647e,
transparent: true,
opacity: 0.24,
depthWrite: false
});
function addCircle(radius, color = gridMaterial, y = 0.025) {
const points = [];
for (let i = 0; i < 96; i++) {
const angle = (i / 96) * TAU;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
)
);
}
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
color
);
line.renderOrder = 2;
scene.add(line);
}
[5, 10, 15, 20].forEach((radius) => addCircle(radius));
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * TAU;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.025, 0),
new THREE.Vector3(
Math.cos(angle) * 20,
0.025,
Math.sin(angle) * 20
)
]);
const line = new THREE.Line(geometry, gridMaterial);
line.renderOrder = 2;
scene.add(line);
}
const rim = new THREE.Mesh(
new THREE.TorusGeometry(20, 0.045, 5, 128),
new THREE.MeshBasicMaterial({
color: 0x3b7f9f,
transparent: true,
opacity: 0.38
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.015;
scene.add(rim);
// Underground source
const sourceCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.72, 0),
new THREE.MeshStandardMaterial({
color: 0xff9a4b,
emissive: 0xff5d1f,
emissiveIntensity: 2.5,
roughness: 0.4,
flatShading: true
})
);
sourceCore.position.copy(SOURCE);
sourceCore.castShadow = true;
scene.add(sourceCore);
const sourceWire = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 1),
new THREE.MeshBasicMaterial({
color: 0xffb25f,
wireframe: true,
transparent: true,
opacity: 0.4,
depthWrite: false
})
);
sourceWire.position.copy(SOURCE);
scene.add(sourceWire);
const sourceHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.25, 0.035, 5, 64),
new THREE.MeshBasicMaterial({
color: 0xff9b4a,
transparent: true,
opacity: 0.6,
depthWrite: false
})
);
sourceHalo.rotation.x = Math.PI / 2;
sourceHalo.position.copy(SOURCE);
scene.add(sourceHalo);
const sourceLight = new THREE.PointLight(0xff7c32, 18, 18, 2);
sourceLight.position.copy(SOURCE);
scene.add(sourceLight);
const sourceStem = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
SOURCE,
new THREE.Vector3(0, 0.05, 0)
]),
new THREE.LineDashedMaterial({
color: 0xa8c6d9,
dashSize: 0.35,
gapSize: 0.22,
transparent: true,
opacity: 0.3
})
);
sourceStem.computeLineDistances();
scene.add(sourceStem);
// Expanding wavefronts represented by three orthogonal rings.
function createWavefront(color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.18,
depthTest: false,
depthWrite: false
});
const group = new THREE.Group();
group.position.copy(SOURCE);
group.renderOrder = 7;
const geometry = new THREE.TorusGeometry(1, 0.006, 4, 96);
const horizontal = new THREE.Mesh(geometry, material);
horizontal.rotation.x = Math.PI / 2;
const verticalXY = new THREE.Mesh(geometry, material);
const verticalYZ = new THREE.Mesh(geometry, material);
verticalYZ.rotation.y = Math.PI / 2;
group.add(horizontal, verticalXY, verticalYZ);
scene.add(group);
return { group, material };
}
const pFront = createWavefront(P_COLOR);
const sFront = createWavefront(S_COLOR);
function createPacket(color) {
const group = new THREE.Group();
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 8, 6),
new THREE.MeshBasicMaterial({
color,
depthTest: false,
depthWrite: false
})
);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 8, 6),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.16,
depthTest: false,
depthWrite: false
})
);
group.add(core, halo);
group.renderOrder = 9;
group.visible = false;
scene.add(group);
return { group, halo };
}
function createLabel(text, distance) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(6, 15, 24, 0.88)";
context.strokeStyle = "rgba(127, 184, 211, 0.28)";
context.lineWidth = 3;
context.beginPath();
context.roundRect(5, 5, 502, 102, 18);
context.fill();
context.stroke();
context.fillStyle = "#e6f3fb";
context.font = "700 31px system-ui, sans-serif";
context.fillText(text, 24, 48);
context.fillStyle = "#7f9caf";
context.font = "500 22px system-ui, sans-serif";
context.fillText(`${distance.toFixed(1)} km from source`, 24, 83);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(4.6, 1.0, 1);
sprite.center.set(0.5, 0);
sprite.renderOrder = 12;
return sprite;
}
const stationDefinitions = [
{ angle: -0.36, radius: 14.2 },
{ angle: 0.38, radius: 16.1 },
{ angle: 1.16, radius: 13.2 },
{ angle: 1.88, radius: 16.8 },
{ angle: 2.67, radius: 14.6 },
{ angle: 3.37, radius: 15.4 },
{ angle: 4.12, radius: 12.8 },
{ angle: 5.02, radius: 16.4 }
];
const stations = [];
const stationHitMeshes = [];
const stationListElement = document.getElementById("stationList");
function createImpactRing(color) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.35, 0.45, 40),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthTest: false,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.visible = false;
ring.renderOrder = 10;
scene.add(ring);
return ring;
}
stationDefinitions.forEach((definition, index) => {
const x = Math.cos(definition.angle) * definition.radius;
const z = Math.sin(definition.angle) * definition.radius;
const endpoint = new THREE.Vector3(x, 0.12, z);
const distance = SOURCE.distanceTo(endpoint);
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = -definition.angle;
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x25394c,
roughness: 0.9,
flatShading: true
});
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x385269,
roughness: 0.75,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x5a7690,
roughness: 0.65,
flatShading: true
});
const statusMaterial = new THREE.MeshStandardMaterial({
color: 0x31485d,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.3,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 1.08, 0.32, 6),
baseMaterial
);
base.position.y = 0.16;
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.68, 0.86),
bodyMaterial
);
body.position.y = 0.65;
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.73, 0.54, 4),
roofMaterial
);
roof.position.y = 1.25;
roof.rotation.y = Math.PI / 4;
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.05, 0.07, 0.95, 6),
baseMaterial
);
mast.position.y = 1.72;
const sensor = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
statusMaterial
);
sensor.position.y = 2.24;
group.add(base, body, roof, mast, sensor);
scene.add(group);
const label = createLabel(
`ST-${String(index + 1).padStart(2, "0")}`,
distance
);
label.position.set(0, 2.65, 0);
group.add(label);
const path = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([SOURCE, endpoint]),
new THREE.LineBasicMaterial({
color: 0x6c91aa,
transparent: true,
opacity: 0.17,
depthTest: false,
depthWrite: false
})
);
path.renderOrder = 3;
scene.add(path);
body.userData.stationIndex = index;
sensor.userData.stationIndex = index;
stationHitMeshes.push(body, sensor);
const station = {
index,
endpoint,
distance,
pArrival: distance / P_SPEED,
sArrival: distance / S_SPEED,
statusMaterial,
pPacket: createPacket(P_COLOR),
sPacket: createPacket(S_COLOR),
pImpact: createImpactRing(P_COLOR),
sImpact: createImpactRing(S_COLOR)
};
station.pImpact.position.set(x, 0.055, z);
station.sImpact.position.set(x, 0.058, z);
stations.push(station);
const row = document.createElement("div");
row.className = "station-row";
row.tabIndex = 0;
row.setAttribute("role", "button");
row.setAttribute(
"aria-label",
`Inspect station ${index + 1}, ${distance.toFixed(1)} kilometers from source`
);
row.innerHTML = `
<span class="station-dot"></span>
<span class="station-name">
<strong>ST-${String(index + 1).padStart(2, "0")}</strong>
<small>${distance.toFixed(1)} km</small>
</span>
<span class="station-status">—</span>
<span class="station-times">
P ${station.pArrival.toFixed(1)} s · S ${station.sArrival.toFixed(1)} s
</span>
`;
row.addEventListener("click", () => selectStation(index));
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectStation(index);
}
});
stationListElement.appendChild(row);
station.row = row;
station.dot = row.querySelector(".station-dot");
station.status = row.querySelector(".station-status");
});
let selectedStationIndex = 4;
function selectStation(index) {
selectedStationIndex = index;
stations.forEach((station) => {
station.row.classList.toggle("selected", station.index === index);
});
document.getElementById("traceTitle").textContent =
`Synthetic trace · ST-${String(index + 1).padStart(2, "0")}`;
drawTrace();
}
// Custom camera controls: no addon imports.
const cameraTarget = new THREE.Vector3(0, -0.8, 0);
const spherical = new THREE.Spherical(43, 1.08, 0.68);
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
function resetCamera() {
spherical.set(43, 1.08, 0.68);
updateCamera();
}
updateCamera();
let pointerDown = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown || event.pointerId !== pointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.22,
Math.PI / 2 - 0.03
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown || event.pointerId !== pointerId) return;
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragDistance < 5) {
selectStationFromPointer(event);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
25,
72
);
updateCamera();
},
{ passive: false }
);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectStationFromPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
stationHitMeshes,
false
);
if (intersections.length) {
selectStation(intersections[0].object.userData.stationIndex);
}
}
// Animation controls
let simulationTime = 0;
let paused = false;
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
const cameraButton = document.getElementById("cameraButton");
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
}
pauseButton.addEventListener("click", togglePause);
resetButton.addEventListener("click", () => {
simulationTime = 0;
});
cameraButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.code === "KeyR") {
simulationTime = 0;
}
});
// Synthetic station trace
const traceCanvas = document.getElementById("trace");
const traceContext = traceCanvas.getContext("2d");
function hashNoise(value) {
const result = Math.sin(value * 12.9898) * 43758.5453;
return result - Math.floor(result);
}
function drawTrace() {
const station = stations[selectedStationIndex];
const context = traceContext;
const width = traceCanvas.width;
const height = traceCanvas.height;
context.clearRect(0, 0, width, height);
context.strokeStyle = "rgba(130, 169, 192, 0.09)";
context.lineWidth = 1;
for (let i = 1; i < 6; i++) {
const x = (i / 6) * width;
context.beginPath();
context.moveTo(x, 0);
context.lineTo(x, height);
context.stroke();
}
for (let i = 1; i < 4; i++) {
const y = (i / 4) * height;
context.beginPath();
context.moveTo(0, y);
context.lineTo(width, y);
context.stroke();
}
const centerY = height * 0.53;
const amplitude = 43;
const samples = 280;
function sampleAt(time, index) {
const noise = (hashNoise(index + 1) - 0.5) * 0.035;
let p = 0;
let s = 0;
if (time >= station.pArrival) {
const age = time - station.pArrival;
p = Math.exp(-age * 1.45) *
0.28 *
Math.sin(age * 80);
}
if (time >= station.sArrival) {
const age = time - station.sArrival;
s = Math.exp(-age * 0.82) *
0.68 *
Math.sin(age * 31 + 0.5);
}
return { p, s, noise };
}
function drawSeries(color, key) {
context.beginPath();
for (let i = 0; i < samples; i++) {
const time = (i / (samples - 1)) * CYCLE_DURATION;
const value = sampleAt(time, i);
const x = (i / (samples - 1)) * width;
const y = centerY - (value[key] + value.noise) * amplitude;
if (i === 0) context.moveTo(x, y);
else context.lineTo(x, y);
}
context.strokeStyle = color;
context.lineWidth = 2;
context.stroke();
}
drawSeries("#4fe7ff", "p");
drawSeries("#ffb45e", "s");
const pX = (station.pArrival / CYCLE_DURATION) * width;
const sX = (station.sArrival / CYCLE_DURATION) * width;
context.setLineDash([5, 5]);
context.strokeStyle = "rgba(79, 231, 255, 0.55)";
context.beginPath();
context.moveTo(pX, 0);
context.lineTo(pX, height);
context.stroke();
context.strokeStyle = "rgba(255, 180, 94, 0.55)";
context.beginPath();
context.moveTo(sX, 0);
context.lineTo(sX, height);
context.stroke();
context.setLineDash([]);
const playheadX = ((simulationTime % CYCLE_DURATION) / CYCLE_DURATION) * width;
context.strokeStyle = "rgba(255,255,255,0.5)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(playheadX, 0);
context.lineTo(playheadX, height);
context.stroke();
context.fillStyle = "rgba(215,235,247,0.75)";
context.font = "600 16px system-ui, sans-serif";
context.fillText("P", pX + 7, 19);
context.fillText("S", sX + 7, 38);
}
const cycleTimeElement = document.getElementById("cycleTime");
const sourceStateElement = document.getElementById("sourceState");
const progressFill = document.getElementById("progressFill");
function updateStationState(station, cycleTime) {
const pHit = cycleTime >= station.pArrival;
const sHit = cycleTime >= station.sArrival;
if (sHit) {
station.statusMaterial.color.setHex(0xffb45e);
station.statusMaterial.emissive.setHex(S_COLOR);
station.statusMaterial.emissiveIntensity = 1.8;
station.dot.style.background = "#ffb45e";
station.dot.style.boxShadow = "0 0 10px rgba(255,180,94,0.8)";
station.status.textContent = "P + S";
station.status.style.color = "#ffb45e";
} else if (pHit) {
station.statusMaterial.color.setHex(0x4fe7ff);
station.statusMaterial.emissive.setHex(P_COLOR);
station.statusMaterial.emissiveIntensity = 1.8;
station.dot.style.background = "#4fe7ff";
station.dot.style.boxShadow = "0 0 10px rgba(79,231,255,0.8)";
station.status.textContent = "P";
station.status.style.color = "#4fe7ff";
} else {
station.statusMaterial.color.setHex(0x31485d);
station.statusMaterial.emissive.setHex(0x000000);
station.statusMaterial.emissiveIntensity = 0;
station.dot.style.background = "#42566a";
station.dot.style.boxShadow = "none";
station.status.textContent = "—";
station.status.style.color = "#657c90";
}
const pAge = cycleTime - station.pArrival;
const sAge = cycleTime - station.sArrival;
if (pAge >= 0 && pAge < 1.45) {
station.pImpact.visible = true;
station.pImpact.scale.setScalar(0.75 + pAge * 2.3);
station.pImpact.material.opacity = (1 - pAge / 1.45) * 0.85;
} else {
station.pImpact.visible = false;
}
if (sAge >= 0 && sAge < 1.65) {
station.sImpact.visible = true;
station.sImpact.scale.setScalar(0.75 + sAge * 2.1);
station.sImpact.material.opacity = (1 - sAge / 1.65) * 0.9;
} else {
station.sImpact.visible = false;
}
}
function updatePacket(packet, speed, cycleTime, station) {
const traveled = speed * cycleTime;
const visible = traveled <= station.distance + 0.02;
packet.group.visible = visible;
if (!visible) return;
const fraction = THREE.MathUtils.clamp(
traveled / station.distance,
0,
1
);
packet.group.position
.copy(SOURCE)
.lerp(station.endpoint, fraction);
const pulse = 1 + Math.sin(cycleTime * 19 + station.index) * 0.12;
packet.halo.scale.setScalar(pulse);
}
function updateWavefront(front, speed, cycleTime, maxRadius) {
const radius = speed * cycleTime;
const fade = THREE.MathUtils.clamp(
(maxRadius - radius) / 3,
0,
1
);
front.group.visible = radius > 0.02 && fade > 0;
if (front.group.visible) {
front.group.scale.setScalar(Math.max(radius, 0.001));
front.material.opacity = 0.18 * fade;
}
}
function updateUI(cycleTime) {
stations.forEach((station) => {
updateStationState(station, cycleTime);
});
cycleTimeElement.textContent = `T + ${cycleTime.toFixed(2)} s`;
progressFill.style.width = `${(cycleTime / CYCLE_DURATION) * 100}%`;
sourceStateElement.textContent =
cycleTime < 0.22 ? "EMITTING" : "PROPAGATING";
drawTrace();
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
}
const cycleTime = simulationTime % CYCLE_DURATION;
const maxRadius =
Math.max(...stations.map((station) => station.distance)) + 2.5;
updateWavefront(pFront, P_SPEED, cycleTime, maxRadius);
updateWavefront(sFront, S_SPEED, cycleTime, maxRadius);
stations.forEach((station) => {
updatePacket(station.pPacket, P_SPEED, cycleTime, station);
updatePacket(station.sPacket, S_SPEED, cycleTime, station);
});
const sourcePhase = (cycleTime % 1.2) / 1.2;
sourceHalo.scale.setScalar(0.75 + sourcePhase * 2.6);
sourceHalo.material.opacity = 0.55 * (1 - sourcePhase);
sourceWire.rotation.y += delta * 0.55;
sourceWire.rotation.x += delta * 0.22;
sourceCore.rotation.y -= delta * 0.8;
sourceCore.material.emissiveIntensity =
2.1 + Math.sin(cycleTime * 8) * 0.65;
uiAccumulator += delta;
if (uiAccumulator > 0.075) {
uiAccumulator = 0;
updateUI(cycleTime);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
selectStation(selectedStationIndex);
updateUI(0);
animate();
</script>
</body>
</html>
```