Prompt specification
Build or customize the Three.js 3D scene "Parallel and perpendicular particle paths" 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: Parallel and perpendicular particle paths
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/parallel-and-perpendicular-particle-paths-x1646
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring magnetic forces on moving charged particles. Show two charged particles entering a uniform magnetic field with different velocity orientations; display straight parallel motion and circular perpendicular motion under ideal assumptions. Stylized solid forms.
Working Three.js Starter (parallel-and-perpendicular-particle-paths-x1646):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Magnetic Field Trajectories</title>
<style>
:root {
color-scheme: dark;
--bg: #050914;
--panel: rgba(10, 18, 34, 0.78);
--border: rgba(148, 184, 220, 0.18);
--text: #eaf3ff;
--muted: #91a6bf;
--cyan: #4de3ef;
--gold: #ffc857;
--pink: #ff62bd;
--coral: #ff766f;
}
* {
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;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.26);
}
.intro {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
line-height: 1.06;
letter-spacing: -0.035em;
}
.intro p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 22px;
right: 22px;
width: 250px;
padding: 15px;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.control-row:last-child {
margin-bottom: 0;
}
.control-label {
color: var(--muted);
font-size: 12px;
font-weight: 700;
}
button {
appearance: none;
border: 1px solid rgba(141, 199, 231, 0.25);
border-radius: 10px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(77, 227, 239, 0.11);
border-color: rgba(77, 227, 239, 0.5);
}
button:active {
transform: translateY(1px);
}
.button-group {
display: flex;
gap: 7px;
}
input[type="range"] {
width: 118px;
accent-color: var(--cyan);
}
input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: var(--cyan);
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
}
.status::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
content: "";
}
.status.paused {
color: var(--gold);
}
.equations {
position: absolute;
right: 22px;
bottom: 22px;
left: 22px;
display: grid;
grid-template-columns: 1fr 1fr 1.15fr;
gap: 10px;
}
.equation-card {
min-height: 94px;
padding: 15px 17px;
border-top: 2px solid var(--cyan);
}
.equation-card.parallel {
border-top-color: var(--gold);
}
.equation-card.perpendicular {
border-top-color: var(--pink);
}
.equation-card h2 {
margin: 0 0 8px;
font-size: 12px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.equation {
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
line-height: 1.1;
}
.equation-card p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.gold {
color: var(--gold);
}
.pink {
color: var(--pink);
}
.cyan {
color: var(--cyan);
}
.hint {
position: absolute;
bottom: 132px;
left: 50%;
transform: translateX(-50%);
color: rgba(205, 221, 239, 0.5);
font-size: 11px;
white-space: nowrap;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.intro p {
display: none;
}
.controls {
top: 112px;
right: 12px;
width: 205px;
padding: 11px;
}
.equations {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: 1fr;
gap: 7px;
}
.equation-card {
min-height: 0;
padding: 10px 13px;
}
.equation-card p {
display: none;
}
.equation {
font-size: 18px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="intro panel">
<div class="eyebrow">Lorentz force laboratory</div>
<h1>Magnetic field trajectories</h1>
<p>
Two positive charges enter the same uniform field. Their paths differ
because the magnetic force depends on the angle between velocity and
the field direction.
</p>
</section>
<section class="controls panel" aria-label="Scene controls">
<div class="control-row">
<span id="status" class="status">RUNNING</span>
<button id="pause" type="button">Pause</button>
</div>
<div class="control-row">
<span class="control-label">Simulation speed</span>
<input
id="speed"
type="range"
min="0.25"
max="2"
step="0.05"
value="1"
aria-label="Simulation speed"
/>
</div>
<div class="control-row">
<span class="control-label">Velocity & force</span>
<input id="vectors" type="checkbox" checked />
</div>
<div class="control-row">
<span class="control-label">Scene</span>
<div class="button-group">
<button id="reset" type="button">Reset</button>
<button id="camera-reset" type="button">View</button>
</div>
</div>
</section>
<div class="hint">Drag to orbit · scroll to zoom</div>
<section class="equations">
<article class="equation-card parallel panel">
<h2 class="gold">Parallel velocity</h2>
<div class="equation">F<sub>B</sub> = q(v × B) = 0</div>
<p>With velocity parallel to B, there is no magnetic force.</p>
</article>
<article class="equation-card perpendicular panel">
<h2 class="pink">Perpendicular velocity</h2>
<div class="equation">r = mv / |q|B</div>
<p>The force turns the velocity continuously, producing circular motion.</p>
</article>
<article class="equation-card panel">
<h2 class="cyan">Ideal assumptions</h2>
<div class="equation">Uniform B · no drag · q > 0</div>
<p>
Non-relativistic particles, fixed field strength, and no collisions or
electromagnetic radiation effects.
</p>
</article>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050914);
scene.fog = new THREE.Fog(0x050914, 18, 42);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.domElement.setAttribute(
"aria-label",
"Interactive magnetic field trajectory simulation"
);
document.body.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0x9ac7ff, 0x101421, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(7, 12, 9);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x42d9ff, 2.0);
rimLight.position.set(-9, 4, -8);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb84f, 16, 20, 2);
warmLight.position.set(-2, 4, -3);
scene.add(warmLight);
const pinkLight = new THREE.PointLight(0xff45af, 14, 18, 2);
pinkLight.position.set(2, -1, 5);
scene.add(pinkLight);
// ------------------------------------------------------------
// Custom camera controls; no external controls addon
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, -0.6, 0),
theta: 0.73,
phi: 1.03,
radius: 20.5
};
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0, -0.6, 0);
cameraState.theta = 0.73;
cameraState.phi = 1.03;
cameraState.radius = 20.5;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
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;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.32,
1.48
);
updateCamera();
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// ------------------------------------------------------------
// Helpers
// ------------------------------------------------------------
const X_AXIS = new THREE.Vector3(1, 0, 0);
const UP_AXIS = new THREE.Vector3(0, 1, 0);
function makeLabel(text, color = "#dbeafe", scale = 1) {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
context.font = "700 52px system-ui, sans-serif";
const textWidth = context.measureText(text).width;
canvas.width = Math.ceil(textWidth + 44);
canvas.height = 88;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 10, 22, 0.78)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(155, 196, 226, 0.25)";
context.lineWidth = 3;
context.strokeRect(1.5, 1.5, canvas.width - 3, canvas.height - 3);
context.font = "700 52px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
const aspect = canvas.width / canvas.height;
sprite.scale.set(2.2 * aspect * scale, 2.2 * scale, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeArrow(color, radius = 0.045) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.45,
roughness: 0.3,
metalness: 0.15
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 12),
material
);
shaft.rotation.z = -Math.PI / 2;
shaft.position.x = 0.5;
const head = new THREE.Mesh(
new THREE.ConeGeometry(radius * 3.2, radius * 6.5, 16),
material
);
head.rotation.z = -Math.PI / 2;
head.position.x = 1.15;
group.add(shaft, head);
group.userData.baseLength = 1.3;
return group;
}
function orientArrow(arrow, position, direction, length) {
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(X_AXIS, direction);
arrow.scale.set(length / arrow.userData.baseLength, 1, 1);
}
function makeTube(start, end, color, radius = 0.035) {
const curve = new THREE.LineCurve3(start, end);
const geometry = new THREE.TubeGeometry(curve, 1, radius, 8, false);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.35,
metalness: 0.1
});
return new THREE.Mesh(geometry, material);
}
function makeParticle(color) {
const group = new THREE.Group();
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.36, 2),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.34,
roughness: 0.22,
metalness: 0.28
})
);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0xeaf8ff,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.25,
metalness: 0.3
});
const ringA = new THREE.Mesh(
new THREE.TorusGeometry(0.51, 0.025, 8, 48),
ringMaterial
);
const ringB = new THREE.Mesh(
new THREE.TorusGeometry(0.51, 0.018, 8, 48),
ringMaterial
);
ringB.rotation.x = Math.PI / 2;
const charge = makeLabel("+", "#ffffff", 0.42);
charge.position.y = 0.83;
group.add(core, ringA, ringB, charge);
group.userData.core = core;
group.userData.rings = [ringA, ringB];
return group;
}
// ------------------------------------------------------------
// Ground and magnetic-field volume
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(48, 34),
new THREE.MeshStandardMaterial({
color: 0x080e19,
roughness: 0.92,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.85;
scene.add(ground);
const grid = new THREE.GridHelper(42, 42, 0x1b4960, 0x10283a);
grid.position.y = -5.82;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
const fieldGeometry = new THREE.BoxGeometry(13, 11, 11.5);
const fieldCenter = new THREE.Vector3(1, -0.1, 1.25);
const fieldVolume = new THREE.Mesh(
fieldGeometry,
new THREE.MeshStandardMaterial({
color: 0x25c7df,
transparent: true,
opacity: 0.055,
roughness: 0.4,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
fieldVolume.position.copy(fieldCenter);
scene.add(fieldVolume);
const fieldEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(fieldGeometry),
new THREE.LineBasicMaterial({
color: 0x42ddeb,
transparent: true,
opacity: 0.34
})
);
fieldEdges.position.copy(fieldCenter);
scene.add(fieldEdges);
// Solid arrows showing the uniform field direction: +X.
const fieldArrows = [];
for (const y of [-3.7, -0.5, 2.7]) {
for (const z of [-2.8, 0.4, 3.6]) {
const arrow = makeArrow(0x45d8e8, 0.032);
arrow.position.set(-2.3, y, z);
arrow.scale.x = 1.8;
fieldArrows.push(arrow);
scene.add(arrow);
}
}
const fieldLabel = makeLabel("UNIFORM B →", "#62e5ef", 0.82);
fieldLabel.position.set(-3.6, 4.55, -3.55);
scene.add(fieldLabel);
// ------------------------------------------------------------
// Parallel trajectory: particle moves along +X, parallel to B
// ------------------------------------------------------------
const parallelY = 1.75;
const parallelZ = -2.65;
const parallelPath = makeTube(
new THREE.Vector3(-10, parallelY, parallelZ),
new THREE.Vector3(10.5, parallelY, parallelZ),
0xffc857,
0.04
);
scene.add(parallelPath);
const parallelLabel = makeLabel("v ∥ B", "#ffd574", 0.78);
parallelLabel.position.set(-1.6, 2.9, -2.65);
scene.add(parallelLabel);
const parallelParticle = makeParticle(0xffc857);
scene.add(parallelParticle);
const parallelVelocityArrow = makeArrow(0xffd66f, 0.055);
const parallelForceArrow = makeArrow(0xff766f, 0.045);
parallelForceArrow.visible = false;
scene.add(parallelVelocityArrow, parallelForceArrow);
const parallelDotMaterial = new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0xffa72e,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.48
});
for (let i = 0; i < 14; i++) {
const dot = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 1),
parallelDotMaterial
);
dot.position.set(-9.5 + i * 1.42, parallelY, parallelZ);
scene.add(dot);
}
// ------------------------------------------------------------
// Perpendicular trajectory: motion in the YZ plane
// ------------------------------------------------------------
const circleX = 1.3;
const circleStartY = -3.5;
const circleStartZ = 4.2;
const circleRadius = 2.0;
const circleCenter = new THREE.Vector3(
circleX,
circleStartY + circleRadius,
circleStartZ
);
const circleRing = new THREE.Mesh(
new THREE.TorusGeometry(circleRadius, 0.037, 10, 144),
new THREE.MeshStandardMaterial({
color: 0xff62bd,
emissive: 0xff2aa5,
emissiveIntensity: 0.65,
roughness: 0.3,
metalness: 0.12
})
);
circleRing.rotation.y = Math.PI / 2;
circleRing.position.copy(circleCenter);
scene.add(circleRing);
const perpendicularApproach = makeTube(
new THREE.Vector3(circleX, circleStartY, 4.2),
new THREE.Vector3(circleX, circleStartY, 9.2),
0xff62bd,
0.035
);
scene.add(perpendicularApproach);
const perpendicularLabel = makeLabel("v ⟂ B", "#ff7bc7", 0.78);
perpendicularLabel.position.set(2.55, -4.6, 6.35);
scene.add(perpendicularLabel);
const perpendicularParticle = makeParticle(0xff62bd);
scene.add(perpendicularParticle);
const perpendicularVelocityArrow = makeArrow(0xff80ca, 0.055);
const perpendicularForceArrow = makeArrow(0xff766f, 0.045);
scene.add(perpendicularVelocityArrow, perpendicularForceArrow);
const circleDotMaterial = new THREE.MeshStandardMaterial({
color: 0xff62bd,
emissive: 0xff2aa5,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.48
});
for (let i = 0; i < 14; i++) {
const theta = (i / 14) * Math.PI * 2;
const dot = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 1),
circleDotMaterial
);
dot.position.set(
circleX,
circleStartY + circleRadius * (1 - Math.cos(theta)),
circleStartZ + circleRadius * Math.sin(theta)
);
scene.add(dot);
}
// ------------------------------------------------------------
// Simulation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const parallelPosition = new THREE.Vector3();
const perpendicularPosition = new THREE.Vector3();
let simulationTime = 1.8;
let paused = false;
let speed = 1;
let showVectors = true;
const approachDuration = 1.4;
const orbitDuration = 6.0;
const perpendicularCycle = approachDuration + orbitDuration;
function updateSimulation(delta) {
if (!paused) {
simulationTime += delta * speed;
}
// Parallel particle: uniform straight motion along B.
const parallelTravel = (simulationTime * 3.15) % 21;
parallelPosition.set(
-10 + parallelTravel,
parallelY,
parallelZ
);
parallelParticle.position.copy(parallelPosition);
orientArrow(
parallelVelocityArrow,
parallelPosition,
X_AXIS,
1.45
);
parallelForceArrow.visible = false;
// Perpendicular particle:
// First show the incoming straight section, then the ideal orbit.
const cycleTime = simulationTime % perpendicularCycle;
let orbitAngle = 0;
let orbiting = false;
if (cycleTime < approachDuration) {
const fraction = cycleTime / approachDuration;
perpendicularPosition.set(
circleX,
circleStartY,
THREE.MathUtils.lerp(9.2, circleStartZ, fraction)
);
} else {
orbiting = true;
orbitAngle =
((cycleTime - approachDuration) / orbitDuration) * Math.PI * 2;
perpendicularPosition.set(
circleX,
circleStartY + circleRadius * (1 - Math.cos(orbitAngle)),
circleStartZ + circleRadius * Math.sin(orbitAngle)
);
}
perpendicularParticle.position.copy(perpendicularPosition);
// Velocity is tangent to the circular path.
const tangent = new THREE.Vector3(
0,
Math.sin(orbitAngle),
Math.cos(orbitAngle)
);
if (!orbiting) {
tangent.set(0, 0, 1);
}
orientArrow(
perpendicularVelocityArrow,
perpendicularPosition,
tangent,
1.45
);
// The magnetic force points toward the circle's center.
const forceDirection = new THREE.Vector3()
.subVectors(circleCenter, perpendicularPosition)
.normalize();
perpendicularForceArrow.visible = orbiting;
orientArrow(
perpendicularForceArrow,
perpendicularPosition,
forceDirection,
1.05
);
parallelVelocityArrow.visible = showVectors;
perpendicularVelocityArrow.visible = showVectors;
perpendicularForceArrow.visible = showVectors && orbiting;
// Gentle rotation gives the solid charge models a stylized feel.
parallelParticle.userData.core.rotation.x += delta * 0.45;
parallelParticle.userData.core.rotation.y += delta * 0.7;
perpendicularParticle.userData.core.rotation.x -= delta * 0.5;
perpendicularParticle.userData.core.rotation.y += delta * 0.8;
perpendicularParticle.userData.rings[0].rotation.z += delta * 0.5;
perpendicularParticle.userData.rings[1].rotation.y += delta * 0.65;
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const pauseButton = document.getElementById("pause");
const status = document.getElementById("status");
const speedInput = document.getElementById("speed");
const vectorInput = document.getElementById("vectors");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
status.textContent = paused ? "PAUSED" : "RUNNING";
status.classList.toggle("paused", paused);
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
});
vectorInput.addEventListener("change", () => {
showVectors = vectorInput.checked;
});
document.getElementById("reset").addEventListener("click", () => {
simulationTime = 0;
});
document.getElementById("camera-reset").addEventListener("click", resetCamera);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateSimulation(delta);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```