Prompt specification
Build or customize the Three.js 3D scene "Passing pulses on a rope" 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: Passing pulses on a rope
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/passing-pulses-on-a-rope-x1590
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows an animation of two localized analytic pulses moving through each other; show temporary superposition and their unchanged shapes afterward under an explicitly linear ideal model. Stylized solid forms.
Working Three.js Starter (passing-pulses-on-a-rope-x1590):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Linear Pulse Superposition</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(9, 22, 39, 0.82);
--panel-border: rgba(164, 210, 255, 0.14);
--text: #eaf5ff;
--muted: #8da7bf;
--cyan: #45dcff;
--pink: #ff6396;
--gold: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--text);
background:
radial-gradient(circle at 50% 38%, #142b46 0%, #091526 42%, #040a12 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.card {
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.24),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: absolute;
top: 27px;
left: 30px;
max-width: 520px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 27px;
height: 2px;
border-radius: 2px;
background: var(--cyan);
content: "";
box-shadow: 0 0 12px rgba(69, 220, 255, 0.75);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 1.02;
}
.brand p {
max-width: 490px;
margin: 14px 0 0;
color: #a9bfd2;
font-size: 14px;
line-height: 1.55;
}
.brand strong {
color: #e8f6ff;
font-weight: 650;
}
.right-hud {
position: absolute;
top: 27px;
right: 28px;
width: 310px;
}
.legend-card {
padding: 15px 17px;
}
.card-label {
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 9px;
color: #c6d7e6;
font-size: 12px;
}
.swatch {
width: 23px;
height: 7px;
flex: 0 0 auto;
border-radius: 8px;
box-shadow: 0 0 15px currentColor;
}
.swatch.cyan {
color: var(--cyan);
background: var(--cyan);
}
.swatch.pink {
color: var(--pink);
background: var(--pink);
}
.swatch.gold {
color: var(--gold);
background: var(--gold);
}
.legend-row code {
margin-left: auto;
color: #f3f9ff;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 11px;
}
.status-card {
position: relative;
margin-top: 12px;
overflow: hidden;
padding: 17px;
transition:
border-color 180ms ease,
box-shadow 180ms ease;
}
.status-card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2px;
background: var(--cyan);
content: "";
opacity: 0.65;
transition: background 180ms ease;
}
.status-card.is-superposed {
border-color: rgba(255, 209, 102, 0.42);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.24),
0 0 35px rgba(255, 209, 102, 0.09),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
}
.status-card.is-superposed::before {
background: var(--gold);
box-shadow: 0 0 16px rgba(255, 209, 102, 0.85);
}
.status-top,
.status-foot {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#timeValue {
color: #dcecff;
font-family: "SFMono-Regular", Consolas, monospace;
letter-spacing: 0;
}
#phase {
margin-top: 10px;
color: var(--cyan);
font-size: 15px;
font-weight: 760;
letter-spacing: 0.035em;
transition: color 180ms ease;
}
.is-superposed #phase {
color: var(--gold);
}
#phaseCopy {
min-height: 54px;
margin-top: 8px;
color: #9eb5c8;
font-size: 12px;
line-height: 1.48;
}
.overlap-track {
height: 5px;
margin: 15px 0 8px;
overflow: hidden;
border-radius: 8px;
background: rgba(255, 255, 255, 0.07);
}
#overlapFill {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--pink), var(--gold));
box-shadow: 0 0 13px rgba(255, 209, 102, 0.7);
transition: width 60ms linear;
}
.formula-card {
position: absolute;
bottom: 28px;
left: 28px;
width: 355px;
padding: 16px 17px 15px;
}
.equation {
display: grid;
gap: 7px;
color: #d8e9f8;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10.5px;
line-height: 1.35;
}
.equation .sum {
padding-top: 7px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
color: var(--gold);
font-weight: 700;
}
.law {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: #9fb7ca;
font-size: 11px;
line-height: 1.4;
}
.law::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 12px rgba(255, 209, 102, 0.75);
content: "";
}
.transport {
position: absolute;
right: 28px;
bottom: 28px;
left: 407px;
min-width: 420px;
padding: 13px 15px 14px;
pointer-events: auto;
}
.transport-row {
display: flex;
align-items: center;
gap: 8px;
}
button {
min-height: 34px;
padding: 0 13px;
border: 1px solid rgba(172, 216, 255, 0.18);
border-radius: 9px;
color: #dceeff;
background: rgba(255, 255, 255, 0.045);
font: inherit;
font-size: 11px;
font-weight: 670;
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
button:hover {
border-color: rgba(172, 216, 255, 0.42);
background: rgba(255, 255, 255, 0.09);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(69, 220, 255, 0.35);
color: #eafaff;
background: rgba(69, 220, 255, 0.12);
}
.timeline-wrap {
flex: 1;
min-width: 150px;
margin-left: 6px;
}
.timeline-labels {
position: relative;
height: 16px;
margin: 0 3px;
color: #637f96;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.timeline-labels span {
position: absolute;
top: 0;
}
.timeline-labels .start {
left: 0;
}
.timeline-labels .end {
right: 0;
}
.timeline-labels .collision-label {
left: 29.38%;
color: #b8994e;
transform: translateX(-50%);
}
input[type="range"] {
--p: 0%;
width: 100%;
height: 4px;
margin: 4px 0 0;
border-radius: 8px;
outline: none;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(
90deg,
var(--cyan) 0%,
var(--gold) var(--p),
rgba(255, 255, 255, 0.09) var(--p),
rgba(255, 255, 255, 0.09) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #dff8ff;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: #16354a;
box-shadow: 0 0 12px rgba(69, 220, 255, 0.75);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #dff8ff;
border-radius: 50%;
background: #16354a;
box-shadow: 0 0 12px rgba(69, 220, 255, 0.75);
}
.hint {
position: absolute;
right: 30px;
bottom: 117px;
color: rgba(168, 193, 215, 0.62);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#loader {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--cyan);
background: #07111f;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1050px) {
.formula-card {
display: none;
}
.transport {
left: 28px;
}
.hint {
bottom: 108px;
}
}
@media (max-width: 720px) {
.brand {
top: 18px;
left: 18px;
max-width: calc(100% - 36px);
}
.brand p {
max-width: 340px;
font-size: 12px;
}
.right-hud {
top: 142px;
right: 14px;
width: 235px;
}
.legend-card {
display: none;
}
.status-card {
margin-top: 0;
padding: 13px;
}
#phaseCopy {
min-height: 0;
}
.transport {
right: 12px;
bottom: 12px;
left: 12px;
min-width: 0;
}
.transport-row {
flex-wrap: wrap;
}
.timeline-wrap {
order: 3;
width: 100%;
flex-basis: 100%;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="hud">
<header class="brand">
<div class="eyebrow">Ideal Linear Field / 01</div>
<h1>Pulses, passing through.</h1>
<p>
Two localized analytic wave packets travel in opposite directions.
Their observed fields add during overlap, while
<strong>both component shapes remain unchanged</strong> before and after.
</p>
</header>
<aside class="right-hud">
<div class="card legend-card">
<div class="card-label">Field Legend</div>
<div class="legend-row">
<span class="swatch cyan"></span>
<span>Component A</span>
<code>a(x,t)</code>
</div>
<div class="legend-row">
<span class="swatch pink"></span>
<span>Component B</span>
<code>b(x,t)</code>
</div>
<div class="legend-row">
<span class="swatch gold"></span>
<span>Observed sum</span>
<code>s = a + b</code>
</div>
</div>
<div class="card status-card" id="statusCard">
<div class="status-top">
<span>Field state</span>
<span id="timeValue">t = 0.00 s</span>
</div>
<div id="phase">INDEPENDENT PULSES</div>
<div id="phaseCopy">
The packets approach without coupling. Each retains its own amplitude,
width, and analytic profile.
</div>
<div class="overlap-track">
<i id="overlapFill"></i>
</div>
<div class="status-foot">
<span>Envelope overlap</span>
<span id="overlapValue">0%</span>
</div>
</div>
</aside>
<section class="card formula-card">
<div class="card-label">Explicitly Linear Model</div>
<div class="equation">
<div>a(x,t) = A exp[−(x−c<sub>A</sub>)² / 2σ²] · sin[k(x−c<sub>A</sub>)]</div>
<div>b(x,t) = A exp[−(x−c<sub>B</sub>)² / 2σ²] · sin[k(x−c<sub>B</sub>)]</div>
<div class="sum">s(x,t) = a(x,t) + b(x,t)</div>
<div>c<sub>A</sub>(t) = −4.6 + 1.45t · c<sub>B</sub>(t) = 4.6 − 1.45t</div>
</div>
<div class="law">
No coupling or nonlinear term. The temporary combined shape does not
alter either component.
</div>
</section>
<section class="card transport">
<div class="transport-row">
<button id="playButton" class="primary" type="button">❚❚ Pause</button>
<button id="replayButton" type="button">↺ Replay</button>
<button id="collisionButton" type="button">Collision</button>
<div class="timeline-wrap">
<div class="timeline-labels">
<span class="start">Independent</span>
<span class="collision-label">Collision</span>
<span class="end">Unchanged</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="10.8"
step="0.01"
value="0"
aria-label="Animation timeline"
/>
</div>
</div>
</section>
<div class="hint">Drag to orbit · wheel to zoom · double-click to reset</div>
</div>
<div id="loader">Initializing linear field</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model parameters
// -------------------------------------------------------------------------
const AMPLITUDE = 0.62;
const SIGMA = 0.9;
const WAVE_NUMBER = 10.5;
const INITIAL_OFFSET = 4.6;
const SPEED = 1.45;
const CYCLE = 10.8;
const COLLISION_TIME = INITIAL_OFFSET / SPEED;
const pulse = (u) =>
Math.exp(-0.5 * (u / SIGMA) ** 2) *
Math.sin(WAVE_NUMBER * u);
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
document.querySelector("#loader").textContent = "WebGL is unavailable";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07111f, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.15, 0);
const controls = {
yaw: 0.10,
pitch: 0.28,
zoom: 1
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const fittedHeight = aspect < 1 ? 23 / aspect : 13.4;
const viewHeight = fittedHeight / controls.zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
const radius = 22;
camera.position.set(
cameraTarget.x + radius * Math.sin(controls.yaw) * Math.cos(controls.pitch),
cameraTarget.y + radius * Math.sin(controls.pitch),
cameraTarget.z + radius * Math.cos(controls.yaw) * Math.cos(controls.pitch)
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
scene.add(new THREE.HemisphereLight(0xbcecff, 0x10182b, 1.75));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x20cfff, 22, 18, 2);
cyanLight.position.set(-6, 3, 4);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff3f7f, 18, 18, 2);
pinkLight.position.set(6, 0, 3);
scene.add(pinkLight);
const collisionLight = new THREE.PointLight(0xffd166, 0, 12, 2);
collisionLight.position.set(0, -0.4, 3.4);
scene.add(collisionLight);
// -------------------------------------------------------------------------
// Solid laboratory decks
// -------------------------------------------------------------------------
const deckMaterial = new THREE.MeshStandardMaterial({
color: 0x0d1d30,
roughness: 0.76,
metalness: 0.08
});
function addDeck(y, edgeColor) {
const deck = new THREE.Mesh(
new THREE.BoxGeometry(21.3, 0.18, 3.15),
deckMaterial
);
deck.position.y = y;
deck.receiveShadow = true;
scene.add(deck);
const edge = new THREE.Mesh(
new THREE.BoxGeometry(21.05, 0.026, 0.035),
new THREE.MeshStandardMaterial({
color: edgeColor,
emissive: edgeColor,
emissiveIntensity: 0.12,
roughness: 0.42
})
);
edge.position.set(0, y + 0.103, 1.575);
scene.add(edge);
const grid = new THREE.GridHelper(
20,
40,
0x31516d,
0x1a3047
);
grid.scale.z = 0.145;
grid.position.y = y + 0.098;
grid.material.transparent = true;
grid.material.opacity = 0.22;
grid.material.depthWrite = false;
scene.add(grid);
}
addDeck(0.02, 0x23627a);
addDeck(-2.28, 0x80672f);
function addGuide(y, color) {
const guide = new THREE.Mesh(
new THREE.BoxGeometry(20.7, 0.018, 0.025),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.5
})
);
guide.position.set(0, y, 0.96);
scene.add(guide);
}
addGuide(1.12, 0x42677e);
addGuide(-0.78, 0x7a6947);
// -------------------------------------------------------------------------
// A dynamic solid ribbon: a rectangular extrusion following a scalar field.
// -------------------------------------------------------------------------
class SolidRibbon {
constructor({
material,
baseline,
z,
width = 0.15,
depth = 0.34,
samples = 281,
xMin = -10.6,
xMax = 10.6
}) {
this.baseline = baseline;
this.z = z;
this.width = width;
this.depth = depth;
this.samples = samples;
this.xMin = xMin;
this.xMax = xMax;
const vertexCount = samples * 4 + 2;
this.positions = new Float32Array(vertexCount * 3);
this.indices = [];
for (let i = 0; i < samples - 1; i++) {
const a = i * 4;
const b = (i + 1) * 4;
for (let edge = 0; edge < 4; edge++) {
const next = (edge + 1) % 4;
this.indices.push(
a + edge,
a + next,
b + next,
b + edge
);
}
}
const startCenter = samples * 4;
const endCenter = startCenter + 1;
for (let edge = 0; edge < 4; edge++) {
const next = (edge + 1) % 4;
this.indices.push(startCenter, edge, next);
this.indices.push(endCenter, (samples - 1) * 4 + next, (samples - 1) * 4 + edge);
}
this.geometry = new THREE.BufferGeometry();
this.positionAttribute = new THREE.BufferAttribute(this.positions, 3);
this.positionAttribute.setUsage(THREE.DynamicDrawUsage);
this.geometry.setAttribute("position", this.positionAttribute);
this.geometry.setIndex(this.indices);
this.mesh = new THREE.Mesh(this.geometry, material);
this.mesh.castShadow = true;
this.mesh.receiveShadow = true;
this.mesh.frustumCulled = false;
scene.add(this.mesh);
this.update(() => 0);
}
update(field) {
const {
positions,
samples,
baseline,
z,
width,
depth
} = this;
const halfWidth = width / 2;
const halfDepth = depth / 2;
for (let i = 0; i < samples; i++) {
const x = this.xMin + (this.xMax - this.xMin) * (i / (samples - 1));
const y = baseline + field(x);
const corners = [
[halfWidth, halfDepth],
[-halfWidth, halfDepth],
[-halfWidth, -halfDepth],
[halfWidth, -halfDepth]
];
for (let corner = 0; corner < 4; corner++) {
const index = (i * 4 + corner) * 3;
positions[index] = x;
positions[index + 1] = y + corners[corner][0];
positions[index + 2] = z + corners[corner][1];
}
}
const startCenter = samples * 4;
const endCenter = startCenter + 1;
positions[startCenter * 3] = this.xMin;
positions[startCenter * 3 + 1] = baseline;
positions[startCenter * 3 + 2] = z;
positions[endCenter * 3] = this.xMax;
positions[endCenter * 3 + 1] = baseline;
positions[endCenter * 3 + 2] = z;
this.positionAttribute.needsUpdate = true;
this.geometry.computeVertexNormals();
}
}
const cyanMaterial = new THREE.MeshPhysicalMaterial({
color: 0x45dcff,
emissive: 0x073b50,
emissiveIntensity: 0.42,
roughness: 0.26,
metalness: 0.12,
clearcoat: 0.85,
clearcoatRoughness: 0.22
});
const pinkMaterial = new THREE.MeshPhysicalMaterial({
color: 0xff6396,
emissive: 0x4b0d28,
emissiveIntensity: 0.42,
roughness: 0.26,
metalness: 0.12,
clearcoat: 0.85,
clearcoatRoughness: 0.22
});
const goldMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffd166,
emissive: 0x6b3900,
emissiveIntensity: 0.26,
roughness: 0.24,
metalness: 0.16,
clearcoat: 0.9,
clearcoatRoughness: 0.2
});
// Upper lane: the two independently moving components.
// Their small depth separation makes the pass-through readable.
const ribbonA = new SolidRibbon({
material: cyanMaterial,
baseline: 1.12,
z: 0.39
});
const ribbonB = new SolidRibbon({
material: pinkMaterial,
baseline: 1.12,
z: -0.39
});
// Lower lane: the observable pointwise sum, s = a + b.
const ribbonSum = new SolidRibbon({
material: goldMaterial,
baseline: -0.78,
z: 0
});
// -------------------------------------------------------------------------
// Direction arrows and in-scene labels
// -------------------------------------------------------------------------
function addArrow(x, y, direction, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.28,
roughness: 0.36,
metalness: 0.12
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.56, 0.055, 0.055),
material
);
shaft.position.x = direction * 0.05;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.28, 16),
material
);
head.rotation.z = direction > 0 ? -Math.PI / 2 : Math.PI / 2;
head.position.x = direction * 0.4;
group.add(head);
group.position.set(x, y, 0.8);
scene.add(group);
}
addArrow(-9.15, 1.62, 1, 0x45dcff);
addArrow(9.15, 1.62, -1, 0xff6396);
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function makeLabel(title, subtitle, accent) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 180;
const context = canvas.getContext("2d");
roundedRect(context, 4, 4, 1016, 172, 26);
context.fillStyle = "rgba(7, 17, 31, 0.82)";
context.fill();
context.fillStyle = accent;
roundedRect(context, 25, 25, 7, 130, 4);
context.fill();
context.fillStyle = "#eaf5ff";
context.font = "700 52px system-ui, sans-serif";
context.textBaseline = "middle";
context.fillText(title, 58, 67);
context.fillStyle = accent;
context.font = "650 30px system-ui, sans-serif";
context.fillText(subtitle, 60, 125);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(4.35, 0.765, 1);
sprite.renderOrder = 20;
return sprite;
}
const componentLabel = makeLabel(
"COMPONENT FORMS",
"independent packets · depth separated",
"#72e2ff"
);
componentLabel.position.set(-7.65, 2.28, 1.6);
scene.add(componentLabel);
const sumLabel = makeLabel(
"OBSERVED SUM",
"s(x,t) = a(x,t) + b(x,t)",
"#ffd166"
);
sumLabel.position.set(-7.65, -2.08, 1.6);
scene.add(sumLabel);
const collisionRing = new THREE.Mesh(
new THREE.RingGeometry(0.42, 0.49, 64),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.05,
side: THREE.DoubleSide,
depthWrite: false
})
);
collisionRing.rotation.x = -Math.PI / 2;
collisionRing.position.set(0, -2.175, 0);
scene.add(collisionRing);
// -------------------------------------------------------------------------
// Interface and animation state
// -------------------------------------------------------------------------
const ui = {
phase: document.querySelector("#phase"),
phaseCopy: document.querySelector("#phaseCopy"),
statusCard: document.querySelector("#statusCard"),
timeValue: document.querySelector("#timeValue"),
overlapFill: document.querySelector("#overlapFill"),
overlapValue: document.querySelector("#overlapValue"),
timeline: document.querySelector("#timeline"),
playButton: document.querySelector("#playButton"),
replayButton: document.querySelector("#replayButton"),
collisionButton: document.querySelector("#collisionButton")
};
let time = 0;
let playing = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function updatePlayButton() {
ui.playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
}
function updateInterface(overlap, separated) {
const progress = (time / CYCLE) * 100;
ui.timeline.value = time.toFixed(2);
ui.timeline.style.setProperty("--p", `${progress}%`);
ui.timeValue.textContent = `t = ${time.toFixed(2)} s`;
ui.overlapFill.style.width = `${(overlap * 100).toFixed(1)}%`;
ui.overlapValue.textContent = `${Math.round(overlap * 100)}%`;
const superposed = overlap > 0.48;
ui.statusCard.classList.toggle("is-superposed", superposed);
if (superposed) {
ui.phase.textContent = "TEMPORARY SUPERPOSITION";
ui.phaseCopy.textContent =
"The observed displacement is the pointwise sum. " +
"Neither component is stretched, compressed, or otherwise changed.";
} else if (!separated) {
ui.phase.textContent = "INDEPENDENT PULSES";
ui.phaseCopy.textContent =
"The packets approach without coupling. Each retains its own amplitude, " +
"width, and analytic profile.";
} else {
ui.phase.textContent = "PASSED THROUGH · SHAPES UNCHANGED";
ui.phaseCopy.textContent =
"Both packets have separated with identical profiles. " +
"Only their temporary combined observation has disappeared.";
}
}
function updateScene() {
const centerA = -INITIAL_OFFSET + SPEED * time;
const centerB = INITIAL_OFFSET - SPEED * time;
const separation = Math.abs(centerA - centerB);
const overlap = Math.exp(
-0.5 * (separation / (2 * SIGMA)) ** 2
);
const fieldA = (x) => AMPLITUDE * pulse(x - centerA);
const fieldB = (x) => AMPLITUDE * pulse(x - centerB);
const fieldSum = (x) => fieldA(x) + fieldB(x);
ribbonA.update(fieldA);
ribbonB.update(fieldB);
ribbonSum.update(fieldSum);
cyanMaterial.emissiveIntensity = 0.38 + overlap * 0.15;
pinkMaterial.emissiveIntensity = 0.38 + overlap * 0.15;
goldMaterial.emissiveIntensity = 0.24 + overlap * 0.9;
collisionLight.intensity = overlap * 28;
collisionRing.material.opacity = 0.035 + overlap * 0.28;
collisionRing.scale.setScalar(0.75 + overlap * 0.75);
const separated = time > COLLISION_TIME;
updateInterface(overlap, separated);
}
ui.playButton.addEventListener("click", () => {
playing = !playing;
updatePlayButton();
});
ui.replayButton.addEventListener("click", () => {
time = 0;
playing = true;
updatePlayButton();
});
ui.collisionButton.addEventListener("click", () => {
time = COLLISION_TIME;
playing = true;
updatePlayButton();
});
ui.timeline.addEventListener("input", () => {
time = Number(ui.timeline.value);
playing = false;
updatePlayButton();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
playing = !playing;
updatePlayButton();
} else if (event.key.toLowerCase() === "r") {
time = 0;
playing = true;
updatePlayButton();
} else if (event.key.toLowerCase() === "c") {
time = COLLISION_TIME;
playing = true;
updatePlayButton();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset. No external addons.
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.yaw = THREE.MathUtils.clamp(
controls.yaw - dx * 0.006,
-0.68,
0.68
);
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.08,
0.78
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.7
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.yaw = 0.10;
controls.pitch = 0.28;
controls.zoom = 1;
updateCamera();
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
time += delta;
if (time >= CYCLE) {
time -= CYCLE;
}
}
updateScene();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
updatePlayButton();
updateScene();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loader").classList.add("hidden");
});
</script>
</body>
</html>
```