Prompt specification
Build or customize the Three.js 3D scene "Moving source wavefront rings" 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: Moving source wavefront rings
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/moving-source-wavefront-rings-x1537
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly moving wave source above a flat reference grid. Emit a new circular wavefront at regular intervals from the source's position at that emission time, then let each ring expand from its own fixed center. Keep the source at a constant subsonic speed so the spacing becomes compressed ahead and expanded behind without a shock front. Two stationary observer posts show successive wave arrivals. A pause control reveals the older emission centers and the source's current position, making clear that already emitted rings do not move along with the source.
Working Three.js Starter (moving-source-wavefront-rings-x1537):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Fixed-Origin Wavefronts</title>
<style>
:root {
color-scheme: dark;
--cyan: #56dcff;
--amber: #ffc857;
--purple: #bb9cff;
--orange: #ff9675;
--panel: rgba(7, 18, 27, 0.78);
--border: rgba(128, 220, 255, 0.2);
--muted: #91a8b8;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #07111a;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
#title {
top: 18px;
left: 18px;
width: min(380px, calc(100vw - 36px));
padding: 17px 18px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 7px;
font-size: clamp(21px, 3vw, 29px);
line-height: 1.05;
letter-spacing: -0.03em;
}
#title p {
margin: 0;
color: #b5c6d1;
font-size: 13px;
line-height: 1.45;
}
.formula {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255,255,255,0.09);
color: #d9edf6;
font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#stats {
top: 18px;
right: 18px;
width: 230px;
padding: 14px 16px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
color: #9cf3c7;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #71efad;
box-shadow: 0 0 12px #71efad;
}
.stat-row {
display: flex;
justify-content: space-between;
gap: 15px;
padding: 4px 0;
color: var(--muted);
font-size: 12px;
}
.stat-row strong {
color: #e9f8ff;
font-variant-numeric: tabular-nums;
}
#observers {
left: 18px;
bottom: 88px;
display: flex;
gap: 10px;
}
.observer-card {
width: 190px;
padding: 13px 14px;
border-top: 2px solid var(--purple);
transition: border-color 150ms ease, transform 150ms ease;
}
.observer-card.rear {
border-top-color: var(--orange);
}
.observer-card.ping {
animation: observerPing 650ms ease-out;
}
@keyframes observerPing {
0% { transform: scale(1); filter: brightness(1); }
25% { transform: scale(1.045); filter: brightness(1.7); }
100% { transform: scale(1); filter: brightness(1); }
}
.observer-name {
display: flex;
align-items: center;
gap: 8px;
color: #dcecff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
}
.observer-name i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--purple);
box-shadow: 0 0 10px var(--purple);
}
.rear .observer-name i {
background: var(--orange);
box-shadow: 0 0 10px var(--orange);
}
.observer-count {
margin: 8px 0 5px;
font-size: 13px;
color: #aabcc9;
}
.observer-count b {
color: white;
font-size: 24px;
line-height: 1;
margin-right: 4px;
}
.observer-interval {
color: var(--purple);
font-size: 12px;
font-weight: 700;
}
.rear .observer-interval {
color: var(--orange);
}
.observer-hint {
margin-top: 5px;
color: #849baa;
font-size: 10px;
line-height: 1.35;
}
#controls {
left: 50%;
bottom: 18px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
pointer-events: auto;
white-space: nowrap;
}
button {
appearance: none;
border: 1px solid rgba(95, 220, 255, 0.34);
border-radius: 9px;
padding: 10px 14px;
background: rgba(27, 70, 88, 0.65);
color: #eafaff;
font: 700 12px inherit;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(39, 99, 122, 0.8);
transform: translateY(-1px);
}
button.primary {
background: linear-gradient(135deg, #176d82, #285b82);
border-color: rgba(108, 229, 255, 0.6);
}
#camera-hint {
color: #829aaa;
font-size: 10px;
padding: 0 6px;
}
#pause-note {
right: 18px;
bottom: 88px;
width: min(335px, calc(100vw - 36px));
padding: 16px 17px;
border-color: rgba(255, 200, 87, 0.45);
background: rgba(43, 31, 10, 0.86);
transform: translateY(12px);
opacity: 0;
transition: opacity 180ms ease, transform 180ms ease;
}
#pause-note.visible {
opacity: 1;
transform: translateY(0);
}
#pause-note h2 {
margin: 0 0 8px;
color: var(--amber);
font-size: 14px;
}
#pause-note p {
margin: 0;
color: #e9ddc4;
font-size: 12px;
line-height: 1.5;
}
#legend {
position: absolute;
right: 18px;
top: 230px;
color: #91a8b8;
font-size: 10px;
line-height: 1.75;
text-align: right;
}
#legend span {
display: inline-block;
width: 18px;
height: 2px;
margin-right: 6px;
vertical-align: middle;
background: var(--cyan);
box-shadow: 0 0 7px var(--cyan);
}
#legend .origin {
background: var(--amber);
box-shadow: 0 0 7px var(--amber);
}
@media (max-width: 760px) {
#stats {
top: auto;
right: 12px;
bottom: 84px;
width: 178px;
}
#title {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
#observers {
left: 12px;
bottom: 245px;
flex-direction: column;
}
.observer-card {
width: 175px;
}
#pause-note {
right: 12px;
bottom: 84px;
}
#legend, #camera-hint {
display: none;
}
#controls {
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="ui">
<section id="title" class="panel">
<div class="eyebrow">Wave mechanics / fixed-origin model</div>
<h1>Moving source.<br>Independent origins.</h1>
<p>
Each wavefront is born at the source’s location at emission time.
It then expands around that fixed center while the source continues moving.
</p>
<div class="formula">r(t) = c · (t − tₑ) | M = vₛ / c < 1</div>
</section>
<section id="stats" class="panel">
<div class="status"><span class="status-dot"></span> SUBSONIC · NO SHOCK FRONT</div>
<div class="stat-row"><span>Simulation time</span><strong id="time-value">0.00 s</strong></div>
<div class="stat-row"><span>Source speed</span><strong id="source-speed">1.35 u/s</strong></div>
<div class="stat-row"><span>Wave speed</span><strong id="wave-speed">4.20 u/s</strong></div>
<div class="stat-row"><span>Mach number</span><strong id="mach-value">0.32</strong></div>
<div class="stat-row"><span>Source position</span><strong id="source-position">−8.00</strong></div>
<div class="stat-row"><span>Emissions</span><strong id="emission-count">0</strong></div>
</section>
<section id="observers">
<div id="forward-card" class="observer-card panel">
<div class="observer-name"><i></i> FORWARD OBSERVER</div>
<div class="observer-count"><b id="forward-count">0</b>arrivals</div>
<div class="observer-interval" id="forward-interval">Last spacing: —</div>
<div class="observer-hint">Wavefront spacing contracts in the +X direction.</div>
</div>
<div id="rear-card" class="observer-card rear panel">
<div class="observer-name"><i></i> REAR OBSERVER</div>
<div class="observer-count"><b id="rear-count">0</b>arrivals</div>
<div class="observer-interval" id="rear-interval">Last spacing: —</div>
<div class="observer-hint">Wavefront spacing expands in the −X direction.</div>
</div>
</section>
<section id="pause-note" class="panel">
<h2>Paused — emission centers revealed</h2>
<p>
Amber diamonds mark the fixed positions where rings were emitted.
The faint spokes connect those origins to the current cyan source.
Old rings remain centered on their diamonds; they do not translate with the source.
</p>
</section>
<div id="legend">
<div><span></span> expanding wavefront</div>
<div><span class="origin"></span> fixed emission center</div>
<div>Drag to orbit · wheel to zoom</div>
</div>
<div id="controls" class="panel">
<button id="pause" class="primary" type="button">Pause & reveal origins</button>
<button id="reset" type="button">Reset</button>
<span id="camera-hint">Drag: orbit · Wheel: zoom · Space: pause</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";
/* ------------------------------------------------------------------
Simulation constants
------------------------------------------------------------------ */
const WAVE_SPEED = 4.2;
const SOURCE_SPEED = 1.35;
const EMIT_INTERVAL = 0.8;
const START_X = -8;
const SOURCE_Z = 0;
const MACH = SOURCE_SPEED / WAVE_SPEED;
const WAVE_SEGMENTS = 72;
const MAX_WAVE_RADIUS = 43;
const forwardObserverPosition = new THREE.Vector3(11, 0, 4.2);
const rearObserverPosition = new THREE.Vector3(-13, 0, 4.2);
/* ------------------------------------------------------------------
Renderer, camera, lights
------------------------------------------------------------------ */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111a);
scene.fog = new THREE.Fog(0x07111a, 34, 78);
const camera = new THREE.PerspectiveCamera(
45,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0x9acfff, 0x152028, 1.6));
const keyLight = new THREE.DirectionalLight(0xc9efff, 2.3);
keyLight.position.set(9, 18, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -30;
keyLight.shadow.camera.right = 30;
keyLight.shadow.camera.top = 24;
keyLight.shadow.camera.bottom = -24;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3a75ff, 1.25);
rimLight.position.set(-14, 8, -13);
scene.add(rimLight);
/* ------------------------------------------------------------------
Reference grid and direction marker
------------------------------------------------------------------ */
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(76, 76),
new THREE.MeshStandardMaterial({
color: 0x081721,
roughness: 0.93,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(64, 64, 0x3b8299, 0x1a3a48);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-25, 0.025, 0),
new THREE.Vector3(25, 0.025, 0)
]);
const pathLine = new THREE.Line(
pathGeometry,
new THREE.LineDashedMaterial({
color: 0x5acde9,
transparent: true,
opacity: 0.22,
dashSize: 0.45,
gapSize: 0.3
})
);
pathLine.computeLineDistances();
scene.add(pathLine);
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-17, 0.08, -6.5),
3.2,
0x56dcff,
0.55,
0.28
);
scene.add(directionArrow);
/* ------------------------------------------------------------------
Labels built with Three.js canvas textures
------------------------------------------------------------------ */
function makeLabel(text, color = "#d9f6ff", width = 4.1, height = 0.72) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(4, 14, 21, 0.76)";
ctx.fillRect(0, 7, canvas.width, canvas.height - 14);
ctx.strokeStyle = color;
ctx.globalAlpha = 0.55;
ctx.lineWidth = 3;
ctx.strokeRect(2, 8, canvas.width - 4, canvas.height - 16);
ctx.globalAlpha = 1;
ctx.fillStyle = color;
ctx.font = "700 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
const directionLabel = makeLabel("SOURCE TRAVEL +X", "#7bdfff", 4.2, 0.64);
directionLabel.position.set(-13.3, 0.8, -6.5);
scene.add(directionLabel);
/* ------------------------------------------------------------------
Low-poly moving source
------------------------------------------------------------------ */
const sourceRig = new THREE.Group();
sourceRig.position.set(START_X, 0.78, SOURCE_Z);
scene.add(sourceRig);
const sourceBodyMaterial = new THREE.MeshStandardMaterial({
color: 0x315765,
emissive: 0x0a5261,
emissiveIntensity: 0.65,
roughness: 0.48,
metalness: 0.42,
flatShading: true
});
const sourceBody = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 0),
sourceBodyMaterial
);
sourceBody.scale.set(1.28, 0.78, 0.9);
sourceBody.castShadow = true;
sourceRig.add(sourceBody);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.27, 0.72, 4),
new THREE.MeshStandardMaterial({
color: 0x72d8e9,
emissive: 0x0c7c91,
emissiveIntensity: 0.7,
flatShading: true,
roughness: 0.4,
metalness: 0.35
})
);
nose.rotation.z = -Math.PI / 2;
nose.position.x = 0.72;
nose.castShadow = true;
sourceRig.add(nose);
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.31, 0.62, 4),
new THREE.MeshStandardMaterial({
color: 0x263c49,
emissive: 0x102a35,
flatShading: true,
roughness: 0.6,
metalness: 0.35
})
);
tail.rotation.z = Math.PI / 2;
tail.position.x = -0.7;
tail.castShadow = true;
sourceRig.add(tail);
const emitterMaterial = new THREE.MeshStandardMaterial({
color: 0xbff8ff,
emissive: 0x36dfff,
emissiveIntensity: 2,
roughness: 0.2,
metalness: 0.15
});
const emitterRing = new THREE.Mesh(
new THREE.TorusGeometry(0.24, 0.045, 4, 16),
emitterMaterial
);
emitterRing.rotation.y = Math.PI / 2;
emitterRing.position.x = 0.89;
sourceRig.add(emitterRing);
const emitterCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.12, 0),
emitterMaterial
);
emitterCore.position.x = 0.91;
sourceRig.add(emitterCore);
const finGeometry = new THREE.BoxGeometry(0.48, 0.09, 0.84);
for (const z of [-0.43, 0.43]) {
const fin = new THREE.Mesh(finGeometry, sourceBodyMaterial);
fin.position.set(-0.18, -0.08, z);
fin.castShadow = true;
sourceRig.add(fin);
}
const sourceLabel = makeLabel("SOURCE • M 0.32", "#77eaff", 3.7, 0.64);
sourceLabel.position.set(0, 1.18, 0);
sourceRig.add(sourceLabel);
const sourceLight = new THREE.PointLight(0x50dfff, 2.2, 5, 2);
sourceLight.position.set(0.85, 0.02, 0);
sourceRig.add(sourceLight);
const sourceShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.68, 24),
new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
sourceShadow.rotation.x = -Math.PI / 2;
sourceShadow.position.y = 0.018;
scene.add(sourceShadow);
/* ------------------------------------------------------------------
Stationary observer posts
------------------------------------------------------------------ */
function createObserver(name, position, color, cardId) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.58, 0.18, 8),
new THREE.MeshStandardMaterial({
color: 0x263a46,
roughness: 0.75,
metalness: 0.25,
flatShading: true
})
);
base.position.y = 0.09;
base.castShadow = true;
group.add(base);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.16, 1.08, 6),
new THREE.MeshStandardMaterial({
color: 0x4b6572,
roughness: 0.65,
metalness: 0.3,
flatShading: true
})
);
post.position.y = 0.7;
post.castShadow = true;
group.add(post);
const sensorMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.8,
roughness: 0.25,
metalness: 0.2,
flatShading: true
});
const sensor = new THREE.Mesh(
new THREE.OctahedronGeometry(0.24, 0),
sensorMaterial
);
sensor.position.y = 1.37;
sensor.castShadow = true;
group.add(sensor);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.035, 4, 20),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.75,
toneMapped: false
})
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 1.37;
group.add(halo);
const label = makeLabel(name, `#${new THREE.Color(color).getHexString()}`, 4.1, 0.66);
label.position.set(0, 2.02, 0);
group.add(label);
const arrivalPulse = new THREE.Mesh(
new THREE.RingGeometry(0.44, 0.52, 40),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
})
);
arrivalPulse.rotation.x = -Math.PI / 2;
arrivalPulse.position.y = 0.025;
arrivalPulse.visible = false;
group.add(arrivalPulse);
const beacon = new THREE.PointLight(color, 0, 5, 2);
beacon.position.y = 1.4;
group.add(beacon);
return {
name,
position: position.clone(),
group,
sensor,
sensorMaterial,
halo,
arrivalPulse,
beacon,
card: document.getElementById(cardId),
nextEmissionIndex: 0,
arrivals: 0,
lastArrival: null,
lastInterval: null,
pulseAge: 10,
pulseEnergy: 0
};
}
const forwardObserver = createObserver(
"FORWARD POST",
forwardObserverPosition,
0xbb9cff,
"forward-card"
);
const rearObserver = createObserver(
"REAR POST",
rearObserverPosition,
0xff9675,
"rear-card"
);
const observers = [forwardObserver, rearObserver];
/* ------------------------------------------------------------------
Wavefront geometry
Each ring owns a fixed center. Only its radius is animated.
------------------------------------------------------------------ */
function makeAnnulusGeometry() {
const positions = new Float32Array((WAVE_SEGMENTS + 1) * 2 * 3);
const indices = [];
for (let i = 0; i < WAVE_SEGMENTS; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
return geometry;
}
function updateAnnulus(geometry, radius, thickness, y) {
const positions = geometry.attributes.position.array;
for (let i = 0; i <= WAVE_SEGMENTS; i++) {
const angle = (i / WAVE_SEGMENTS) * Math.PI * 2;
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
const inner = Math.max(0, radius - thickness);
const outer = radius + thickness;
const innerOffset = i * 6;
positions[innerOffset] = cosine * inner;
positions[innerOffset + 1] = y;
positions[innerOffset + 2] = sine * inner;
const outerOffset = innerOffset + 3;
positions[outerOffset] = cosine * outer;
positions[outerOffset + 1] = y;
positions[outerOffset + 2] = sine * outer;
}
geometry.attributes.position.needsUpdate = true;
}
function makeWaveVisual() {
const group = new THREE.Group();
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0x36cfff,
transparent: true,
opacity: 0.08,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
});
const coreMaterial = new THREE.MeshBasicMaterial({
color: 0x71e7ff,
transparent: true,
opacity: 0.23,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
});
const glow = new THREE.Mesh(makeAnnulusGeometry(), glowMaterial);
const core = new THREE.Mesh(makeAnnulusGeometry(), coreMaterial);
glow.frustumCulled = false;
core.frustumCulled = false;
group.add(glow, core);
const linePositions = new Float32Array(WAVE_SEGMENTS * 3);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(linePositions, 3)
);
const outline = new THREE.LineLoop(
lineGeometry,
new THREE.LineBasicMaterial({
color: 0x8ceeff,
transparent: true,
opacity: 0.78,
blending: THREE.AdditiveBlending,
toneMapped: false
})
);
outline.frustumCulled = false;
group.add(outline);
scene.add(group);
return {
group,
glow,
core,
outline,
lineGeometry
};
}
function updateWaveVisual(visual, radius) {
updateAnnulus(visual.glow.geometry, radius, 0.14, 0.025);
updateAnnulus(visual.core.geometry, radius, 0.047, 0.031);
const positions = visual.lineGeometry.attributes.position.array;
for (let i = 0; i < WAVE_SEGMENTS; i++) {
const angle = (i / WAVE_SEGMENTS) * Math.PI * 2;
positions[i * 3] = Math.cos(angle) * radius;
positions[i * 3 + 1] = 0.039;
positions[i * 3 + 2] = Math.sin(angle) * radius;
}
visual.lineGeometry.attributes.position.needsUpdate = true;
}
/* ------------------------------------------------------------------
Simulation state
------------------------------------------------------------------ */
const emissions = [];
let simulationTime = 0;
let nextEmissionTime = EMIT_INTERVAL;
let sourceX = START_X;
let sourceFlash = 0;
let paused = false;
const revealGroup = new THREE.Group();
revealGroup.visible = false;
scene.add(revealGroup);
function emitWave(emissionTime) {
// This x is the source's position at the scheduled emission time.
const center = new THREE.Vector3(
START_X + SOURCE_SPEED * emissionTime,
0,
SOURCE_Z
);
const visual = makeWaveVisual();
visual.group.position.copy(center);
emissions.push({
index: emissions.length,
time: emissionTime,
center,
visual
});
sourceFlash = 1;
}
function removeWaveVisual(emission) {
if (!emission.visual) return;
scene.remove(emission.visual.group);
emission.visual.group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach(material => material.dispose());
} else {
object.material.dispose();
}
}
});
emission.visual = null;
}
/* ------------------------------------------------------------------
Arrival detection
Arrival time = emission time + distance(center, observer) / c
------------------------------------------------------------------ */
function triggerArrival(observer, emission, arrivalTime) {
observer.arrivals += 1;
if (observer.lastArrival !== null) {
observer.lastInterval = arrivalTime - observer.lastArrival;
}
observer.lastArrival = arrivalTime;
observer.pulseAge = 0;
observer.pulseEnergy = 1;
observer.arrivalPulse.visible = true;
observer.card.classList.remove("ping");
void observer.card.offsetWidth;
observer.card.classList.add("ping");
}
function processObserverArrivals() {
for (const observer of observers) {
while (observer.nextEmissionIndex < emissions.length) {
const emission = emissions[observer.nextEmissionIndex];
const dx = emission.center.x - observer.position.x;
const dz = emission.center.z - observer.position.z;
const travelTime = Math.hypot(dx, dz) / WAVE_SPEED;
const arrivalTime = emission.time + travelTime;
if (arrivalTime <= simulationTime + 1e-6) {
triggerArrival(observer, emission, arrivalTime);
observer.nextEmissionIndex += 1;
} else {
break;
}
}
}
}
/* ------------------------------------------------------------------
Pause reveal: fixed emission origins and current source
------------------------------------------------------------------ */
function disposeGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
}
}
function buildReveal() {
disposeGroup(revealGroup);
const currentSource = new THREE.Vector3(sourceX, 0, SOURCE_Z);
const activeEmissions = emissions.filter(emission => emission.visual);
for (const emission of activeEmissions) {
const marker = new THREE.Group();
marker.position.set(emission.center.x, 0, emission.center.z);
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.105, 0),
new THREE.MeshBasicMaterial({
color: 0xffc857,
toneMapped: false
})
);
diamond.position.y = 0.15;
marker.add(diamond);
const stem = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.02, 0),
new THREE.Vector3(0, 0.48, 0)
]),
new THREE.LineBasicMaterial({
color: 0xffc857,
transparent: true,
opacity: 0.72
})
);
marker.add(stem);
const originRing = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.16, 16),
new THREE.MeshBasicMaterial({
color: 0xffc857,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
originRing.rotation.x = -Math.PI / 2;
originRing.position.y = 0.027;
marker.add(originRing);
revealGroup.add(marker);
// A faint spoke emphasizes that the current source is not the center
// of the older rings.
const spoke = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(emission.center.x, 0.07, emission.center.z),
new THREE.Vector3(currentSource.x, 0.07, currentSource.z)
]),
new THREE.LineDashedMaterial({
color: 0xffd36f,
transparent: true,
opacity: 0.14,
dashSize: 0.22,
gapSize: 0.18
})
);
spoke.computeLineDistances();
revealGroup.add(spoke);
}
const currentMarker = new THREE.Group();
currentMarker.position.copy(currentSource);
const currentRing = new THREE.Mesh(
new THREE.RingGeometry(0.67, 0.75, 40),
new THREE.MeshBasicMaterial({
color: 0xe9fbff,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
currentRing.rotation.x = -Math.PI / 2;
currentRing.position.y = 0.04;
currentMarker.add(currentRing);
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.14, 2.8, 8, 1, true),
new THREE.MeshBasicMaterial({
color: 0xbff8ff,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
})
);
beam.position.y = 1.4;
currentMarker.add(beam);
const currentLabel = makeLabel(
"CURRENT SOURCE",
"#e9fbff",
3.5,
0.62
);
currentLabel.position.y = 2.0;
currentMarker.add(currentLabel);
revealGroup.add(currentMarker);
revealGroup.visible = true;
}
/* ------------------------------------------------------------------
HUD updates
------------------------------------------------------------------ */
const timeValue = document.getElementById("time-value");
const sourceSpeedValue = document.getElementById("source-speed");
const waveSpeedValue = document.getElementById("wave-speed");
const machValue = document.getElementById("mach-value");
const sourcePositionValue = document.getElementById("source-position");
const emissionCountValue = document.getElementById("emission-count");
const forwardCount = document.getElementById("forward-count");
const rearCount = document.getElementById("rear-count");
const forwardInterval = document.getElementById("forward-interval");
const rearInterval = document.getElementById("rear-interval");
const pauseButton = document.getElementById("pause");
const pauseNote = document.getElementById("pause-note");
sourceSpeedValue.textContent = `${SOURCE_SPEED.toFixed(2)} u/s`;
waveSpeedValue.textContent = `${WAVE_SPEED.toFixed(2)} u/s`;
machValue.textContent = MACH.toFixed(2);
function updateHUD() {
timeValue.textContent = `${simulationTime.toFixed(2)} s`;
sourcePositionValue.textContent = sourceX.toFixed(2);
emissionCountValue.textContent = emissions.length;
forwardCount.textContent = forwardObserver.arrivals;
rearCount.textContent = rearObserver.arrivals;
forwardInterval.textContent = forwardObserver.lastInterval === null
? "Last spacing: —"
: `Last spacing: ${forwardObserver.lastInterval.toFixed(2)} s`;
rearInterval.textContent = rearObserver.lastInterval === null
? "Last spacing: —"
: `Last spacing: ${rearObserver.lastInterval.toFixed(2)} s`;
}
function setPaused(nextPaused) {
paused = nextPaused;
pauseButton.textContent = paused
? "Resume simulation"
: "Pause & reveal origins";
pauseNote.classList.toggle("visible", paused);
if (paused) {
buildReveal();
} else {
revealGroup.visible = false;
disposeGroup(revealGroup);
}
}
pauseButton.addEventListener("click", () => setPaused(!paused));
/* ------------------------------------------------------------------
Reset
------------------------------------------------------------------ */
function resetSimulation() {
for (const emission of emissions) {
removeWaveVisual(emission);
}
emissions.length = 0;
simulationTime = 0;
nextEmissionTime = EMIT_INTERVAL;
sourceX = START_X;
sourceFlash = 0;
sourceRig.position.set(sourceX, 0.78, SOURCE_Z);
sourceShadow.position.set(sourceX, 0.018, SOURCE_Z);
for (const observer of observers) {
observer.nextEmissionIndex = 0;
observer.arrivals = 0;
observer.lastArrival = null;
observer.lastInterval = null;
observer.pulseAge = 10;
observer.pulseEnergy = 0;
observer.arrivalPulse.visible = false;
observer.arrivalPulse.material.opacity = 0;
}
emitWave(0);
updateHUD();
if (paused) buildReveal();
}
document.getElementById("reset").addEventListener("click", resetSimulation);
/* ------------------------------------------------------------------
Direct camera controls: orbit and zoom, without addons
------------------------------------------------------------------ */
const cameraTarget = new THREE.Vector3(0, 0.4, 0);
let cameraYaw = 0.58;
let cameraPitch = 0.67;
let cameraRadius = 31;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const sinPitch = Math.sin(cameraPitch);
camera.position.set(
cameraTarget.x + cameraRadius * sinPitch * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.cos(cameraPitch),
cameraTarget.z + cameraRadius * sinPitch * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.24,
1.38
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
15,
60
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
setPaused(!paused);
}
if (event.code === "KeyR") {
resetSimulation();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
/* ------------------------------------------------------------------
Animation
------------------------------------------------------------------ */
const clock = new THREE.Clock();
function updateObserverVisuals(dt) {
for (const observer of observers) {
observer.pulseAge += dt;
observer.pulseEnergy = Math.max(0, observer.pulseEnergy - dt * 1.45);
const pulse = observer.pulseAge / 1.15;
if (pulse < 1) {
observer.arrivalPulse.visible = true;
const scale = 1 + pulse * 2.7;
observer.arrivalPulse.scale.setScalar(scale);
observer.arrivalPulse.material.opacity = (1 - pulse) * 0.9;
} else {
observer.arrivalPulse.visible = false;
}
observer.sensor.scale.setScalar(1 + observer.pulseEnergy * 0.32);
observer.sensorMaterial.emissiveIntensity =
0.75 + observer.pulseEnergy * 3.0;
observer.halo.scale.setScalar(1 + observer.pulseEnergy * 0.25);
observer.halo.material.opacity = 0.68 + observer.pulseEnergy * 0.3;
observer.beacon.intensity = observer.pulseEnergy * 4.5;
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += dt;
// Exactly constant source speed in simulation coordinates.
sourceX = START_X + SOURCE_SPEED * simulationTime;
sourceRig.position.set(sourceX, 0.78, SOURCE_Z);
sourceShadow.position.set(sourceX, 0.018, SOURCE_Z);
// Emit at regular scheduled times, using the source position at
// each scheduled emission time.
while (nextEmissionTime <= simulationTime + 1e-8) {
emitWave(nextEmissionTime);
nextEmissionTime += EMIT_INTERVAL;
}
processObserverArrivals();
for (const emission of emissions) {
if (!emission.visual) continue;
const age = simulationTime - emission.time;
const radius = Math.max(0, WAVE_SPEED * age);
updateWaveVisual(emission.visual, radius);
const fade = THREE.MathUtils.clamp(
1 - radius / (MAX_WAVE_RADIUS * 1.3),
0.18,
1
);
emission.visual.glow.material.opacity = 0.075 * fade;
emission.visual.core.material.opacity = 0.23 * fade;
emission.visual.outline.material.opacity = 0.78 * fade;
if (radius > MAX_WAVE_RADIUS) {
removeWaveVisual(emission);
}
}
sourceFlash = Math.max(0, sourceFlash - dt * 2.6);
emitterMaterial.emissiveIntensity = 1.7 + sourceFlash * 4.0;
sourceLight.intensity = 1.7 + sourceFlash * 4.0;
emitterRing.rotation.x += dt * (0.7 + sourceFlash * 8);
}
updateObserverVisuals(paused ? 0 : dt);
updateHUD();
renderer.render(scene, camera);
}
resetSimulation();
updateCamera();
animate();
</script>
</body>
</html>
```