Prompt specification
Build or customize the Three.js 3D scene "Orderly and mixed tracer comparison" 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: Orderly and mixed tracer comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/orderly-and-mixed-tracer-comparison-x1466
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: orderly and mixed tracer comparison. Place smooth streamline and swirling prescribed tracer displays side by side; distinguish qualitative flow regimes without claiming that particle appearance alone determines Reynolds number. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (orderly-and-mixed-tracer-comparison-x1466):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Orderly & Mixed — Prescribed Tracer Study</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf8ff;
--muted: #8ea8ba;
--cyan: #69e6ff;
--violet: #aa94ff;
--panel: rgba(8, 20, 34, 0.72);
--line: rgba(150, 220, 255, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #06101d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active { cursor: grabbing; }
.brand {
position: fixed;
top: 26px;
left: 30px;
z-index: 5;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.view-hint {
position: fixed;
top: 30px;
right: 30px;
z-index: 5;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(5, 15, 27, 0.56);
color: #91a9ba;
font-size: 10px;
letter-spacing: 0.08em;
pointer-events: none;
backdrop-filter: blur(10px);
}
.controls {
position: fixed;
z-index: 6;
left: 28px;
bottom: 27px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 38px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
button {
border: 1px solid rgba(135, 216, 255, 0.22);
border-radius: 9px;
padding: 9px 12px;
background: rgba(105, 230, 255, 0.08);
color: #dff8ff;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(105, 230, 255, 0.15);
transform: translateY(-1px);
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px 0 4px;
color: #9cb2c1;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 76px;
accent-color: var(--cyan);
cursor: pointer;
}
.interpretation {
position: fixed;
z-index: 5;
right: 28px;
bottom: 27px;
width: min(410px, calc(100vw - 56px));
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
color: #9fb4c3;
font-size: 11px;
line-height: 1.55;
pointer-events: none;
box-shadow: 0 12px 38px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.interpretation strong {
display: block;
margin-bottom: 4px;
color: #e9f8ff;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.equation {
color: #c9e7f7;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #06101d;
color: #88a7ba;
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease, visibility 400ms ease;
}
#loading.hide {
opacity: 0;
visibility: hidden;
}
@media (max-width: 720px) {
.brand {
top: 18px;
left: 18px;
}
.brand p { display: none; }
.view-hint {
top: 19px;
right: 16px;
font-size: 9px;
}
.controls {
left: 14px;
bottom: 14px;
}
.interpretation {
right: 14px;
bottom: 82px;
width: calc(100vw - 28px);
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="brand">
<div class="eyebrow">Prescribed tracer study / 01</div>
<h1>Orderly & Mixed</h1>
<p>Side-by-side qualitative flow-regime comparison</p>
</header>
<div class="view-hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<div class="controls" aria-label="Scene controls">
<button id="pause" type="button" aria-pressed="false">Pause tracers</button>
<button id="reset" type="button">Reset view</button>
<label class="speed-control">
Speed
<input id="speed" type="range" min="0" max="2" step="0.05" value="1">
</label>
</div>
<aside class="interpretation" aria-live="polite">
<strong>Interpretation note</strong>
These labels describe qualitative visual behavior only. Particle size, shape,
color, or streak length alone cannot determine Reynolds number.
<span class="equation">Re = ρUL/μ</span> also requires characteristic length,
velocity, density, and viscosity.
</aside>
<div id="loading">Loading prescribed flow fields</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.domElement.setAttribute(
"aria-label",
"Two side-by-side Three.js displays of orderly and swirling prescribed tracers"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06101d);
scene.fog = new THREE.Fog(0x06101d, 21, 48);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.05, 0);
scene.add(new THREE.HemisphereLight(0x9edfff, 0x07111d, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(5, 8, 11);
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38dfff, 18, 18, 2);
cyanLight.position.set(-6, 1, 5);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x956fff, 17, 18, 2);
violetLight.position.set(6, 0, 5);
scene.add(violetLight);
// Floor and technical grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 32),
new THREE.MeshStandardMaterial({
color: 0x07111d,
roughness: 0.93,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.42;
scene.add(floor);
const floorGrid = new THREE.GridHelper(34, 68, 0x28506a, 0x153248);
floorGrid.position.y = -3.405;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.42;
scene.add(floorGrid);
// -------------------------------------------------------------------------
// Texture helpers
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w * 0.5, h * 0.5);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function makeTextSprite(
text,
{
color = "#eaf8ff",
fontSize = 72,
fontWeight = 700,
worldWidth = 5.4,
canvasHeight = 128
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = canvasHeight;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `${fontWeight} ${fontSize}px Inter, Arial, sans-serif`;
ctx.fillStyle = color;
ctx.fillText(text, canvas.width * 0.5, canvas.height * 0.5, 960);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * canvasHeight / 1024, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeBadge(label, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.beginPath();
ctx.arc(64, 64, 49, 0, Math.PI * 2);
ctx.fillStyle = "rgba(5, 18, 31, 0.88)";
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = color;
ctx.stroke();
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 54px Inter, Arial, sans-serif";
ctx.fillText(label, 64, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
fog: false
}));
sprite.scale.set(0.48, 0.48, 1);
sprite.renderOrder = 21;
return sprite;
}
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createRadialGradient(128, 128, 0, 128, 128, 128);
gradient.addColorStop(0, "rgba(255,255,255,0.9)");
gradient.addColorStop(0.22, "rgba(255,255,255,0.36)");
gradient.addColorStop(0.58, "rgba(255,255,255,0.08)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glowTexture = makeGlowTexture();
// -------------------------------------------------------------------------
// Prescribed vector fields
// -------------------------------------------------------------------------
function orderlyField(x, y, out) {
const u = 1.0;
const v = 0.38 * Math.sin(0.95 * y + 0.35 * Math.sin(0.55 * x));
return out.set(u, v);
}
function mixedField(x, y, out) {
let u = 0.88 + 0.08 * Math.sin(y * 1.35);
let v = 0.07 * Math.cos(x * 1.1);
// Opposing Gaussian vortices produce coherent recirculation and mixing.
const dx1 = x - 0.85;
const dy1 = y - 0.62;
const f1 =
3.55 * Math.exp(-(dx1 * dx1 + dy1 * dy1) / 2.0);
u -= dy1 * f1;
v += dx1 * f1;
const dx2 = x + 1.35;
const dy2 = y + 0.72;
const f2 =
-2.35 * Math.exp(-(dx2 * dx2 + dy2 * dy2) / 1.25);
u -= dy2 * f2;
v += dx2 * f2;
return out.set(u, v);
}
function traceStreamline(field, x0, y0, maxSteps = 300, dt = 0.035) {
const points = [];
let x = x0;
let y = y0;
const k1 = new THREE.Vector2();
const k2 = new THREE.Vector2();
const k3 = new THREE.Vector2();
const k4 = new THREE.Vector2();
for (let i = 0; i < maxSteps; i++) {
points.push(new THREE.Vector3(x, y, 0));
field(x, y, k1);
field(x + k1.x * dt * 0.5, y + k1.y * dt * 0.5, k2);
field(x + k2.x * dt * 0.5, y + k2.y * dt * 0.5, k3);
field(x + k3.x * dt, y + k3.y * dt, k4);
x += dt * (k1.x + 2 * k2.x + 2 * k3.x + k4.x) / 6;
y += dt * (k1.y + 2 * k2.y + 2 * k3.y + k4.y) / 6;
if (x > 3.05 || x < -3.15 || Math.abs(y) > 2.42) break;
}
if (points.length < 8) return null;
return new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
}
// -------------------------------------------------------------------------
// Panels
// -------------------------------------------------------------------------
const panelWidth = 6.45;
const panelHeight = 5.6;
function addBar(group, x, y, width, height, material) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.12),
material
);
bar.position.set(x, y, 0.01);
group.add(bar);
}
function addFieldArrows(group, field, accent) {
const temporary = new THREE.Vector2();
for (let ix = 0; ix < 5; ix++) {
for (let iy = 0; iy < 4; iy++) {
const x = -2.4 + ix * 1.2;
const y = -1.8 + iy * 1.2;
field(x, y, temporary);
const magnitude = Math.max(0.001, temporary.length());
const direction = new THREE.Vector3(
temporary.x / magnitude,
temporary.y / magnitude,
0
);
const arrow = new THREE.ArrowHelper(
direction,
new THREE.Vector3(x, y, 0.045),
Math.min(0.37, 0.16 + magnitude * 0.095),
accent,
0.09,
0.055
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.14;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.19;
arrow.cone.material.depthWrite = false;
group.add(arrow);
}
}
}
function createPanel({
x,
accent,
title,
subtitle,
badge,
footer,
field,
isMixed
}) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const glow = new THREE.Sprite(new THREE.SpriteMaterial({
map: glowTexture,
color: accent,
transparent: true,
opacity: 0.15,
blending: THREE.AdditiveBlending,
depthWrite: false,
toneMapped: false
}));
glow.position.set(0, 0, -0.8);
glow.scale.set(8.3, 8.3, 1);
glow.renderOrder = -2;
group.add(glow);
const backing = new THREE.Mesh(
new THREE.BoxGeometry(panelWidth, panelHeight, 0.22),
new THREE.MeshStandardMaterial({
color: 0x0a1929,
roughness: 0.72,
metalness: 0.2,
emissive: 0x06121e,
emissiveIntensity: 0.52
})
);
backing.position.z = -0.15;
group.add(backing);
const frameMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.62,
depthWrite: false
});
addBar(group, -panelWidth * 0.5, 0, 0.045, panelHeight, frameMaterial);
addBar(group, panelWidth * 0.5, 0, 0.045, panelHeight, frameMaterial);
addBar(group, 0, panelHeight * 0.5, panelWidth, 0.045, frameMaterial);
addBar(group, 0, -panelHeight * 0.5, panelWidth, 0.045, frameMaterial);
// Interior measurement grid.
const gridPositions = [];
for (let i = 0; i <= 8; i++) {
const gx = -3 + i * 0.75;
gridPositions.push(gx, -2.3, -0.025, gx, 2.3, -0.025);
}
for (let i = 0; i <= 5; i++) {
const gy = -2.3 + i * 0.92;
gridPositions.push(-3, gy, -0.025, 3, gy, -0.025);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
group.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x6ba7c5,
transparent: true,
opacity: 0.09,
depthWrite: false
})
));
addFieldArrows(group, field, accent);
const titleSprite = makeTextSprite(title, {
color: isMixed ? "#d5c8ff" : "#b9f5ff",
fontSize: 72,
fontWeight: 760,
worldWidth: 5.55,
canvasHeight: 128
});
titleSprite.position.set(0, 3.36, 0.35);
group.add(titleSprite);
const subtitleSprite = makeTextSprite(subtitle, {
color: "#8faec1",
fontSize: 34,
fontWeight: 520,
worldWidth: 5.6,
canvasHeight: 92
});
subtitleSprite.position.set(0, 2.91, 0.35);
group.add(subtitleSprite);
const badgeSprite = makeBadge(
badge,
isMixed ? "#bba7ff" : "#72e8ff"
);
badgeSprite.position.set(-2.79, 2.38, 0.35);
group.add(badgeSprite);
// Low plinth gives the panel a physical, exhibit-like presence.
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(6.9, 0.27, 1.35),
new THREE.MeshStandardMaterial({
color: 0x0a1826,
roughness: 0.5,
metalness: 0.45,
emissive: 0x06101b,
emissiveIntensity: 0.5
})
);
plinth.position.set(0, -3.02, 0.08);
group.add(plinth);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.28
})
);
plinthEdges.position.copy(plinth.position);
group.add(plinthEdges);
const lightStrip = new THREE.Mesh(
new THREE.BoxGeometry(5.8, 0.022, 0.025),
new THREE.MeshBasicMaterial({ color: accent })
);
lightStrip.position.set(0, -2.975, 0.765);
group.add(lightStrip);
const footerSprite = makeTextSprite(footer, {
color: isMixed ? "#b6a7df" : "#75aec1",
fontSize: 27,
fontWeight: 700,
worldWidth: 5.35,
canvasHeight: 74
});
footerSprite.position.set(0, -3.015, 0.79);
group.add(footerSprite);
return group;
}
const leftPanel = createPanel({
x: -3.55,
accent: 0x65e4ff,
title: "ORDERLY FLOW",
subtitle: "Smooth, coherent prescribed streamlines",
badge: "A",
footer: "COHERENT PATHLINES",
field: orderlyField,
isMixed: false
});
const rightPanel = createPanel({
x: 3.55,
accent: 0xa991ff,
title: "MIXED FLOW",
subtitle: "Swirling paths with varied tracer scales",
badge: "B",
footer: "ILLUSTRATIVE MIXING / VARIABLE SCALES",
field: mixedField,
isMixed: true
});
// A subtle divider emphasizes the side-by-side comparison.
const divider = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -2.45, -0.02),
new THREE.Vector3(0, 2.45, -0.02)
]),
new THREE.LineBasicMaterial({
color: 0x72b8d0,
transparent: true,
opacity: 0.16
})
);
scene.add(divider);
// -------------------------------------------------------------------------
// Streamlines and animated prescribed tracers
// -------------------------------------------------------------------------
const leftCurves = [];
for (let i = 0; i < 16; i++) {
const y = -2.08 + i * (4.16 / 15);
const curve = traceStreamline(orderlyField, -3.0, y, 230, 0.035);
if (curve) leftCurves.push(curve);
}
const rightCurves = [];
// Paths entering from the left side of the mixed field.
for (let i = 0; i < 17; i++) {
const y = -2.2 + i * (4.4 / 16);
const curve = traceStreamline(mixedField, -3.0, y, 340, 0.033);
if (curve) rightCurves.push(curve);
}
// Additional short paths reveal the two recirculation structures.
for (const x of [-1.65, 0.0, 1.65]) {
for (const y of [-1.65, -0.82, 0, 0.82, 1.65]) {
const curve = traceStreamline(mixedField, x, y, 240, 0.031);
if (curve) rightCurves.push(curve);
}
}
const leftPalette = [0x67e8f9, 0x51efbd, 0xb6f5ff, 0xffd27a];
const rightPalette = [0x9c8cff, 0xff748d, 0x50e3d0, 0xffc56e];
function addStreamlines(group, curves, palette, mixed) {
curves.forEach((curve, index) => {
const color = palette[index % palette.length];
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(mixed ? 145 : 125)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: mixed ? 0.19 : 0.23,
depthWrite: false
})
);
line.position.z = 0.025;
line.renderOrder = 1;
group.add(line);
});
}
addStreamlines(leftPanel, leftCurves, leftPalette, false);
addStreamlines(rightPanel, rightCurves, rightPalette, true);
const axisX = new THREE.Vector3(1, 0, 0);
const dummy = new THREE.Object3D();
function createTracerSystem(group, curves, palette, options) {
const {
perCurve,
baseSpeed,
mixed,
depth
} = options;
const count = curves.length * perCurve;
const core = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 9, 7),
new THREE.MeshBasicMaterial({
color: 0xffffff,
toneMapped: false
}),
count
);
const glow = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 8, 6),
new THREE.MeshBasicMaterial({
color: mixed ? 0xa8b5ff : 0x70ddff,
transparent: true,
opacity: 0.055,
blending: THREE.AdditiveBlending,
depthWrite: false,
toneMapped: false
}),
count
);
core.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
glow.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
core.frustumCulled = false;
glow.frustumCulled = false;
core.renderOrder = 5;
glow.renderOrder = 4;
const particles = [];
for (let curveIndex = 0; curveIndex < curves.length; curveIndex++) {
for (let particleIndex = 0; particleIndex < perCurve; particleIndex++) {
const index = curveIndex * perCurve + particleIndex;
const round = mixed && Math.random() < 0.4;
let sx;
let sy;
let sz;
if (mixed && round) {
const radius = 0.052 + Math.random() * 0.045;
sx = sy = sz = radius;
} else if (mixed) {
sx = 0.105 + Math.random() * 0.065;
sy = 0.042 + Math.random() * 0.028;
sz = 0.042 + Math.random() * 0.028;
} else {
sx = 0.12 + Math.random() * 0.035;
sy = 0.042 + Math.random() * 0.012;
sz = 0.042 + Math.random() * 0.012;
}
const particle = {
curve: curves[curveIndex],
phase: Math.random(),
speed: baseSpeed * (0.76 + Math.random() * 0.48),
sx,
sy,
sz,
round,
z: depth + Math.random() * 0.065
};
particles.push(particle);
let color = new THREE.Color(
palette[(curveIndex + particleIndex) % palette.length]
);
// Rare warm markers add visual rhythm without representing a
// physical particle property.
if (!mixed && Math.random() < 0.055) {
color = new THREE.Color(0xffd27a);
}
core.setColorAt(index, color);
}
}
if (core.instanceColor) core.instanceColor.needsUpdate = true;
group.add(glow);
group.add(core);
return { core, glow, particles };
}
const leftSystem = createTracerSystem(
leftPanel,
leftCurves,
leftPalette,
{
perCurve: 13,
baseSpeed: 0.040,
mixed: false,
depth: 0.12
}
);
const rightSystem = createTracerSystem(
rightPanel,
rightCurves,
rightPalette,
{
perCurve: 11,
baseSpeed: 0.031,
mixed: true,
depth: 0.12
}
);
function updateTracerSystem(system, time) {
system.particles.forEach((particle, index) => {
const t = (
particle.phase + time * particle.speed
) % 1;
const position = particle.curve.getPointAt(t);
const tangent = particle.curve.getTangentAt(t);
dummy.position.set(position.x, position.y, particle.z);
if (particle.round) {
dummy.quaternion.identity();
} else {
dummy.quaternion.setFromUnitVectors(axisX, tangent);
}
dummy.scale.set(particle.sx, particle.sy, particle.sz);
dummy.updateMatrix();
system.core.setMatrixAt(index, dummy.matrix);
dummy.scale.multiplyScalar(2.5);
dummy.updateMatrix();
system.glow.setMatrixAt(index, dummy.matrix);
});
system.core.instanceMatrix.needsUpdate = true;
system.glow.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons or example modules
// -------------------------------------------------------------------------
let theta = 0;
let targetTheta = 0;
let phi = 1.47;
let targetPhi = 1.47;
let radius = 16;
let targetRadius = 16;
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const requiredWidth = 14.6;
const requiredHeight = 7.9;
const widthDistance =
requiredWidth / (2 * Math.tan(verticalFov * 0.5) * aspect);
const heightDistance =
requiredHeight / (2 * Math.tan(verticalFov * 0.5));
return Math.max(15.5, widthDistance, heightDistance);
}
function resetCamera() {
targetTheta = 0;
targetPhi = 1.47;
targetRadius = fittedRadius();
}
resetCamera();
radius = targetRadius;
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
targetTheta = THREE.MathUtils.clamp(
targetTheta + dx * 0.0042,
-0.52,
0.52
);
targetPhi = THREE.MathUtils.clamp(
targetPhi + dy * 0.0034,
1.08,
1.76
);
});
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();
targetRadius = THREE.MathUtils.clamp(
targetRadius + event.deltaY * 0.009,
fittedRadius(),
42
);
}, { passive: false });
function updateCamera(delta) {
const smoothing = 1 - Math.pow(0.001, delta);
theta += (targetTheta - theta) * smoothing;
phi += (targetPhi - phi) * smoothing;
radius += (targetRadius - radius) * smoothing;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Interface and animation
// -------------------------------------------------------------------------
const pauseButton = document.querySelector("#pause");
const speedInput = document.querySelector("#speed");
const resetButton = document.querySelector("#reset");
let running = true;
let tracerSpeed = Number(speedInput.value);
let simulationTime = 0;
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause tracers" : "Resume tracers";
pauseButton.setAttribute("aria-pressed", String(!running));
});
speedInput.addEventListener("input", () => {
tracerSpeed = Number(speedInput.value);
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
const minimum = fittedRadius();
if (targetRadius < minimum) targetRadius = minimum;
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
simulationTime += delta * tracerSpeed;
}
updateTracerSystem(leftSystem, simulationTime);
updateTracerSystem(rightSystem, simulationTime);
updateCamera(delta);
renderer.render(scene, camera);
});
// Render once before dismissing the loading state.
updateTracerSystem(leftSystem, simulationTime);
updateTracerSystem(rightSystem, simulationTime);
updateCamera(1);
renderer.render(scene, camera);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hide");
});
</script>
</body>
</html>
```