Prompt specification
Build or customize the Three.js 3D scene "Peak and RMS comparison display" 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: Peak and RMS comparison display
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/peak-and-rms-comparison-display-x1602
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: peak and RMS comparison display. Place sine-wave peak markers beside a steady equivalent-heating current indicator; use the correct RMS relation for the stated sinusoid and fixed resistor.
Working Three.js Starter (peak-and-rms-comparison-display-x1602):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Peak vs RMS — Heating Equivalent</title>
<style>
:root {
color-scheme: dark;
--cyan: #56e7ff;
--amber: #ffb34d;
--text: #e9f7ff;
--muted: #83a6b7;
--panel: rgba(7, 18, 30, 0.76);
--border: rgba(93, 210, 240, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #050b13;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 26px;
left: 30px;
max-width: 430px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.75);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(29px, 3vw, 48px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.brand p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
position: absolute;
top: 26px;
right: 30px;
display: grid;
grid-template-columns: repeat(3, minmax(112px, 1fr));
gap: 8px;
padding: 8px;
border: 1px solid var(--border);
border-radius: 17px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.3),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
}
.metric {
min-width: 112px;
padding: 11px 13px;
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric strong {
color: var(--text);
font-size: 19px;
font-variant-numeric: tabular-nums;
}
.metric.peak strong {
color: var(--amber);
}
.metric.rms strong {
color: var(--cyan);
}
.legend {
position: absolute;
right: 30px;
bottom: 28px;
display: flex;
gap: 17px;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.legend i {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 7px;
border-radius: 50%;
vertical-align: -1px;
}
.legend .amber {
background: var(--amber);
box-shadow: 0 0 13px var(--amber);
}
.legend .cyan {
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
}
.help {
position: absolute;
bottom: 30px;
left: 30px;
color: rgba(159, 190, 205, 0.75);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #050b13;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.metrics {
top: auto;
right: 14px;
bottom: 48px;
grid-template-columns: repeat(3, 1fr);
gap: 3px;
padding: 5px;
}
.metric {
min-width: 0;
padding: 8px;
}
.metric strong {
font-size: 15px;
}
.metric span {
font-size: 7px;
}
.legend {
display: none;
}
.help {
bottom: 18px;
left: 18px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="ui">
<div class="brand">
<div class="eyebrow">AC power laboratory · 01</div>
<h1>Peak ≠ RMS</h1>
<p>
Equivalent steady current for the same average heating in a fixed
resistive load.
</p>
</div>
<div class="metrics">
<div class="metric peak">
<span>Sinusoid peak</span>
<strong>10.00 A</strong>
</div>
<div class="metric rms">
<span>Heating-equivalent</span>
<strong>7.07 A</strong>
</div>
<div class="metric">
<span>Average power</span>
<strong>500 W</strong>
</div>
</div>
<div class="legend">
<span><i class="amber"></i>Instantaneous peak</span>
<span><i class="cyan"></i>Steady heating current</span>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div id="loading">Initializing power comparison</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------------
// Stated electrical quantities
//
// i(t) = I_PEAK sin(omega t) A
// R = 10 ohm, purely resistive
//
// For a sinusoid:
// I_RMS = I_PEAK / sqrt(2)
//
// A steady DC current with the same heating must satisfy:
// I_EQ^2 R = I_RMS^2 R
// therefore I_EQ = I_RMS.
// ------------------------------------------------------------------
const I_PEAK = 10;
const R_OHMS = 10;
const I_RMS = I_PEAK / Math.SQRT2;
const P_AVG = I_RMS * I_RMS * R_OHMS;
const P_PEAK = I_PEAK * I_PEAK * R_OHMS;
const COLORS = {
cyan: 0x56e7ff,
cyanDark: 0x138ea8,
amber: 0xffb34d,
amberDark: 0xa85b16,
screen: 0x06131f,
board: 0x0d1926,
grid: 0x174456,
axis: 0x3c8299,
white: 0xeafaff
};
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive Three.js comparison of sinusoidal peak current and RMS heating-equivalent current"
);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050b13);
scene.fog = new THREE.Fog(0x050b13, 24, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const world = new THREE.Group();
scene.add(world);
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x91d9ff, 0x091019, 1.35));
const keyLight = new THREE.DirectionalLight(0xc9efff, 2.6);
keyLight.position.set(-4, 9, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(COLORS.cyan, 28, 13, 2);
cyanLight.position.set(5, 2.5, 5);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(COLORS.amber, 24, 12, 2);
amberLight.position.set(-5, 1.5, 4);
scene.add(amberLight);
// ------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(text, options = {}) {
const fontSize = options.fontSize ?? 30;
const font = `750 ${fontSize}px Inter, ui-sans-serif, system-ui, sans-serif`;
const padding = options.padding ?? 24;
const measureCanvas = document.createElement("canvas");
const measureContext = measureCanvas.getContext("2d");
measureContext.font = font;
const measuredWidth = measureContext.measureText(text).width;
const canvas = document.createElement("canvas");
canvas.width = Math.ceil(measuredWidth + padding * 2);
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(
ctx,
1,
1,
canvas.width - 2,
canvas.height - 2,
options.radius ?? 15
);
ctx.fillStyle = options.fill ?? "rgba(7, 18, 30, 0.88)";
ctx.fill();
if (options.stroke) {
ctx.lineWidth = options.strokeWidth ?? 2;
ctx.strokeStyle = options.stroke;
ctx.stroke();
}
ctx.font = font;
ctx.textBaseline = "middle";
ctx.textAlign = "left";
ctx.fillStyle = options.color ?? "#eafaff";
ctx.fillText(text, padding, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
fog: false
});
const sprite = new THREE.Sprite(material);
const height = options.height ?? 0.38;
let width = height * (canvas.width / canvas.height);
if (options.maxWidth && width > options.maxWidth) {
width = options.maxWidth;
sprite.scale.set(width, width * canvas.height / canvas.width, 1);
} else {
sprite.scale.set(width, height, 1);
}
sprite.position.set(
options.x ?? 0,
options.y ?? 0,
options.z ?? 0.5
);
sprite.renderOrder = 20;
return sprite;
}
function makeLine(points, color, opacity = 1, z = 0) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(p[0], p[1], p[2] ?? z))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
return new THREE.Line(geometry, material);
}
function makeRectangle(width, height, z, color, opacity = 1) {
return makeLine(
[
[-width / 2, -height / 2, z],
[ width / 2, -height / 2, z],
[ width / 2, height / 2, z],
[-width / 2, height / 2, z],
[-width / 2, -height / 2, z]
],
color,
opacity
);
}
function makeBoard(width, height) {
const group = new THREE.Group();
const shell = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.36),
new THREE.MeshStandardMaterial({
color: COLORS.board,
roughness: 0.42,
metalness: 0.48
})
);
shell.castShadow = true;
shell.receiveShadow = true;
group.add(shell);
const screen = new THREE.Mesh(
new THREE.PlaneGeometry(width - 0.52, height - 0.52),
new THREE.MeshBasicMaterial({ color: COLORS.screen })
);
screen.position.z = 0.191;
group.add(screen);
const outline = makeRectangle(
width - 0.30,
height - 0.30,
0.205,
COLORS.cyanDark,
0.42
);
group.add(outline);
return group;
}
function makeGlowArrow(x, endY, color) {
const group = new THREE.Group();
group.position.x = x;
const shaftLength = Math.max(0.04, endY - 0.2);
const shaftGeometry = new THREE.CylinderGeometry(0.034, 0.034, shaftLength, 16);
const glowShaft = new THREE.Mesh(
shaftGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
glowShaft.position.y = shaftLength / 2;
const shaft = new THREE.Mesh(
shaftGeometry,
new THREE.MeshBasicMaterial({ color })
);
shaft.position.y = shaftLength / 2;
const coneGeometry = new THREE.ConeGeometry(0.16, 0.25, 24);
const glowCone = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
glowCone.position.y = endY - 0.125;
const cone = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({ color })
);
cone.position.y = endY - 0.125;
group.add(glowShaft, glowCone, shaft, cone);
return group;
}
function makeDoubleArrow(x, amplitude, color) {
const group = new THREE.Group();
group.position.x = x;
const shaftLength = amplitude * 2 - 0.27;
const shaftGeometry = new THREE.CylinderGeometry(
0.034,
0.034,
shaftLength,
16
);
const glowShaft = new THREE.Mesh(
shaftGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
const shaft = new THREE.Mesh(
shaftGeometry,
new THREE.MeshBasicMaterial({ color })
);
const coneGeometry = new THREE.ConeGeometry(0.16, 0.25, 24);
const topCone = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({ color })
);
topCone.position.y = amplitude - 0.125;
const bottomCone = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({ color })
);
bottomCone.position.y = -amplitude + 0.125;
bottomCone.rotation.z = Math.PI;
const glowTop = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
glowTop.position.copy(topCone.position);
const glowBottom = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
glowBottom.position.copy(bottomCone.position);
glowBottom.rotation.z = Math.PI;
group.add(
glowShaft,
glowTop,
glowBottom,
shaft,
topCone,
bottomCone
);
return group;
}
function makePedestal(x) {
const base = new THREE.Mesh(
new THREE.BoxGeometry(2.7, 0.14, 1.35),
new THREE.MeshStandardMaterial({
color: 0x0c1722,
roughness: 0.48,
metalness: 0.58
})
);
base.position.set(x, -2.57, 0);
base.castShadow = true;
base.receiveShadow = true;
world.add(base);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.45, 0.28),
new THREE.MeshStandardMaterial({
color: 0x173040,
roughness: 0.4,
metalness: 0.6
})
);
stem.position.set(x, -2.29, 0);
stem.castShadow = true;
world.add(stem);
}
// ------------------------------------------------------------------
// Floor and ambient set dressing
// ------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 45),
new THREE.MeshStandardMaterial({
color: 0x071018,
roughness: 0.86,
metalness: 0.18
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.66;
floor.receiveShadow = true;
world.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x1b5263, 0x0b2531);
grid.position.y = -2.645;
grid.material.transparent = true;
grid.material.opacity = 0.28;
world.add(grid);
const halo1 = new THREE.Mesh(
new THREE.RingGeometry(7.65, 7.67, 128),
new THREE.MeshBasicMaterial({
color: COLORS.cyanDark,
transparent: true,
opacity: 0.23,
side: THREE.DoubleSide,
depthWrite: false
})
);
halo1.position.set(0, 0.15, -1.5);
world.add(halo1);
const halo2 = new THREE.Mesh(
new THREE.RingGeometry(8.45, 8.46, 128),
new THREE.MeshBasicMaterial({
color: COLORS.cyanDark,
transparent: true,
opacity: 0.10,
side: THREE.DoubleSide,
depthWrite: false
})
);
halo2.position.set(0, 0.15, -1.6);
world.add(halo2);
const particlePositions = new Float32Array(95 * 3);
for (let i = 0; i < 95; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 21;
particlePositions[i * 3 + 1] = Math.random() * 8 - 1;
particlePositions[i * 3 + 2] = Math.random() * -8 + 1;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x6fcde0,
size: 0.027,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
world.add(particles);
// ------------------------------------------------------------------
// Left panel: sinusoidal current waveform and actual peak markers
// ------------------------------------------------------------------
const scope = new THREE.Group();
scope.position.set(-3.45, 0.25, 0);
world.add(scope);
scope.add(makeBoard(6.8, 4.9));
const scopeGridPoints = [];
for (let x = -2.95; x <= 2.96; x += 0.59) {
scopeGridPoints.push(
new THREE.Vector3(x, -1.95, 0.207),
new THREE.Vector3(x, 1.95, 0.207)
);
}
for (let y = -1.95; y <= 1.96; y += 0.39) {
scopeGridPoints.push(
new THREE.Vector3(-2.95, y, 0.207),
new THREE.Vector3(2.95, y, 0.207)
);
}
const scopeGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(scopeGridPoints),
new THREE.LineBasicMaterial({
color: COLORS.grid,
transparent: true,
opacity: 0.34
})
);
scope.add(scopeGrid);
scope.add(
makeLine(
[[-3.0, 0, 0.216], [3.0, 0, 0.216]],
COLORS.axis,
0.52
)
);
const waveStartX = -2.86;
const waveEndX = 2.86;
const waveAmplitude = 1.28;
const wavePoints = [];
for (let i = 0; i <= 180; i++) {
const phase = (i / 180) * Math.PI * 2;
wavePoints.push(
new THREE.Vector3(
THREE.MathUtils.lerp(waveStartX, waveEndX, i / 180),
Math.sin(phase) * waveAmplitude,
0.275
)
);
}
const waveCurve = new THREE.CatmullRomCurve3(
wavePoints,
false,
"centripetal"
);
const waveGlow = new THREE.Mesh(
new THREE.TubeGeometry(waveCurve, 240, 0.13, 8, false),
new THREE.MeshBasicMaterial({
color: COLORS.amber,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
scope.add(waveGlow);
const wave = new THREE.Mesh(
new THREE.TubeGeometry(waveCurve, 240, 0.052, 8, false),
new THREE.MeshBasicMaterial({ color: COLORS.amber })
);
scope.add(wave);
const positivePeakX = waveStartX + (waveEndX - waveStartX) * 0.25;
const negativePeakX = waveStartX + (waveEndX - waveStartX) * 0.75;
function addPeakMarker(x, y, label, labelX, labelY) {
const dashed = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0, 0.25),
new THREE.Vector3(x, y, 0.25)
]),
new THREE.LineDashedMaterial({
color: COLORS.amber,
dashSize: 0.11,
gapSize: 0.075,
transparent: true,
opacity: 0.72
})
);
dashed.computeLineDistances();
scope.add(dashed);
const point = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 20, 12),
new THREE.MeshBasicMaterial({ color: COLORS.white })
);
point.position.set(x, y, 0.34);
scope.add(point);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.022, 8, 32),
new THREE.MeshBasicMaterial({ color: COLORS.amber })
);
ring.position.set(x, y, 0.35);
scope.add(ring);
scope.add(
makeLabel(label, {
x: labelX,
y: labelY,
z: 0.48,
height: 0.33,
color: "#ffd494",
stroke: "rgba(255,179,77,0.42)",
fill: "rgba(48,27,8,0.91)"
})
);
}
addPeakMarker(
positivePeakX,
waveAmplitude,
"+10.00 A PEAK",
positivePeakX - 0.08,
waveAmplitude + 0.31
);
addPeakMarker(
negativePeakX,
-waveAmplitude,
"−10.00 A PEAK",
negativePeakX + 0.05,
-waveAmplitude - 0.31
);
scope.add(
makeLabel("AC CURRENT / RESISTIVE", {
x: 0,
y: 2.13,
z: 0.48,
height: 0.43,
color: "#dff9ff",
stroke: "rgba(86,231,255,0.25)"
})
);
scope.add(
makeLabel("i(t) = 10 sin(ωt) A", {
x: 0,
y: 1.77,
z: 0.48,
height: 0.34,
color: "#83eaff",
fill: "rgba(6,27,38,0.88)"
})
);
scope.add(
makeLabel("R = 10 Ω · FIXED LOAD", {
x: -1.68,
y: -1.91,
z: 0.48,
height: 0.31,
color: "#a8c4d1",
fill: "rgba(7,18,30,0.88)"
})
);
scope.add(
makeLabel(`PEAK POWER ${P_PEAK.toFixed(0)} W`, {
x: 1.61,
y: -1.91,
z: 0.48,
height: 0.31,
color: "#ffd08c",
fill: "rgba(39,25,10,0.88)"
})
);
const scanDot = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 16, 12),
new THREE.MeshBasicMaterial({ color: COLORS.white })
);
scope.add(scanDot);
const scanLight = new THREE.PointLight(COLORS.amber, 0.45, 1.8, 2);
scope.add(scanLight);
// ------------------------------------------------------------------
// Right panel: peak marker beside steady equivalent-heating current
// ------------------------------------------------------------------
const comparison = new THREE.Group();
comparison.position.set(3.65, 0.25, 0);
world.add(comparison);
comparison.add(makeBoard(5.2, 4.9));
const compareScale = 0.14; // world units per ampere
const peakY = I_PEAK * compareScale;
const rmsY = I_RMS * compareScale;
comparison.add(
makeLine(
[[-1.92, 0, 0.22], [1.92, 0, 0.22]],
COLORS.axis,
0.54
)
);
const rmsGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0.30, rmsY, 0.235),
new THREE.Vector3(1.64, rmsY, 0.235)
]),
new THREE.LineDashedMaterial({
color: COLORS.cyan,
dashSize: 0.10,
gapSize: 0.07,
transparent: true,
opacity: 0.68
})
);
rmsGuide.computeLineDistances();
comparison.add(rmsGuide);
const rmsTick = makeLine(
[[1.52, rmsY - 0.08, 0.25], [1.52, rmsY + 0.08, 0.25]],
COLORS.cyan,
0.95
);
comparison.add(rmsTick);
comparison.add(
makeDoubleArrow(-0.82, peakY, COLORS.amber)
);
comparison.add(
makeGlowArrow(0.72, rmsY, COLORS.cyan)
);
comparison.add(
makeLabel("HEATING COMPARISON", {
x: 0,
y: 2.13,
z: 0.48,
height: 0.43,
color: "#dff9ff",
stroke: "rgba(86,231,255,0.25)"
})
);
comparison.add(
makeLabel("I_RMS = I_PEAK / √2", {
x: 0,
y: 1.76,
z: 0.48,
height: 0.36,
color: "#8eeeff",
fill: "rgba(6,29,40,0.9)"
})
);
comparison.add(
makeLabel("PEAK ±10.00 A", {
x: -0.88,
y: 1.48,
z: 0.50,
height: 0.33,
color: "#ffd494",
stroke: "rgba(255,179,77,0.42)",
fill: "rgba(48,27,8,0.92)"
})
);
comparison.add(
makeLabel("STEADY HEATING-EQ 7.07 A", {
x: 0.72,
y: 1.18,
z: 0.50,
height: 0.32,
color: "#9af2ff",
stroke: "rgba(86,231,255,0.42)",
fill: "rgba(5,31,43,0.92)"
})
);
comparison.add(
makeLabel("SAME AVERAGE HEAT", {
x: 0,
y: -1.51,
z: 0.48,
height: 0.34,
color: "#c4e9f3",
fill: "rgba(7,18,30,0.88)"
})
);
comparison.add(
makeLabel(`P = I_RMS²R = ${P_AVG.toFixed(0)} W`, {
x: 0,
y: -1.93,
z: 0.48,
height: 0.34,
color: "#8eeeff",
fill: "rgba(5,28,39,0.9)"
})
);
makePedestal(-3.45);
makePedestal(3.65);
// ------------------------------------------------------------------
// Camera controls implemented directly without addons
// ------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, -0.05, 0),
radius: 16.4,
theta: 0.13,
phi: 1.25,
dragging: false,
lastX: 0,
lastY: 0,
userZoomed: false
};
function applyCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.theta = 0.13;
controls.phi = 1.25;
controls.userZoomed = false;
controls.radius = fittedRadius();
applyCamera();
}
function fittedRadius() {
// Maintain visibility of the complete comparison on narrow screens.
return Math.max(16.4, 18.8 / camera.aspect);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.72,
1.48
);
applyCamera();
});
function endDrag(event) {
controls.dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
11,
42
);
controls.userZoomed = true;
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
controls.theta += step;
} else if (event.key === "ArrowRight") {
controls.theta -= step;
} else if (event.key === "ArrowUp") {
controls.phi = Math.max(0.72, controls.phi - step);
} else if (event.key === "ArrowDown") {
controls.phi = Math.min(1.48, controls.phi + step);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(11, controls.radius - 1);
controls.userZoomed = true;
} else if (event.key === "-") {
controls.radius = Math.min(42, controls.radius + 1);
controls.userZoomed = true;
} else {
return;
}
applyCamera();
});
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(
window.innerWidth,
window.innerHeight,
false
);
if (!controls.userZoomed) {
controls.radius = fittedRadius();
}
applyCamera();
}
window.addEventListener("resize", onResize);
controls.radius = fittedRadius();
applyCamera();
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const phase = (elapsed * 0.115) % 1;
const angle = phase * Math.PI * 2;
scanDot.position.set(
THREE.MathUtils.lerp(waveStartX, waveEndX, phase),
Math.sin(angle) * waveAmplitude,
0.37
);
scanLight.position.copy(scanDot.position);
waveGlow.material.opacity = 0.115 + Math.sin(elapsed * 2.2) * 0.025;
halo1.rotation.z = elapsed * 0.012;
halo2.rotation.z = -elapsed * 0.008;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```