Prompt specification
Build or customize the Three.js 3D scene "Equal parameter and equal distance markers" 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: Equal parameter and equal distance markers
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-parameter-and-equal-distance-markers-x1714
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing parametric curves and control points. Place two marker sequences along one curved path, one sampled uniformly in parameter and one approximately by arc length; reveal their different spatial spacing. Stylized solid forms.
Working Three.js Starter (equal-parameter-and-equal-distance-markers-x1714):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>One Path — Two Rhythms</title>
<style>
:root {
--ink: #202521;
--muted: #706f68;
--paper: #f1ede4;
--panel: rgba(249, 247, 241, 0.88);
--line: rgba(32, 37, 33, 0.14);
--coral: #f06448;
--teal: #079b94;
--gold: #d49b2f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
overscroll-behavior: none;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#stage canvas.grabbing {
cursor: grabbing;
}
.title-panel {
position: fixed;
z-index: 3;
top: 30px;
left: 32px;
width: 390px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 18px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
background: var(--coral);
content: "";
}
h1 {
margin: 0;
font-size: clamp(42px, 5.1vw, 74px);
font-weight: 780;
letter-spacing: -0.065em;
line-height: 0.91;
}
h1 em {
color: var(--coral);
font-family: Georgia, "Times New Roman", serif;
font-weight: 400;
}
.title-panel p {
max-width: 345px;
margin: 19px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow:
0 18px 45px rgba(39, 34, 25, 0.09),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.controls-panel {
position: fixed;
z-index: 4;
bottom: 28px;
left: 30px;
width: 330px;
padding: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-heading span:last-child {
color: #9b988f;
font-weight: 600;
letter-spacing: 0.04em;
}
.layer-list {
display: grid;
gap: 4px;
}
.layer {
display: grid;
grid-template-columns: 22px 1fr auto;
align-items: center;
min-height: 35px;
border-radius: 9px;
cursor: pointer;
font-size: 12px;
transition: background 150ms ease;
}
.layer:hover {
background: rgba(32, 37, 33, 0.045);
}
.layer input {
width: 14px;
height: 14px;
margin: 0;
accent-color: var(--ink);
cursor: pointer;
}
.layer-symbol {
display: inline-flex;
align-items: center;
justify-content: center;
width: 19px;
height: 19px;
}
.symbol-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 2px 5px rgba(240, 100, 72, 0.28);
}
.symbol-ring {
width: 13px;
height: 13px;
border: 4px solid var(--teal);
border-radius: 50%;
}
.symbol-line {
width: 17px;
height: 2px;
border-radius: 2px;
background: var(--ink);
}
.symbol-control {
width: 11px;
height: 11px;
border-radius: 2px;
background: var(--ink);
transform: rotate(45deg);
}
.symbol-vector {
width: 17px;
height: 2px;
background: var(--gold);
transform: rotate(-35deg);
position: relative;
}
.symbol-vector::after {
position: absolute;
top: -3px;
right: -1px;
width: 6px;
height: 6px;
border-top: 2px solid var(--gold);
border-right: 2px solid var(--gold);
content: "";
transform: rotate(45deg);
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
button {
min-height: 39px;
border: 0;
border-radius: 10px;
cursor: pointer;
font-size: 12px;
font-weight: 720;
transition:
transform 140ms ease,
background 140ms ease,
color 140ms ease;
}
button:active {
transform: translateY(1px);
}
#play-button {
color: #f8f5ee;
background: var(--ink);
}
#play-button:hover {
background: #343a35;
}
#reset-button {
width: 42px;
color: var(--ink);
background: rgba(32, 37, 33, 0.075);
font-size: 17px;
}
#reset-button:hover {
background: rgba(32, 37, 33, 0.13);
}
.metrics-panel {
position: fixed;
z-index: 4;
top: 30px;
right: 30px;
width: 280px;
padding: 18px;
}
.metric {
padding: 12px 0;
border-bottom: 1px solid var(--line);
}
.metric:last-of-type {
border-bottom: 0;
}
.metric-label {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.metric-label i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
}
.metric-label i.teal {
background: var(--teal);
}
.metric strong {
display: block;
font-size: 19px;
font-weight: 690;
letter-spacing: -0.025em;
}
.metric small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.spread {
display: inline-block;
margin-top: 7px;
padding: 4px 7px;
border-radius: 999px;
color: #9c3e2e;
background: rgba(240, 100, 72, 0.1);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.spread.teal {
color: #08756f;
background: rgba(7, 155, 148, 0.11);
}
.metrics-note {
margin: 12px 0 0;
color: #8b887f;
font-size: 9px;
line-height: 1.45;
}
.hint {
position: fixed;
z-index: 3;
right: 30px;
bottom: 30px;
color: rgba(32, 37, 33, 0.55);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
pointer-events: none;
}
#inspector {
position: fixed;
z-index: 6;
display: none;
min-width: 134px;
padding: 10px 12px;
border: 1px solid rgba(32, 37, 33, 0.13);
border-radius: 11px;
background: rgba(251, 249, 244, 0.94);
box-shadow: 0 10px 30px rgba(30, 27, 20, 0.14);
pointer-events: none;
transform: translate(-50%, calc(-100% - 15px));
}
#inspector::after {
position: absolute;
bottom: -5px;
left: calc(50% - 5px);
width: 9px;
height: 9px;
border-right: 1px solid rgba(32, 37, 33, 0.13);
border-bottom: 1px solid rgba(32, 37, 33, 0.13);
background: rgba(251, 249, 244, 0.94);
content: "";
transform: rotate(45deg);
}
#inspector span {
display: block;
margin-bottom: 5px;
color: #8a877f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
}
#inspector strong,
#inspector small {
display: block;
white-space: nowrap;
}
#inspector strong {
font-size: 12px;
}
#inspector small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: var(--paper);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-panel {
top: 20px;
left: 20px;
width: calc(100% - 40px);
}
h1 {
font-size: 43px;
}
.title-panel p {
display: none;
}
.eyebrow {
margin-bottom: 12px;
}
.metrics-panel {
top: 137px;
right: 16px;
width: 190px;
padding: 13px;
}
.metric {
padding: 9px 0;
}
.metric strong {
font-size: 15px;
}
.metrics-note,
.metric small {
display: none;
}
.controls-panel {
bottom: 14px;
left: 14px;
width: calc(100% - 28px);
padding: 13px;
}
.controls-panel .layer-list {
grid-template-columns: 1fr 1fr;
column-gap: 8px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-panel">
<div class="eyebrow">Geometry Study / 01</div>
<h1>One path.<br /><em>Two rhythms.</em></h1>
<p>
A cubic Bézier sampled evenly in parameter space, then again by
approximate arc length. The curve stays fixed; only the spacing changes.
</p>
</header>
<aside class="panel metrics-panel">
<div class="panel-heading">
<span>Consecutive gaps</span>
<span>25 markers</span>
</div>
<div class="metric">
<div class="metric-label"><i></i> Uniform parameter t</div>
<strong id="uniform-range">—</strong>
<small>Distance between adjacent samples</small>
<span class="spread" id="uniform-spread">—</span>
</div>
<div class="metric">
<div class="metric-label"><i class="teal"></i> Approx. arc length</div>
<strong id="arc-range">—</strong>
<small>Distance between adjacent samples</small>
<span class="spread teal" id="arc-spread">—</span>
</div>
<p class="metrics-note">
Arc-length positions use a 2,400-step lookup table.
</p>
</aside>
<section class="panel controls-panel">
<div class="panel-heading">
<span>Layers</span>
<span>B(t), cubic Bézier</span>
</div>
<div class="layer-list">
<label class="layer">
<input type="checkbox" id="uniform-toggle" checked />
<span class="layer-symbol"><i class="symbol-dot"></i></span>
<span>Uniform in parameter t</span>
</label>
<label class="layer">
<input type="checkbox" id="arc-toggle" checked />
<span class="layer-symbol"><i class="symbol-ring"></i></span>
<span>Approximately uniform arc length</span>
</label>
<label class="layer">
<input type="checkbox" id="control-toggle" checked />
<span class="layer-symbol"><i class="symbol-control"></i></span>
<span>Control points and polygon</span>
</label>
<label class="layer">
<input type="checkbox" id="vector-toggle" />
<span class="layer-symbol"><i class="symbol-vector"></i></span>
<span>Parameter-speed vectors</span>
</label>
</div>
<div class="button-row">
<button id="play-button" type="button">Run synchronized sweep</button>
<button id="reset-button" type="button" aria-label="Reset camera" title="Reset camera">
↺
</button>
</div>
</section>
<div class="hint">Drag to orbit · Wheel to zoom · Click the curve to inspect</div>
<div id="inspector">
<span>Curve inspection</span>
<strong id="inspect-t">t = 0.000</strong>
<small id="inspect-s">s = 0.00 units</small>
</div>
<div id="loading">Building the curve…</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
// -------------------------------------------------------------------------
const host = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1ede4);
scene.fog = new THREE.Fog(0xf1ede4, 18, 34);
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.setAttribute("aria-label", "Interactive 3D Bézier curve visualization");
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.15, 0.95, 0);
const initialView = {
theta: 0.72,
phi: 1.02,
radius: 15.4
};
const view = { ...initialView };
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.cos(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.sin(view.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting and sculptural platform
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfffbf2, 0x8e8b80, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff6e7, 3.1);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcce9ea, 1.0);
fillLight.position.set(-7, 4, -6);
scene.add(fillLight);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xe3ddd2,
roughness: 0.95,
metalness: 0
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(7.45, 7.68, 0.36, 64),
platformMaterial
);
platform.position.y = -2.15;
platform.receiveShadow = true;
scene.add(platform);
const platformEdge = new THREE.Mesh(
new THREE.TorusGeometry(7.43, 0.018, 6, 128),
new THREE.MeshStandardMaterial({
color: 0xb9b0a2,
roughness: 0.8
})
);
platformEdge.rotation.x = Math.PI / 2;
platformEdge.position.y = -1.962;
scene.add(platformEdge);
// -------------------------------------------------------------------------
// Parametric cubic Bézier
// -------------------------------------------------------------------------
const controlPoints = [
new THREE.Vector3(-4.4, -1.25, 0.0),
new THREE.Vector3(-6.3, 3.7, 1.8),
new THREE.Vector3(5.7, 4.2, -1.6),
new THREE.Vector3(4.1, -1.25, 0.0)
];
const curve = new THREE.CubicBezierCurve3(...controlPoints);
function derivativeAt(t) {
const s = 1 - t;
return new THREE.Vector3()
.addScaledVector(
controlPoints[1].clone().sub(controlPoints[0]),
3 * s * s
)
.addScaledVector(
controlPoints[2].clone().sub(controlPoints[1]),
6 * s * t
)
.addScaledVector(
controlPoints[3].clone().sub(controlPoints[2]),
3 * t * t
);
}
const curveMesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 360, 0.065, 8, false),
new THREE.MeshStandardMaterial({
color: 0x252a26,
roughness: 0.66,
metalness: 0.02
})
);
curveMesh.castShadow = true;
curveMesh.receiveShadow = true;
scene.add(curveMesh);
// A wider invisible tube makes the curve easier to click.
const pickMesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 360, 0.19, 8, false),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
})
);
scene.add(pickMesh);
// -------------------------------------------------------------------------
// Canvas-generated labels
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(text, accent = "#202521") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 96;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 256, 96);
roundedRect(ctx, 4, 8, 248, 80, 22);
ctx.fillStyle = "rgba(250,248,242,0.96)";
ctx.fill();
ctx.lineWidth = 3;
ctx.strokeStyle = "rgba(32,37,33,0.18)";
ctx.stroke();
ctx.fillStyle = accent;
ctx.font = "700 39px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 49);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.78, 0.293, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Control cage
// -------------------------------------------------------------------------
const controlGroup = new THREE.Group();
scene.add(controlGroup);
const polygonGeometry = new THREE.BufferGeometry().setFromPoints(controlPoints);
const polygon = new THREE.Line(
polygonGeometry,
new THREE.LineDashedMaterial({
color: 0x77766f,
transparent: true,
opacity: 0.55,
dashSize: 0.16,
gapSize: 0.11
})
);
polygon.computeLineDistances();
controlGroup.add(polygon);
const controlPointGeometry = new THREE.IcosahedronGeometry(0.27, 0);
const controlPointMaterial = new THREE.MeshStandardMaterial({
color: 0x292e2a,
roughness: 0.52,
metalness: 0.06,
flatShading: true
});
const subscriptLabels = ["P₀", "P₁", "P₂", "P₃"];
controlPoints.forEach((point, index) => {
const mesh = new THREE.Mesh(controlPointGeometry, controlPointMaterial);
mesh.position.copy(point);
mesh.castShadow = true;
mesh.receiveShadow = true;
controlGroup.add(mesh);
const label = makeLabel(subscriptLabels[index]);
label.position.copy(point).add(new THREE.Vector3(0, 0.52, 0));
controlGroup.add(label);
});
const curveLabel = makeLabel("B(t)", "#f06448");
curveLabel.position.copy(curve.getPoint(0.43)).add(new THREE.Vector3(0, 0.68, 0));
curveLabel.scale.set(0.68, 0.255, 1);
scene.add(curveLabel);
// -------------------------------------------------------------------------
// Arc-length lookup table
// -------------------------------------------------------------------------
const LUT_STEPS = 2400;
const cumulativeLengths = new Float32Array(LUT_STEPS + 1);
const lutPoints = new Array(LUT_STEPS + 1);
lutPoints[0] = curve.getPoint(0);
cumulativeLengths[0] = 0;
for (let i = 1; i <= LUT_STEPS; i++) {
const point = curve.getPoint(i / LUT_STEPS);
lutPoints[i] = point;
cumulativeLengths[i] =
cumulativeLengths[i - 1] + point.distanceTo(lutPoints[i - 1]);
}
const totalLength = cumulativeLengths[LUT_STEPS];
function tAtArcFraction(fraction) {
const distance = THREE.MathUtils.clamp(fraction, 0, 1) * totalLength;
let low = 0;
let high = LUT_STEPS;
while (low < high) {
const middle = Math.floor((low + high) / 2);
if (cumulativeLengths[middle] < distance) {
low = middle + 1;
} else {
high = middle;
}
}
const upper = Math.max(1, low);
const lower = upper - 1;
const segmentLength =
cumulativeLengths[upper] - cumulativeLengths[lower];
const alpha =
segmentLength > 0
? (distance - cumulativeLengths[lower]) / segmentLength
: 0;
return (lower + alpha) / LUT_STEPS;
}
function arcLengthAtT(t) {
if (t <= 0) return 0;
if (t >= 1) return totalLength;
const position = t * LUT_STEPS;
const lower = Math.floor(position);
const upper = Math.min(LUT_STEPS, lower + 1);
const alpha = position - lower;
return THREE.MathUtils.lerp(
cumulativeLengths[lower],
cumulativeLengths[upper],
alpha
);
}
// -------------------------------------------------------------------------
// Two marker sequences on the same curve
// -------------------------------------------------------------------------
const MARKER_COUNT = 25;
const uniformGroup = new THREE.Group();
const arcGroup = new THREE.Group();
scene.add(uniformGroup, arcGroup);
const uniformMaterial = new THREE.MeshStandardMaterial({
color: 0xf06448,
roughness: 0.48,
metalness: 0.02,
flatShading: true
});
const arcMaterial = new THREE.MeshStandardMaterial({
color: 0x079b94,
roughness: 0.4,
metalness: 0.06,
flatShading: true
});
const uniformPoints = [];
const arcPoints = [];
const uniformTimes = [];
const arcTimes = [];
const zAxis = new THREE.Vector3(0, 0, 1);
for (let i = 0; i < MARKER_COUNT; i++) {
// Uniform parameter sampling.
const uniformT = i / (MARKER_COUNT - 1);
const uniformPoint = curve.getPoint(uniformT);
uniformTimes.push(uniformT);
uniformPoints.push(uniformPoint);
const sphere = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.115, 1),
uniformMaterial
);
sphere.position.copy(uniformPoint);
sphere.castShadow = true;
uniformGroup.add(sphere);
// Approximate uniform arc-length sampling.
const arcT = tAtArcFraction(i / (MARKER_COUNT - 1));
const arcPoint = curve.getPoint(arcT);
arcTimes.push(arcT);
arcPoints.push(arcPoint);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.043, 7, 20),
arcMaterial
);
collar.position.copy(arcPoint);
const tangent = curve.getTangent(arcT).normalize();
collar.quaternion.setFromUnitVectors(zAxis, tangent);
collar.castShadow = true;
arcGroup.add(collar);
}
// Spacing measurements.
function consecutiveGaps(points) {
const gaps = [];
for (let i = 1; i < points.length; i++) {
gaps.push(points[i].distanceTo(points[i - 1]));
}
return gaps;
}
const uniformGaps = consecutiveGaps(uniformPoints);
const arcGaps = consecutiveGaps(arcPoints);
const uniformMin = Math.min(...uniformGaps);
const uniformMax = Math.max(...uniformGaps);
const arcMin = Math.min(...arcGaps);
const arcMax = Math.max(...arcGaps);
const arcAverage = arcGaps.reduce((sum, gap) => sum + gap, 0) / arcGaps.length;
document.querySelector("#uniform-range").textContent =
`${uniformMin.toFixed(2)} — ${uniformMax.toFixed(2)} units`;
document.querySelector("#arc-range").textContent =
`${arcMin.toFixed(2)} — ${arcMax.toFixed(2)} units`;
document.querySelector("#uniform-spread").textContent =
`${(uniformMax / uniformMin).toFixed(1)}× spread`;
document.querySelector("#arc-spread").textContent =
`${(((arcMax - arcMin) / arcAverage) * 100).toFixed(2)}% spread`;
// -------------------------------------------------------------------------
// Optional parameter-speed vectors
// -------------------------------------------------------------------------
const speedGroup = new THREE.Group();
speedGroup.visible = false;
scene.add(speedGroup);
const speedTimes = [0.1, 0.28, 0.5, 0.72, 0.9];
const speedValues = speedTimes.map((t) => derivativeAt(t).length());
const minSpeed = Math.min(...speedValues);
const maxSpeed = Math.max(...speedValues);
speedTimes.forEach((t, index) => {
const derivative = derivativeAt(t);
const speed = derivative.length();
const direction = derivative.clone().normalize();
const normalizedSpeed = (speed - minSpeed) / (maxSpeed - minSpeed);
const length = THREE.MathUtils.lerp(0.48, 2.15, normalizedSpeed);
const arrow = new THREE.ArrowHelper(
direction,
curve.getPoint(t),
length,
0xd49b2f,
Math.min(0.24, length * 0.22),
Math.min(0.12, length * 0.11)
);
speedGroup.add(arrow);
});
// -------------------------------------------------------------------------
// Animated sweep heads
// -------------------------------------------------------------------------
const sweepGroup = new THREE.Group();
sweepGroup.visible = false;
scene.add(sweepGroup);
const uniformHead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.185, 1),
new THREE.MeshStandardMaterial({
color: 0xf06448,
emissive: 0x6d1608,
emissiveIntensity: 0.25,
roughness: 0.35,
flatShading: true
})
);
const arcHead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.185, 1),
new THREE.MeshStandardMaterial({
color: 0x079b94,
emissive: 0x034c49,
emissiveIntensity: 0.25,
roughness: 0.35,
flatShading: true
})
);
uniformHead.castShadow = true;
arcHead.castShadow = true;
sweepGroup.add(uniformHead, arcHead);
const SWEEP_DURATION = 9;
let sweepRunning = false;
let sweepOffset = 0;
const playButton = document.querySelector("#play-button");
playButton.addEventListener("click", () => {
sweepRunning = !sweepRunning;
playButton.textContent = sweepRunning
? "Pause synchronized sweep"
: "Run synchronized sweep";
});
// -------------------------------------------------------------------------
// Layer controls
// -------------------------------------------------------------------------
document.querySelector("#uniform-toggle").addEventListener("change", (event) => {
uniformGroup.visible = event.target.checked;
});
document.querySelector("#arc-toggle").addEventListener("change", (event) => {
arcGroup.visible = event.target.checked;
});
document.querySelector("#control-toggle").addEventListener("change", (event) => {
controlGroup.visible = event.target.checked;
});
document.querySelector("#vector-toggle").addEventListener("change", (event) => {
speedGroup.visible = event.target.checked;
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// -------------------------------------------------------------------------
let dragging = false;
let moved = false;
let lastX = 0;
let lastY = 0;
let pointerStartX = 0;
let pointerStartY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
moved = false;
lastX = event.clientX;
lastY = event.clientY;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("grabbing");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (
Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
) > 4
) {
moved = true;
}
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.28, 1.47);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
canvas.classList.remove("grabbing");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!moved) {
inspectCurve(event);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.classList.remove("grabbing");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
9,
23
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
Object.assign(view, initialView);
updateCamera();
}
document.querySelector("#reset-button").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Curve inspection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const selectedMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 1),
new THREE.MeshStandardMaterial({
color: 0xfffdf7,
emissive: 0x333333,
emissiveIntensity: 0.08,
roughness: 0.4,
flatShading: true
})
);
selectedMarker.visible = false;
selectedMarker.castShadow = true;
scene.add(selectedMarker);
const inspector = document.querySelector("#inspector");
const inspectorT = document.querySelector("#inspect-t");
const inspectorS = document.querySelector("#inspect-s");
let selectedPoint = null;
function inspectCurve(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(pickMesh, false);
if (hits.length === 0) {
selectedMarker.visible = false;
selectedPoint = null;
inspector.style.display = "none";
return;
}
const hitPoint = hits[0].point;
let closestIndex = 0;
let closestDistance = Infinity;
for (let i = 0; i < lutPoints.length; i++) {
const distance = hitPoint.distanceToSquared(lutPoints[i]);
if (distance < closestDistance) {
closestDistance = distance;
closestIndex = i;
}
}
const t = closestIndex / LUT_STEPS;
const point = curve.getPoint(t);
const arcLength = arcLengthAtT(t);
selectedPoint = point.clone();
selectedMarker.position.copy(point);
selectedMarker.visible = true;
inspectorT.textContent = `t = ${t.toFixed(3)}`;
inspectorS.textContent = `s = ${arcLength.toFixed(2)} units`;
inspector.style.display = "block";
}
function updateInspectorPosition() {
if (!selectedPoint || !selectedMarker.visible) return;
const projected = selectedPoint
.clone()
.add(new THREE.Vector3(0, 0.28, 0))
.project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
inspector.style.left = `${x}px`;
inspector.style.top = `${y}px`;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > 0 &&
x < window.innerWidth &&
y > 0 &&
y < window.innerHeight;
inspector.style.visibility = visible ? "visible" : "hidden";
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
let previousTime = performance.now();
function animate(time) {
const delta = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
if (sweepRunning) {
sweepOffset = (sweepOffset + delta) % SWEEP_DURATION;
const fraction = sweepOffset / SWEEP_DURATION;
const uniformHeadPosition = curve.getPoint(fraction);
const arcHeadPosition = curve.getPoint(tAtArcFraction(fraction));
uniformHead.position.copy(uniformHeadPosition);
arcHead.position.copy(arcHeadPosition);
sweepGroup.visible =
document.querySelector("#uniform-toggle").checked ||
document.querySelector("#arc-toggle").checked;
uniformHead.visible = document.querySelector("#uniform-toggle").checked;
arcHead.visible = document.querySelector("#arc-toggle").checked;
} else {
sweepGroup.visible = false;
}
updateInspectorPosition();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
const loading = document.querySelector("#loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
</script>
</body>
</html>
```