Prompt specification
Build or customize the Three.js 3D scene "Transverse bead wave rail" 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: Transverse bead wave rail
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/transverse-bead-wave-rail-x1597
Scene Description Prompt:
Transverse bead wave rail. Build a row of beads whose vertical oscillations form a traveling sinusoid; mark one bead to show that it oscillates locally rather than traveling with the wave. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (transverse-bead-wave-rail-x1597):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transverse Bead Wave Rail</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 20, 35, 0.78);
--border: rgba(137, 211, 255, 0.2);
--text: #eaf7ff;
--muted: #91aabd;
--cyan: #54d8ff;
--orange: #ffad42;
--mint: #74f3c2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 21px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--mint);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
}
header p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
header strong {
color: var(--text);
}
.legend {
top: 22px;
right: 22px;
width: 245px;
padding: 16px 17px;
pointer-events: none;
}
.legend-title {
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: 10px;
margin: 9px 0;
color: #c4d8e7;
font-size: 12px;
}
.swatch {
flex: 0 0 auto;
width: 11px;
height: 11px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px rgba(84, 216, 255, 0.7);
}
.swatch.orange {
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 66, 0.65);
}
.direction {
position: relative;
width: 34px;
height: 10px;
}
.direction::before {
position: absolute;
top: 4px;
left: 0;
width: 27px;
height: 2px;
background: var(--mint);
content: "";
}
.direction::after {
position: absolute;
top: 1px;
right: 1px;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 7px solid var(--mint);
content: "";
}
#callout {
position: fixed;
z-index: 8;
display: flex;
align-items: center;
gap: 9px;
width: 225px;
padding: 10px 12px;
border: 1px solid rgba(255, 173, 66, 0.42);
border-radius: 12px;
background: rgba(26, 19, 11, 0.86);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
pointer-events: none;
transform: translate(16px, -50%);
transition: opacity 120ms ease;
}
#callout::before {
position: absolute;
top: 50%;
right: 100%;
width: 17px;
height: 1px;
background: rgba(255, 173, 66, 0.7);
content: "";
}
.callout-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 14px rgba(255, 173, 66, 0.85);
}
#callout strong,
#callout span {
display: block;
}
#callout strong {
color: #ffd29a;
font-size: 12px;
}
#callout span {
margin-top: 2px;
color: #c8ae8c;
font-size: 10px;
line-height: 1.35;
}
.controls {
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 18px;
width: max-content;
max-width: calc(100vw - 44px);
padding: 13px 15px;
transform: translateX(-50%);
}
.control {
display: grid;
grid-template-columns: auto 105px 43px;
align-items: center;
gap: 9px;
}
.control label {
color: var(--muted);
font-size: 11px;
font-weight: 650;
white-space: nowrap;
}
.control output {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
text-align: right;
}
input[type="range"] {
width: 105px;
height: 4px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: rgba(117, 160, 190, 0.25);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #dff7ff;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 11px rgba(84, 216, 255, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #dff7ff;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 11px rgba(84, 216, 255, 0.55);
}
button {
border: 1px solid rgba(116, 243, 194, 0.38);
border-radius: 10px;
padding: 9px 13px;
color: var(--mint);
background: rgba(116, 243, 194, 0.08);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(116, 243, 194, 0.16);
transform: translateY(-1px);
}
button.secondary {
border-color: rgba(137, 211, 255, 0.22);
color: var(--muted);
background: rgba(137, 211, 255, 0.05);
}
.help {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 9;
color: rgba(185, 207, 222, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 900px) {
.legend {
display: none;
}
.controls {
flex-wrap: wrap;
justify-content: center;
gap: 11px 16px;
}
.help {
display: none;
}
}
@media (max-width: 560px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
header p {
font-size: 12px;
}
.controls {
bottom: 12px;
max-width: calc(100vw - 24px);
padding: 10px;
}
.control {
grid-template-columns: 66px 80px 36px;
gap: 6px;
}
input[type="range"] {
width: 80px;
}
#callout {
width: 190px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="panel">
<div class="eyebrow">Wave laboratory</div>
<h1>Transverse<br>Bead Wave</h1>
<p>
The wave shape travels along the rail, while every bead stays at a
<strong>fixed horizontal position</strong> and moves only up and down.
</p>
</header>
<aside class="legend panel">
<div class="legend-title">Reading the model</div>
<div class="legend-row">
<span class="swatch"></span>
<span>Oscillating bead</span>
</div>
<div class="legend-row">
<span class="swatch orange"></span>
<span>Tracked bead</span>
</div>
<div class="legend-row">
<span class="direction"></span>
<span>Wave travel direction</span>
</div>
<div class="legend-row">
<span class="swatch" style="background: transparent; border: 1px solid #ffad42; box-shadow: none;"></span>
<span>Fixed equilibrium position</span>
</div>
</aside>
<div id="callout">
<span class="callout-dot"></span>
<div>
<strong>Tracked bead</strong>
<span>Same x-position · local up/down motion</span>
</div>
</div>
<section class="controls panel" aria-label="Wave controls">
<div class="control">
<label for="amplitude">Amplitude</label>
<input id="amplitude" type="range" min="0.15" max="0.95" step="0.01" value="0.58">
<output id="amplitude-value">0.58</output>
</div>
<div class="control">
<label for="wavelength">Wavelength</label>
<input id="wavelength" type="range" min="4" max="11" step="0.1" value="6.8">
<output id="wavelength-value">6.8</output>
</div>
<div class="control">
<label for="speed">Speed</label>
<input id="speed" type="range" min="0.25" max="2" step="0.05" value="1">
<output id="speed-value">1.00</output>
</div>
<button id="toggle" type="button">Pause</button>
<button id="reset-view" class="secondary" type="button">Reset view</button>
</section>
<div class="help">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const callout = document.getElementById("callout");
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 16, 36);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const defaultView = {
radius: 12.4,
phi: 1.23,
theta: 0.48
};
const orbit = {
radius: defaultView.radius,
phi: defaultView.phi,
theta: defaultView.theta
};
function updateCamera() {
camera.position.setFromSpherical(
new THREE.Spherical(orbit.radius, orbit.phi, orbit.theta)
);
camera.position.add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting and floor
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc8efff, 0x09111c, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54d8ff, 1.5);
rimLight.position.set(-6, 3, -5);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xffb968, 8, 18, 2);
fillLight.position.set(4.5, 2.8, 3.5);
scene.add(fillLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.93,
metalness: 0.08
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.15;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x1e7895, 0x173246);
grid.position.y = -1.135;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// -------------------------------------------------------------------------
// Static guide rail
// -------------------------------------------------------------------------
const railY = 1.55;
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x1e3b55,
metalness: 0.72,
roughness: 0.32
});
const rail = new THREE.Mesh(
new THREE.BoxGeometry(11.4, 0.16, 0.22),
railMaterial
);
rail.position.y = railY;
rail.castShadow = true;
rail.receiveShadow = true;
scene.add(rail);
const railEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(rail.geometry),
new THREE.LineBasicMaterial({
color: 0x6fa8c9,
transparent: true,
opacity: 0.5
})
);
railEdges.position.copy(rail.position);
scene.add(railEdges);
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x183147,
metalness: 0.65,
roughness: 0.42
});
for (const x of [-5.35, 5.35]) {
const postHeight = railY + 1.05;
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.095, postHeight, 6),
supportMaterial
);
post.position.set(x, -1.05 + postHeight / 2, -0.03);
post.castShadow = true;
scene.add(post);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.42, 0.12, 8),
supportMaterial
);
foot.position.set(x, -1.09, -0.03);
foot.castShadow = true;
scene.add(foot);
}
// -------------------------------------------------------------------------
// Wave direction arrow
// -------------------------------------------------------------------------
const directionMaterial = new THREE.MeshStandardMaterial({
color: 0x74f3c2,
emissive: 0x17694f,
emissiveIntensity: 0.9,
roughness: 0.35
});
const directionArrow = new THREE.Group();
const arrowShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 10, 6),
directionMaterial
);
arrowShaft.rotation.z = -Math.PI / 2;
arrowShaft.position.set(0, 1.98, 0);
directionArrow.add(arrowShaft);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.4, 8),
directionMaterial
);
arrowHead.rotation.z = -Math.PI / 2;
arrowHead.position.set(5.2, 1.98, 0);
directionArrow.add(arrowHead);
scene.add(directionArrow);
// -------------------------------------------------------------------------
// Beads, tethers, equilibrium line, and moving wave trace
// -------------------------------------------------------------------------
const beadCount = 31;
const railSpan = 10.4;
const equilibriumY = 0.2;
const beadGeometry = new THREE.IcosahedronGeometry(0.19, 0);
const beadMaterial = new THREE.MeshStandardMaterial({
color: 0x54d8ff,
emissive: 0x07556c,
emissiveIntensity: 0.72,
metalness: 0.25,
roughness: 0.28,
flatShading: true
});
const trackedBeadMaterial = new THREE.MeshStandardMaterial({
color: 0xffad42,
emissive: 0x8b3d00,
emissiveIntensity: 0.82,
metalness: 0.22,
roughness: 0.3,
flatShading: true
});
const tetherGeometry = new THREE.CylinderGeometry(0.012, 0.012, 1, 5);
const tetherMaterial = new THREE.MeshStandardMaterial({
color: 0x4d7892,
metalness: 0.48,
roughness: 0.5
});
const beads = [];
const tethers = [];
const beadX = [];
for (let i = 0; i < beadCount; i++) {
const x = -railSpan / 2 + (i / (beadCount - 1)) * railSpan;
beadX.push(x);
const bead = new THREE.Mesh(
beadGeometry,
beadMaterial
);
bead.position.set(x, equilibriumY, 0);
bead.castShadow = true;
bead.receiveShadow = true;
scene.add(bead);
beads.push(bead);
const tether = new THREE.Mesh(
tetherGeometry,
tetherMaterial
);
tether.castShadow = true;
scene.add(tether);
tethers.push(tether);
}
// Highlight one bead and fix its horizontal coordinate.
const trackedIndex = 18;
const trackedBead = beads[trackedIndex];
trackedBead.material = trackedBeadMaterial;
const trackedX = beadX[trackedIndex];
// Equilibrium guide behind all beads.
const equilibriumGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-5.35, equilibriumY, -0.06),
new THREE.Vector3(5.35, equilibriumY, -0.06)
]);
const equilibriumLine = new THREE.Line(
equilibriumGeometry,
new THREE.LineDashedMaterial({
color: 0x7794a8,
dashSize: 0.13,
gapSize: 0.1,
transparent: true,
opacity: 0.45
})
);
equilibriumLine.computeLineDistances();
scene.add(equilibriumLine);
// Moving polyline joining the current bead positions.
const wavePositions = new Float32Array(beadCount * 3);
const waveGeometry = new THREE.BufferGeometry();
waveGeometry.setAttribute(
"position",
new THREE.BufferAttribute(wavePositions, 3)
);
const waveTrace = new THREE.Line(
waveGeometry,
new THREE.LineBasicMaterial({
color: 0x65e7ff,
transparent: true,
opacity: 0.68
})
);
waveTrace.frustumCulled = false;
waveTrace.renderOrder = 2;
scene.add(waveTrace);
// -------------------------------------------------------------------------
// Tracked-bead guide: fixed x-position and local vertical oscillation
// -------------------------------------------------------------------------
const trackedGuideMaterial = new THREE.LineDashedMaterial({
color: 0xffad42,
dashSize: 0.11,
gapSize: 0.075,
transparent: true,
opacity: 0.68
});
const trackedGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(trackedX, -0.73, 0.28),
new THREE.Vector3(trackedX, 1.4, 0.28)
]),
trackedGuideMaterial
);
trackedGuide.computeLineDistances();
scene.add(trackedGuide);
const equilibriumGhost = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.OctahedronGeometry(0.255)),
new THREE.LineBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.58
})
);
equilibriumGhost.position.set(trackedX, equilibriumY, 0.015);
scene.add(equilibriumGhost);
const verticalArrow = new THREE.Group();
const verticalArrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffad42,
emissive: 0x743100,
emissiveIntensity: 0.75,
roughness: 0.4
});
const verticalShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.014, 0.014, 1.55, 6),
verticalArrowMaterial
);
verticalShaft.position.set(trackedX + 0.48, 0.2, 0.28);
verticalArrow.add(verticalShaft);
const verticalTop = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.18, 6),
verticalArrowMaterial
);
verticalTop.position.set(trackedX + 0.48, 1.08, 0.28);
verticalArrow.add(verticalTop);
const verticalBottom = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.18, 6),
verticalArrowMaterial
);
verticalBottom.rotation.z = Math.PI;
verticalBottom.position.set(trackedX + 0.48, -0.68, 0.28);
verticalArrow.add(verticalBottom);
scene.add(verticalArrow);
// -------------------------------------------------------------------------
// Custom camera controls — no OrbitControls or addons
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.27,
1.47
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
6.8,
21
);
updateCamera();
}, { passive: false });
// -------------------------------------------------------------------------
// User controls
// -------------------------------------------------------------------------
let amplitude = 0.58;
let wavelength = 6.8;
let speed = 1;
let playing = true;
let elapsed = 0;
const amplitudeInput = document.getElementById("amplitude");
const wavelengthInput = document.getElementById("wavelength");
const speedInput = document.getElementById("speed");
const amplitudeValue = document.getElementById("amplitude-value");
const wavelengthValue = document.getElementById("wavelength-value");
const speedValue = document.getElementById("speed-value");
const toggleButton = document.getElementById("toggle");
amplitudeInput.addEventListener("input", () => {
amplitude = Number(amplitudeInput.value);
amplitudeValue.textContent = amplitude.toFixed(2);
});
wavelengthInput.addEventListener("input", () => {
wavelength = Number(wavelengthInput.value);
wavelengthValue.textContent = wavelength.toFixed(1);
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
speedValue.textContent = speed.toFixed(2);
});
function togglePlayback() {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Resume";
toggleButton.setAttribute("aria-pressed", String(!playing));
}
toggleButton.addEventListener("click", togglePlayback);
document.getElementById("reset-view").addEventListener("click", () => {
orbit.radius = defaultView.radius;
orbit.phi = defaultView.phi;
orbit.theta = defaultView.theta;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
event.target.tagName !== "INPUT" &&
event.target.tagName !== "BUTTON"
) {
event.preventDefault();
togglePlayback();
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projectedMarker = new THREE.Vector3();
function updateWave(time) {
const waveNumber = (Math.PI * 2) / wavelength;
const angularSpeed = 1.25 * speed;
for (let i = 0; i < beadCount; i++) {
const x = beadX[i];
// y = A sin(kx - ωt): the waveform travels in the +x direction,
// while every bead keeps x constant and moves only vertically.
const y = equilibriumY + amplitude * Math.sin(
waveNumber * x - angularSpeed * time
);
beads[i].position.set(x, y, 0);
const tetherBottom = y + 0.145;
const tetherTop = railY - 0.08;
const tetherLength = Math.max(0.05, tetherTop - tetherBottom);
tethers[i].position.set(
x,
(tetherTop + tetherBottom) / 2,
0
);
tethers[i].scale.y = tetherLength;
wavePositions[i * 3] = x;
wavePositions[i * 3 + 1] = y;
wavePositions[i * 3 + 2] = -0.025;
}
waveGeometry.attributes.position.needsUpdate = true;
}
function updateCallout() {
projectedMarker.copy(trackedBead.position);
projectedMarker.y += 0.28;
projectedMarker.project(camera);
const visible =
projectedMarker.z > -1 &&
projectedMarker.z < 1 &&
Math.abs(projectedMarker.x) < 1.15 &&
Math.abs(projectedMarker.y) < 1.15;
callout.style.opacity = visible ? "1" : "0";
const x = (projectedMarker.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedMarker.y * 0.5 + 0.5) * window.innerHeight;
callout.style.left = `${x}px`;
callout.style.top = `${y}px`;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed += delta;
}
updateWave(elapsed);
updateCallout();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
});
</script>
</body>
</html>
```