Prompt specification
Build or customize the Three.js 3D scene "Rotation speed and induced voltage 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: Rotation speed and induced voltage comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rotation-speed-and-induced-voltage-comparison-x1638
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Place identical loops rotating at different rates in equal fields; show corresponding frequency and amplitude changes under the same ideal generator assumptions.
Working Three.js Starter (rotation-speed-and-induced-voltage-comparison-x1638):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rotational Generator Comparison</title>
<style>
:root {
--bg: #060914;
--panel: rgba(12, 20, 39, 0.84);
--panel-border: rgba(151, 213, 255, 0.16);
--text: #eef8ff;
--muted: #91a8bd;
--cyan: #67e8ff;
--violet: #c397ff;
--copper: #ff9c57;
--green: #77f0bb;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 30%, #12223c 0%, #090e1d 45%, #050711 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.hero {
position: absolute;
top: 26px;
left: 28px;
width: min(490px, calc(100vw - 56px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 11px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: linear-gradient(90deg, var(--cyan), transparent);
}
h1 {
margin: 0;
font-size: clamp(28px, 3.2vw, 47px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
h1 span {
color: var(--cyan);
}
.hero p {
max-width: 440px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.same-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(119, 240, 187, 0.22);
border-radius: 999px;
background: rgba(119, 240, 187, 0.07);
color: var(--green);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.same-badge::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
}
.assumptions {
position: absolute;
top: 24px;
right: 24px;
width: 292px;
padding: 17px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
}
.panel-title {
margin-bottom: 12px;
color: #c9eaff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.assumption-row {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 6px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.055);
color: var(--muted);
font-size: 12px;
}
.assumption-row strong {
color: var(--text);
font-size: 12px;
font-weight: 700;
}
.equation {
margin-top: 13px;
padding: 11px 12px;
border: 1px solid rgba(103, 232, 255, 0.12);
border-radius: 12px;
background: rgba(103, 232, 255, 0.045);
color: #dff8ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.8;
}
.equation .result {
color: var(--cyan);
font-weight: 700;
}
.assumptions p {
margin: 11px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.world-tag {
position: absolute;
top: 0;
left: 0;
min-width: 145px;
padding: 8px 11px;
border: 1px solid rgba(103, 232, 255, 0.23);
border-radius: 11px;
background: rgba(7, 13, 28, 0.76);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
opacity: 0;
transform-origin: center bottom;
transition: opacity 150ms ease;
backdrop-filter: blur(10px);
}
.world-tag::after {
position: absolute;
bottom: -7px;
left: 50%;
width: 12px;
height: 12px;
content: "";
border-right: 1px solid rgba(103, 232, 255, 0.23);
border-bottom: 1px solid rgba(103, 232, 255, 0.23);
background: rgba(7, 13, 28, 0.76);
transform: translateX(-50%) rotate(45deg);
}
.world-tag b {
display: block;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.13em;
}
.world-tag span {
display: block;
margin-top: 3px;
color: #d8ebf8;
font-size: 11px;
}
#tag-fast {
border-color: rgba(195, 151, 255, 0.26);
}
#tag-fast::after {
border-color: rgba(195, 151, 255, 0.26);
}
#tag-fast b {
color: var(--violet);
}
.bottom-panel {
position: absolute;
bottom: 18px;
left: 50%;
width: min(900px, calc(100vw - 32px));
padding: 14px 16px 12px;
border: 1px solid var(--panel-border);
border-radius: 20px;
background: rgba(8, 15, 31, 0.88);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
transform: translateX(-50%);
backdrop-filter: blur(18px);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.generator-card {
padding: 10px 12px;
border: 1px solid rgba(103, 232, 255, 0.13);
border-radius: 13px;
background: rgba(103, 232, 255, 0.035);
}
.generator-card.fast {
border-color: rgba(195, 151, 255, 0.15);
background: rgba(195, 151, 255, 0.035);
}
.generator-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.fast .generator-head {
color: var(--violet);
}
.rate-pill {
padding: 3px 7px;
border: 1px solid currentColor;
border-radius: 999px;
font-size: 9px;
letter-spacing: 0.08em;
opacity: 0.9;
}
.metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.metric small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
color: #f0f9ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.scope-header {
display: flex;
align-items: center;
justify-content: space-between;
margin: 11px 2px 5px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.scope-wrap {
position: relative;
height: 76px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 10px;
background:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
rgba(2, 7, 18, 0.45);
background-size: 25px 25px;
}
#scope {
display: block;
width: 100%;
height: 100%;
}
#scope path.wave {
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
vector-effect: non-scaling-stroke;
}
#slow-path {
stroke: var(--cyan);
stroke-width: 2;
filter: drop-shadow(0 0 4px rgba(103, 232, 255, 0.55));
}
#fast-path {
stroke: var(--violet);
stroke-width: 2;
filter: drop-shadow(0 0 4px rgba(195, 151, 255, 0.5));
}
.scope-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 7px;
color: #7890a5;
font-size: 8px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend {
display: flex;
gap: 14px;
}
.legend span::before {
display: inline-block;
width: 14px;
height: 2px;
margin-right: 5px;
content: "";
vertical-align: middle;
background: var(--cyan);
}
.legend span:nth-child(2)::before {
background: var(--violet);
}
.view-tools {
position: absolute;
bottom: 252px;
right: 24px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.view-tools button {
padding: 8px 11px;
border: 1px solid rgba(151, 213, 255, 0.2);
border-radius: 999px;
background: rgba(10, 18, 35, 0.78);
color: #d9efff;
font: inherit;
font-size: 10px;
cursor: pointer;
backdrop-filter: blur(12px);
}
.view-tools button:hover {
border-color: rgba(103, 232, 255, 0.55);
color: white;
}
.view-tools span {
color: #7890a5;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#fallback {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 30px;
background: #070b16;
color: white;
text-align: center;
}
[hidden] {
display: none !important;
}
@media (max-width: 920px) {
.assumptions {
display: none;
}
.hero {
top: 20px;
left: 20px;
}
.hero p {
max-width: 360px;
}
.view-tools {
right: 16px;
bottom: 245px;
}
.view-tools span {
display: none;
}
}
@media (max-width: 620px) {
.hero {
width: calc(100vw - 40px);
}
.hero p,
.same-badge {
display: none;
}
h1 {
max-width: 340px;
font-size: 29px;
}
.bottom-panel {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
.metric-grid {
gap: 6px;
}
.generator-card {
padding: 8px;
}
.metrics {
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.metric strong {
font-size: 10px;
}
.scope-wrap {
height: 66px;
}
.view-tools {
bottom: 270px;
}
.world-tag {
min-width: 125px;
padding: 6px 8px;
}
.world-tag span {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D comparison of two rotating generator loops"
></canvas>
<div class="hud">
<header class="hero">
<div class="eyebrow">Rotational Generator Lab</div>
<h1>Same field.<br /><span>Different speed.</span></h1>
<p>
Two identical copper loops rotate in equal magnetic fields. Only the
angular velocity changes, so the induced frequency and peak voltage
scale directly with rotation rate.
</p>
<div class="same-badge">N, A and B are identical</div>
</header>
<aside class="assumptions" aria-label="Ideal generator assumptions">
<div class="panel-title">Ideal generator assumptions</div>
<div class="assumption-row">
<span>Turns, N</span>
<strong>100</strong>
</div>
<div class="assumption-row">
<span>Loop area, A</span>
<strong>0.010 m²</strong>
</div>
<div class="assumption-row">
<span>Field, B</span>
<strong>0.20 T</strong>
</div>
<div class="assumption-row">
<span>Initial phase</span>
<strong>φ = 0</strong>
</div>
<div class="equation">
<div>Φ(t) = N B A cos(ωt)</div>
<div class="result">ε(t) = N B A ω sin(ωt)</div>
</div>
<p>
Open-circuit EMF. Rigid loops, uniform fields, no loading and no
additional losses. Only ω differs between the two generators.
</p>
</aside>
<div id="tag-slow" class="world-tag" aria-hidden="true">
<b>SLOWER LOOP</b>
<span>1× rate · f = 1.00 Hz</span>
</div>
<div id="tag-fast" class="world-tag" aria-hidden="true">
<b>FASTER LOOP</b>
<span>2× rate · f = 2.00 Hz</span>
</div>
<div class="view-tools">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button">Reset view</button>
</div>
<section class="bottom-panel" aria-label="Live generator readings">
<div class="metric-grid">
<article class="generator-card">
<div class="generator-head">
Slower loop
<span class="rate-pill">1× rate</span>
</div>
<div class="metrics">
<div class="metric">
<small>Angular speed</small>
<strong>6.28 rad/s</strong>
</div>
<div class="metric">
<small>Frequency</small>
<strong>1.00 Hz</strong>
</div>
<div class="metric">
<small>Peak EMF</small>
<strong>1.26 V</strong>
</div>
<div class="metric">
<small>Live EMF</small>
<strong id="slow-live">+0.00 V</strong>
</div>
</div>
</article>
<article class="generator-card fast">
<div class="generator-head">
Faster loop
<span class="rate-pill">2× rate</span>
</div>
<div class="metrics">
<div class="metric">
<small>Angular speed</small>
<strong>12.57 rad/s</strong>
</div>
<div class="metric">
<small>Frequency</small>
<strong>2.00 Hz</strong>
</div>
<div class="metric">
<small>Peak EMF</small>
<strong>2.51 V</strong>
</div>
<div class="metric">
<small>Live EMF</small>
<strong id="fast-live">+0.00 V</strong>
</div>
</div>
</article>
</div>
<div class="scope-header">
<span>Open-circuit induced EMF</span>
<span>Common vertical scale: ±3.0 V</span>
</div>
<div class="scope-wrap">
<svg
id="scope"
viewBox="0 0 800 100"
preserveAspectRatio="none"
aria-label="Live comparison of the two sinusoidal voltages"
>
<line
x1="0"
y1="50"
x2="800"
y2="50"
stroke="rgba(255,255,255,0.18)"
stroke-width="1"
vector-effect="non-scaling-stroke"
/>
<line
x1="0"
y1="16"
x2="800"
y2="16"
stroke="rgba(255,255,255,0.07)"
stroke-width="1"
vector-effect="non-scaling-stroke"
/>
<line
x1="0"
y1="84"
x2="800"
y2="84"
stroke="rgba(255,255,255,0.07)"
stroke-width="1"
vector-effect="non-scaling-stroke"
/>
<path id="slow-path" class="wave"></path>
<path id="fast-path" class="wave"></path>
</svg>
</div>
<div class="scope-footer">
<div class="legend">
<span>1× loop</span>
<span>2× loop</span>
</div>
<span id="scope-time">Live window: 2.0 s</span>
</div>
</section>
</div>
<div id="fallback" hidden>
<div>
<h2>WebGL could not be initialized.</h2>
<p>Please open this file in a browser with hardware acceleration enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Physical model
// -------------------------------------------------------------------------
const MODEL = Object.freeze({
turns: 100,
area: 0.01,
field: 0.2,
slowOmega: 2 * Math.PI,
fastOmega: 4 * Math.PI
});
const nBa = MODEL.turns * MODEL.field * MODEL.area;
const slowPeak = nBa * MODEL.slowOmega;
const fastPeak = nBa * MODEL.fastOmega;
const scopeVoltageRange = 3.0;
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
document.querySelector("#fallback").hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setClearColor(0x060914, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x060914, 16, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xb7e9ff, 0x171125, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xeaf7ff, 3.5);
keyLight.position.set(-5, 9, 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 = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanRim = new THREE.PointLight(0x38dfff, 32, 15, 2);
cyanRim.position.set(-6, 4, 3);
scene.add(cyanRim);
const violetRim = new THREE.PointLight(0xa96dff, 30, 15, 2);
violetRim.position.set(6, 4, -1);
scene.add(violetRim);
const warmRim = new THREE.PointLight(0xff8a42, 18, 10, 2);
warmRim.position.set(0, 3, 6);
scene.add(warmRim);
// -------------------------------------------------------------------------
// Shared materials
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1020,
roughness: 0.86,
metalness: 0.12
});
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x17243b,
roughness: 0.38,
metalness: 0.62
});
const pedestalTopMaterial = new THREE.MeshStandardMaterial({
color: 0x263956,
roughness: 0.28,
metalness: 0.72
});
const shaftMaterial = new THREE.MeshStandardMaterial({
color: 0xa8bfd0,
roughness: 0.2,
metalness: 0.9
});
const fieldMaterial = new THREE.MeshBasicMaterial({
color: 0x5ee7ff,
transparent: true,
opacity: 0.56,
toneMapped: false,
depthWrite: false
});
const fieldBoxMaterial = new THREE.MeshBasicMaterial({
color: 0x43d9ff,
transparent: true,
opacity: 0.022,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
});
const fieldEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x54dfff,
transparent: true,
opacity: 0.18
});
const baseRingMaterial = new THREE.MeshBasicMaterial({
color: 0x4adfff,
transparent: true,
opacity: 0.52,
toneMapped: false
});
// Floor and grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x28516d, 0x14283d);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
// Subtle atmospheric particles
const particleCount = 220;
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 23;
particlePositions[i * 3 + 1] = 0.4 + Math.random() * 8;
particlePositions[i * 3 + 2] = (Math.random() - 0.5) * 18 - 2;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x7fcfff,
size: 0.027,
transparent: true,
opacity: 0.42,
depthWrite: false,
toneMapped: false
})
);
scene.add(particles);
// -------------------------------------------------------------------------
// Small canvas-generated label texture; no external assets
// -------------------------------------------------------------------------
function makeLabelSprite(text, color = "#80eaff") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(7, 14, 29, 0.82)";
context.strokeStyle = "rgba(95, 225, 255, 0.35)";
context.lineWidth = 3;
context.beginPath();
context.moveTo(18, 18);
context.lineTo(494, 18);
context.quadraticCurveTo(506, 18, 506, 30);
context.lineTo(506, 98);
context.quadraticCurveTo(506, 110, 494, 110);
context.lineTo(18, 110);
context.quadraticCurveTo(6, 110, 6, 98);
context.lineTo(6, 30);
context.quadraticCurveTo(6, 18, 18, 18);
context.closePath();
context.fill();
context.stroke();
context.fillStyle = color;
context.font = "700 42px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(1.75, 0.44, 1);
sprite.renderOrder = 8;
return sprite;
}
// -------------------------------------------------------------------------
// Generator rig construction
// -------------------------------------------------------------------------
function createFieldArrow() {
const arrow = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 1.4, 8),
fieldMaterial
);
shaft.rotation.x = Math.PI / 2;
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.18, 12),
fieldMaterial
);
tip.rotation.x = Math.PI / 2;
tip.position.z = 0.78;
arrow.add(shaft, tip);
return arrow;
}
function createRig(xPosition) {
const group = new THREE.Group();
group.position.x = xPosition;
// Pedestal
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.22, 1.32, 0.24, 64),
pedestalMaterial
);
base.position.y = 0.12;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(0.96, 1.06, 0.09, 64),
pedestalTopMaterial
);
top.position.y = 0.275;
top.castShadow = true;
top.receiveShadow = true;
group.add(top);
const baseRing = new THREE.Mesh(
new THREE.TorusGeometry(1.1, 0.014, 8, 96),
baseRingMaterial
);
baseRing.rotation.x = Math.PI / 2;
baseRing.position.y = 0.255;
group.add(baseRing);
// Vertical rotation axis
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 2.05, 20),
shaftMaterial
);
shaft.position.y = 1.26;
shaft.castShadow = true;
group.add(shaft);
const lowerBearing = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.2, 0.18, 32),
pedestalTopMaterial
);
lowerBearing.position.y = 0.44;
lowerBearing.castShadow = true;
group.add(lowerBearing);
const upperBearing = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.13, 32),
shaftMaterial
);
upperBearing.position.y = 2.29;
upperBearing.castShadow = true;
group.add(upperBearing);
// Transparent volume representing the uniform field region
const fieldVolume = new THREE.Mesh(
new THREE.BoxGeometry(2.45, 1.92, 1.85),
fieldBoxMaterial
);
fieldVolume.position.y = 1.72;
group.add(fieldVolume);
const fieldEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(fieldVolume.geometry),
fieldEdgeMaterial
);
fieldEdges.position.copy(fieldVolume.position);
group.add(fieldEdges);
// Equal-strength field arrows, all pointing in +Z
for (const arrowX of [-0.92, 0.92]) {
for (const arrowY of [1.24, 2.22]) {
const arrow = createFieldArrow();
arrow.position.set(arrowX, arrowY, -0.76);
group.add(arrow);
}
}
const fieldLabel = makeLabelSprite("B = 0.20 T");
fieldLabel.position.set(-0.95, 2.84, 0.2);
group.add(fieldLabel);
// Rotating loop assembly
const rotor = new THREE.Group();
rotor.position.y = 1.72;
group.add(rotor);
const coilMaterial = new THREE.MeshStandardMaterial({
color: 0xff944f,
emissive: 0xff4b08,
emissiveIntensity: 0.12,
roughness: 0.24,
metalness: 0.72
});
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xffa15c,
transparent: true,
opacity: 0.045,
depthWrite: false,
toneMapped: false
});
// Two closely spaced turns suggest a compact multi-turn winding.
const outerTurn = new THREE.Mesh(
new THREE.TorusGeometry(0.77, 0.038, 12, 112),
coilMaterial
);
outerTurn.castShadow = true;
rotor.add(outerTurn);
const innerTurn = new THREE.Mesh(
new THREE.TorusGeometry(0.77, 0.024, 10, 112),
coilMaterial
);
innerTurn.position.z = 0.055;
innerTurn.castShadow = true;
rotor.add(innerTurn);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.77, 0.095, 10, 112),
haloMaterial
);
halo.position.z = 0.02;
rotor.add(halo);
// Bright phase marker on the copper loop
const phaseMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 20, 16),
new THREE.MeshStandardMaterial({
color: 0xfff4dc,
emissive: 0xffa44a,
emissiveIntensity: 0.85,
roughness: 0.2,
metalness: 0.25
})
);
phaseMarker.position.set(
Math.cos(0.72) * 0.77,
Math.sin(0.72) * 0.77,
0.08
);
phaseMarker.castShadow = true;
rotor.add(phaseMarker);
// Small slip-ring terminals
const terminalGeometry = new THREE.SphereGeometry(0.085, 16, 12);
const terminalMaterial = new THREE.MeshStandardMaterial({
color: 0xd8e5ef,
roughness: 0.2,
metalness: 0.92
});
for (const direction of [-1, 1]) {
const terminal = new THREE.Mesh(terminalGeometry, terminalMaterial);
terminal.position.set(direction * 0.77, 0, 0.07);
rotor.add(terminal);
}
scene.add(group);
return {
group,
rotor,
coilMaterial,
haloMaterial
};
}
const slowRig = createRig(-3.05);
const fastRig = createRig(3.05);
// -------------------------------------------------------------------------
// Custom camera controls, implemented directly without addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0,
pitch: 0.32,
distance: 12,
target: new THREE.Vector3(0, 1.12, 0)
};
let userAdjustedCamera = false;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const horizontalDistance =
cameraState.distance * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
horizontalDistance * Math.sin(cameraState.yaw),
cameraState.target.y +
cameraState.distance * Math.sin(cameraState.pitch),
cameraState.target.z +
horizontalDistance * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
const aspect = window.innerWidth / window.innerHeight;
cameraState.yaw = 0;
cameraState.pitch = aspect < 0.75 ? 0.39 : 0.32;
if (aspect < 0.75) {
cameraState.distance = 20;
} else if (aspect < 1.1) {
cameraState.distance = 15;
} else {
cameraState.distance = 11.7;
}
userAdjustedCamera = false;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
userAdjustedCamera = true;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
0.12,
1.08
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
userAdjustedCamera = true;
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
6.5,
27
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw += 0.09;
break;
case "ArrowRight":
cameraState.yaw -= 0.09;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - 0.06,
0.12,
1.08
);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + 0.06,
0.12,
1.08
);
break;
case "+":
case "=":
cameraState.distance = Math.max(6.5, cameraState.distance - 0.7);
break;
case "-":
cameraState.distance = Math.min(27, cameraState.distance + 0.7);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
userAdjustedCamera = true;
updateCamera();
}
});
document
.querySelector("#reset-view")
.addEventListener("click", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (!userAdjustedCamera) {
resetCamera();
}
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Scope drawing and projected HTML labels
// -------------------------------------------------------------------------
const slowPath = document.querySelector("#slow-path");
const fastPath = document.querySelector("#fast-path");
const slowLive = document.querySelector("#slow-live");
const fastLive = document.querySelector("#fast-live");
const scopeTime = document.querySelector("#scope-time");
const slowTag = document.querySelector("#tag-slow");
const fastTag = document.querySelector("#tag-fast");
const projectedPosition = new THREE.Vector3();
function makeScopePath(omega, time) {
const points = 320;
const windowDuration = 2;
const startTime = time - windowDuration * 0.5;
let path = "";
for (let i = 0; i <= points; i++) {
const fraction = i / points;
const sampleTime = startTime + fraction * windowDuration;
const voltage = nBa * omega * Math.sin(omega * sampleTime);
const x = fraction * 800;
const y = 50 - (voltage / scopeVoltageRange) * 34;
path += `${i === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)} `;
}
return path;
}
function placeWorldTag(element, rig) {
rig.group.getWorldPosition(projectedPosition);
projectedPosition.y = 3.08;
projectedPosition.project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
projectedPosition.x > -1.25 &&
projectedPosition.x < 1.25;
const x = (projectedPosition.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedPosition.y * 0.5 + 0.5) * window.innerHeight;
element.style.opacity = visible ? "1" : "0";
element.style.transform =
`translate(${x.toFixed(1)}px, ${y.toFixed(1)}px) ` +
"translate(-50%, -100%)";
}
function formatLiveVoltage(value) {
return `${value >= 0 ? "+" : ""}${value.toFixed(2)} V`;
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate() {
const elapsed = clock.getElapsedTime();
slowRig.rotor.rotation.y = MODEL.slowOmega * elapsed;
fastRig.rotor.rotation.y = MODEL.fastOmega * elapsed;
const slowVoltage =
nBa * MODEL.slowOmega * Math.sin(MODEL.slowOmega * elapsed);
const fastVoltage =
nBa * MODEL.fastOmega * Math.sin(MODEL.fastOmega * elapsed);
const slowLevel = Math.min(1, Math.abs(slowVoltage) / slowPeak);
const fastLevel = Math.min(1, Math.abs(fastVoltage) / fastPeak);
slowRig.coilMaterial.emissiveIntensity = 0.1 + slowLevel * 0.9;
fastRig.coilMaterial.emissiveIntensity = 0.1 + fastLevel * 0.9;
slowRig.haloMaterial.opacity = 0.035 + slowLevel * 0.16;
fastRig.haloMaterial.opacity = 0.035 + fastLevel * 0.16;
slowPath.setAttribute("d", makeScopePath(MODEL.slowOmega, elapsed));
fastPath.setAttribute("d", makeScopePath(MODEL.fastOmega, elapsed));
slowLive.textContent = formatLiveVoltage(slowVoltage);
fastLive.textContent = formatLiveVoltage(fastVoltage);
scopeTime.textContent = `Live window: 2.0 s · t = ${elapsed.toFixed(1)} s`;
particles.rotation.y = elapsed * 0.012;
particles.position.y = Math.sin(elapsed * 0.12) * 0.08;
placeWorldTag(slowTag, slowRig);
placeWorldTag(fastTag, fastRig);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
resetCamera();
animate();
</script>
</body>
</html>
```