Prompt specification
Build or customize the Three.js 3D scene "Flux-versus-time induction explorer" 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: Flux-versus-time induction explorer
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/flux-versus-time-induction-explorer-x1636
Scene Description Prompt:
Explore synthetic magnetic flux and its negative time derivative, induced voltage, in a low-poly exhibit. One HTML file using Three.js from cdnjs.
Working Three.js Starter (flux-versus-time-induction-explorer-x1636):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Faraday Flux Lab — Synthetic Low-Poly Exhibit</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(9, 20, 29, 0.84);
--line: rgba(165, 207, 225, 0.16);
--text: #e7f3f7;
--muted: #8fa8b4;
--flux: #ffb45e;
--flux-negative: #63bdff;
--voltage: #50efd0;
--voltage-negative: #ff609c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #172b38 0, #09141d 48%, #050b11 100%);
color: var(--text);
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%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at center, transparent 42%, rgba(2, 7, 11, 0.36) 100%),
linear-gradient(180deg, rgba(3, 9, 14, 0.25), transparent 30%, transparent 72%, rgba(3, 9, 14, 0.38));
}
header {
position: fixed;
top: 22px;
left: 24px;
z-index: 3;
pointer-events: none;
}
.eyebrow {
color: var(--flux);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: clamp(22px, 2.3vw, 36px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 750;
}
header p {
margin: 0;
max-width: 430px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#readout {
top: 24px;
right: 24px;
width: 300px;
padding: 17px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--voltage);
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
content: "";
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric {
min-width: 0;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric:first-child {
grid-column: 1 / -1;
}
.metric-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.metric strong {
display: inline-block;
font: 650 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.055em;
}
.metric small {
display: block;
margin-top: 6px;
color: #728d9b;
font-size: 9px;
letter-spacing: 0.04em;
}
.flux-color {
color: var(--flux);
}
.emf-color {
color: var(--voltage);
}
.states {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
color: var(--muted);
font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.states span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#fluxState {
color: var(--flux);
}
#emfState {
color: var(--voltage);
}
.equation {
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #b7cbd3;
font: 11px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.equation b {
color: #eaf6fa;
font-weight: 600;
}
.equation .note {
display: block;
margin-top: 5px;
color: #708a97;
font-size: 9px;
line-height: 1.45;
}
#controls {
bottom: 24px;
left: 24px;
width: 326px;
padding: 17px;
}
.control-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 5px 12px;
align-items: center;
margin-top: 14px;
}
.control-row label {
color: #c2d3da;
font-size: 11px;
font-weight: 600;
}
output {
color: var(--flux);
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 3px 0 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(90deg, #315266, #162a36);
accent-color: var(--flux);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #08141c;
border-radius: 50%;
background: var(--flux);
box-shadow: 0 0 0 1px rgba(255, 180, 94, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #08141c;
border-radius: 50%;
background: var(--flux);
}
.button-row {
display: flex;
gap: 8px;
margin-top: 17px;
}
button {
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #dceaf0;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
button:hover {
border-color: rgba(255, 180, 94, 0.38);
background: rgba(255, 180, 94, 0.09);
}
button:active {
transform: translateY(1px);
}
#playBtn {
flex: 1;
border-color: rgba(80, 239, 208, 0.26);
background: rgba(80, 239, 208, 0.09);
color: var(--voltage);
}
.toggles {
display: flex;
flex-wrap: wrap;
gap: 10px 16px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
color: #a8bec8;
font-size: 10px;
cursor: pointer;
}
.toggle input {
width: 14px;
height: 14px;
margin: 0;
accent-color: var(--voltage);
}
#graphPanel {
right: 24px;
bottom: 24px;
width: min(440px, calc(100vw - 410px));
padding: 15px 16px 12px;
}
#scope {
display: block;
width: 100%;
height: 150px;
cursor: crosshair;
}
.legend {
display: flex;
align-items: center;
gap: 15px;
margin-top: 7px;
color: #829ca9;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 13px;
height: 2px;
background: currentColor;
}
.legend .flux {
color: var(--flux);
}
.legend .emf {
color: var(--voltage);
}
.legend .scrub {
margin-left: auto;
color: #718a97;
}
.hint {
position: fixed;
left: 50%;
bottom: 25px;
z-index: 2;
transform: translateX(-50%);
color: rgba(185, 207, 216, 0.48);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
pointer-events: none;
text-transform: uppercase;
}
@media (max-width: 1000px) {
#readout {
width: 270px;
}
#controls {
width: 290px;
}
#graphPanel {
width: 350px;
}
.hint {
display: none;
}
}
@media (max-width: 720px) {
header {
top: 15px;
left: 14px;
}
header p {
display: none;
}
#readout {
top: 72px;
right: 12px;
left: 12px;
width: auto;
padding: 12px;
}
.panel-title,
.equation,
.states {
display: none;
}
.metrics {
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.metric,
.metric:first-child {
grid-column: auto;
padding: 9px;
}
.metric strong {
font-size: 18px;
}
#controls {
bottom: 12px;
left: 12px;
width: 250px;
max-height: 42vh;
overflow: auto;
padding: 13px;
}
#graphPanel {
right: 12px;
bottom: 12px;
width: calc(100vw - 286px);
min-width: 220px;
padding: 11px;
}
#scope {
height: 110px;
}
.legend .scrub {
display: none;
}
}
@media (max-width: 520px) {
#graphPanel {
display: none;
}
#controls {
right: 12px;
width: auto;
max-height: 48vh;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive three-dimensional magnetic flux exhibit"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">Synthetic exhibit / Faraday 01</div>
<h1>Flux → induced voltage</h1>
<p>Explore a synthetic linked-flux signal and its negative time derivative.</p>
</header>
<section id="readout" class="panel" aria-label="Live signal readout">
<div class="panel-title">
<span>Live signal</span>
<span class="live" id="clock">0.00 s</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">LINKED FLUX Φ(t)</span>
<strong id="fluxValue" class="flux-color">+0.00</strong>
<small>mWb-turn</small>
</div>
<div class="metric">
<span class="metric-label">dΦ/dt</span>
<strong id="dFluxValue" class="flux-color">+0.00</strong>
<small>mWb-turn / s</small>
</div>
<div class="metric">
<span class="metric-label">ε = −dΦ/dt</span>
<strong id="emfValue" class="emf-color">+0.00</strong>
<small>millivolts</small>
</div>
</div>
<div class="states">
<span id="fluxState">ZERO FLUX</span>
<span id="emfState">ZERO VOLTAGE</span>
</div>
<div class="equation">
<div><b>Φ(t)</b> = Φ₀ sin(ωt + φ)</div>
<div><b>ε(t)</b> = −dΦ/dt = −Φ₀ω cos(ωt + φ)</div>
<span class="note">
Φ denotes linked flux: Φ = NΦₜᵤᵣₙ. The cyan circulation arrows
indicate the instantaneous sign of the induced voltage.
</span>
</div>
</section>
<section id="controls" class="panel" aria-label="Signal controls">
<div class="panel-title">
<span>Signal controls</span>
<span id="freqOut">0.65 Hz</span>
</div>
<div class="control-row">
<label for="ampSlider">Flux amplitude Φ₀</label>
<output id="ampOut">2.4 mWb-turn</output>
<input id="ampSlider" type="range" min="0.4" max="4" step="0.1" value="2.4">
</div>
<div class="control-row">
<label for="freqSlider">Rotation frequency</label>
<output id="freqOutText">0.65 Hz</output>
<input id="freqSlider" type="range" min="0.1" max="2" step="0.05" value="0.65">
</div>
<div class="control-row">
<label for="phaseSlider">Starting phase φ</label>
<output id="phaseOut">0°</output>
<input id="phaseSlider" type="range" min="0" max="360" step="1" value="0">
</div>
<div class="button-row">
<button id="playBtn" type="button">Pause signal</button>
<button id="resetSignal" type="button">Reset</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="toggles">
<label class="toggle">
<input id="fieldToggle" type="checkbox" checked>
Magnetic field
</label>
<label class="toggle">
<input id="arrowsToggle" type="checkbox" checked>
Voltage circulation
</label>
</div>
</section>
<section id="graphPanel" class="panel" aria-label="Flux and voltage oscilloscope">
<div class="panel-title">
<span>Rolling scope</span>
<span id="scopeScale">independent scales</span>
</div>
<canvas id="scope" aria-label="Flux and induced voltage graph"></canvas>
<div class="legend">
<span class="flux"><i></i>Φ(t)</span>
<span class="emf"><i></i>−dΦ/dt</span>
<span class="scrub">click to scrub</span>
</div>
</section>
<div class="hint">Drag to orbit · scroll to zoom · space to pause</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TAU = Math.PI * 2;
const stage = document.querySelector("#stage");
const scope = document.querySelector("#scope");
const scopeContext = scope.getContext("2d");
const settings = {
amplitude: 2.4,
frequency: 0.65,
phase: 0,
running: true,
showField: true,
showArrows: true
};
const elements = {
playBtn: document.querySelector("#playBtn"),
resetSignal: document.querySelector("#resetSignal"),
resetView: document.querySelector("#resetView"),
fieldToggle: document.querySelector("#fieldToggle"),
arrowsToggle: document.querySelector("#arrowsToggle"),
ampSlider: document.querySelector("#ampSlider"),
freqSlider: document.querySelector("#freqSlider"),
phaseSlider: document.querySelector("#phaseSlider"),
ampOut: document.querySelector("#ampOut"),
freqOut: document.querySelector("#freqOut"),
freqOutText: document.querySelector("#freqOutText"),
phaseOut: document.querySelector("#phaseOut"),
fluxValue: document.querySelector("#fluxValue"),
dFluxValue: document.querySelector("#dFluxValue"),
emfValue: document.querySelector("#emfValue"),
fluxState: document.querySelector("#fluxState"),
emfState: document.querySelector("#emfState"),
clock: document.querySelector("#clock"),
scopeScale: document.querySelector("#scopeScale")
};
let simulationTime = 0;
// -------------------------------------------------------------------------
// Renderer and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.038);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const cameraTarget = new THREE.Vector3(0, -0.12, 0);
const defaultCamera = {
theta: 0.78,
phi: 1.02,
radius: 7.5
};
const cameraOrbit = { ...defaultCamera };
function updateCamera() {
const sinPhi = Math.sin(cameraOrbit.phi);
camera.position.set(
cameraTarget.x + cameraOrbit.radius * sinPhi * Math.sin(cameraOrbit.theta),
cameraTarget.y + cameraOrbit.radius * Math.cos(cameraOrbit.phi),
cameraTarget.z + cameraOrbit.radius * sinPhi * Math.cos(cameraOrbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Direct camera controls; no examples or addons are imported.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
cameraOrbit.theta -= deltaX * 0.006;
cameraOrbit.phi = THREE.MathUtils.clamp(
cameraOrbit.phi + deltaY * 0.005,
0.48,
1.38
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraOrbit.radius = THREE.MathUtils.clamp(
cameraOrbit.radius + event.deltaY * 0.006,
4.7,
10.5
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa8dcff, 0x17101b, 1.7));
const keyLight = new THREE.DirectionalLight(0xfff0da, 3.2);
keyLight.position.set(4.5, 7, 4);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x55dfff, 24, 10, 2);
cyanLight.position.set(-3.5, 3.2, 2.5);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xff9a4f, 18, 8, 2);
orangeLight.position.set(3.8, 1.8, -2.5);
scene.add(orangeLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x182832,
roughness: 0.73,
metalness: 0.24,
flatShading: true
});
const pedestalTopMaterial = new THREE.MeshStandardMaterial({
color: 0x213945,
roughness: 0.58,
metalness: 0.36,
flatShading: true
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x536d78,
roughness: 0.36,
metalness: 0.74,
flatShading: true
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x101b22,
roughness: 0.42,
metalness: 0.72,
flatShading: true
});
const northMaterial = new THREE.MeshStandardMaterial({
color: 0xe65a48,
emissive: 0x48100a,
emissiveIntensity: 0.45,
roughness: 0.44,
metalness: 0.18,
flatShading: true
});
const southMaterial = new THREE.MeshStandardMaterial({
color: 0x3c87d8,
emissive: 0x09284a,
emissiveIntensity: 0.45,
roughness: 0.44,
metalness: 0.18,
flatShading: true
});
const coilMaterial = new THREE.MeshStandardMaterial({
color: 0xe78a46,
emissive: 0x073d36,
emissiveIntensity: 0.25,
roughness: 0.25,
metalness: 0.72,
flatShading: true
});
const coilGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x50efd0,
transparent: true,
opacity: 0.08,
depthWrite: false
});
const fluxPositiveMaterial = new THREE.MeshBasicMaterial({
color: 0xffb45e,
transparent: true,
opacity: 0.9
});
const fluxNegativeMaterial = new THREE.MeshBasicMaterial({
color: 0x63bdff,
transparent: true,
opacity: 0.9
});
const voltagePositiveMaterial = new THREE.MeshBasicMaterial({
color: 0x50efd0,
transparent: true,
opacity: 0.9
});
const voltageNegativeMaterial = new THREE.MeshBasicMaterial({
color: 0xff609c,
transparent: true,
opacity: 0.9
});
// -------------------------------------------------------------------------
// Pedestal and exhibit frame
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CircleGeometry(18, 32),
new THREE.MeshStandardMaterial({
color: 0x08131b,
roughness: 0.96,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.34;
ground.receiveShadow = true;
scene.add(ground);
const pedestalBase = new THREE.Mesh(
new THREE.CylinderGeometry(3.04, 3.25, 0.34, 12),
pedestalMaterial
);
pedestalBase.position.y = -1.16;
pedestalBase.receiveShadow = true;
pedestalBase.castShadow = true;
scene.add(pedestalBase);
const pedestalTop = new THREE.Mesh(
new THREE.CylinderGeometry(2.9, 3.04, 0.11, 12),
pedestalTopMaterial
);
pedestalTop.position.y = -0.94;
pedestalTop.receiveShadow = true;
scene.add(pedestalTop);
const pedestalRim = new THREE.Mesh(
new THREE.TorusGeometry(3.05, 0.045, 4, 48),
new THREE.MeshStandardMaterial({
color: 0x6a8792,
roughness: 0.35,
metalness: 0.75
})
);
pedestalRim.rotation.x = Math.PI / 2;
pedestalRim.position.y = -0.98;
scene.add(pedestalRim);
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.75 + i * 0.48, 0.009, 3, 64),
new THREE.MeshBasicMaterial({
color: 0x537886,
transparent: true,
opacity: 0.22
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.875;
scene.add(ring);
}
const tickGeometry = new THREE.BoxGeometry(0.04, 0.025, 0.19);
const tickMaterial = new THREE.MeshBasicMaterial({ color: 0x7a9aa5 });
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * TAU;
const tick = new THREE.Mesh(tickGeometry, tickMaterial);
tick.position.set(
Math.cos(angle) * 2.73,
-0.86,
Math.sin(angle) * 2.73
);
tick.rotation.y = -angle;
scene.add(tick);
}
const supportGeometry = new THREE.BoxGeometry(0.075, 1.48, 0.075);
for (const x of [-1.48, 1.48]) {
for (const z of [-1.48, 1.48]) {
const post = new THREE.Mesh(supportGeometry, frameMaterial);
post.position.set(x, -0.12, z);
post.castShadow = true;
scene.add(post);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.16, 0.06, 8),
darkMetalMaterial
);
foot.position.set(x, -0.82, z);
scene.add(foot);
}
}
// -------------------------------------------------------------------------
// Low-poly helical coil
// -------------------------------------------------------------------------
class HelixCurve extends THREE.Curve {
constructor(turns, radius, height) {
super();
this.turns = turns;
this.radius = radius;
this.height = height;
}
getPoint(t, target = new THREE.Vector3()) {
const angle = t * this.turns * TAU;
return target.set(
Math.cos(angle) * this.radius,
-this.height / 2 + t * this.height,
Math.sin(angle) * this.radius
);
}
}
const helix = new HelixCurve(6, 1.25, 0.86);
const coilGeometry = new THREE.TubeGeometry(helix, 132, 0.038, 5, false);
const coil = new THREE.Mesh(coilGeometry, coilMaterial);
coil.castShadow = true;
scene.add(coil);
const coilGlow = new THREE.Mesh(
new THREE.TubeGeometry(helix, 132, 0.073, 4, false),
coilGlowMaterial
);
scene.add(coilGlow);
const leadCurveA = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.25, -0.43, 0),
new THREE.Vector3(1.48, -0.43, 0),
new THREE.Vector3(1.55, -0.68, 0)
]);
const leadCurveB = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.25, 0.43, 0),
new THREE.Vector3(1.48, 0.43, 0),
new THREE.Vector3(1.55, 0.68, 0)
]);
for (const curve of [leadCurveA, leadCurveB]) {
const lead = new THREE.Mesh(
new THREE.TubeGeometry(curve, 18, 0.04, 5, false),
coilMaterial
);
scene.add(lead);
}
const terminalGeometry = new THREE.CylinderGeometry(0.09, 0.09, 0.18, 8);
const terminalA = new THREE.Mesh(terminalGeometry, coilMaterial);
terminalA.position.set(1.55, -0.72, 0);
const terminalB = terminalA.clone();
terminalB.position.y = 0.72;
scene.add(terminalA, terminalB);
// -------------------------------------------------------------------------
// Rotating faceted magnet
// -------------------------------------------------------------------------
const rotor = new THREE.Group();
scene.add(rotor);
const northHalf = new THREE.Mesh(
new THREE.CylinderGeometry(0.79, 0.79, 1.5, 12, 1, false, 0, Math.PI),
northMaterial
);
northHalf.castShadow = true;
rotor.add(northHalf);
const southHalf = new THREE.Mesh(
new THREE.CylinderGeometry(
0.79,
0.79,
1.5,
12,
1,
false,
Math.PI,
Math.PI
),
southMaterial
);
southHalf.castShadow = true;
rotor.add(southHalf);
const rotorCapTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.83, 0.83, 0.12, 12),
darkMetalMaterial
);
rotorCapTop.position.y = 0.8;
rotorCapTop.castShadow = true;
rotor.add(rotorCapTop);
const rotorCapBottom = rotorCapTop.clone();
rotorCapBottom.position.y = -0.8;
rotor.add(rotorCapBottom);
const rotorShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.11, 2.32, 8),
frameMaterial
);
rotor.add(rotorShaft);
const rotorBand = new THREE.Mesh(
new THREE.TorusGeometry(0.805, 0.035, 4, 24),
frameMaterial
);
rotorBand.rotation.x = Math.PI / 2;
rotor.add(rotorBand);
function createLabelSprite(text, color, width = 0.44) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(4, 12, 18, 0.78)";
context.fillRect(10, 8, 108, 48);
context.strokeStyle = color;
context.lineWidth = 3;
context.strokeRect(10, 8, 108, 48);
context.fillStyle = color;
context.font = "bold 38px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 64, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.5, 1);
sprite.renderOrder = 10;
return sprite;
}
const northLabel = createLabelSprite("N", "#ff725e", 0.42);
northLabel.position.set(1.01, 0.91, 0);
rotor.add(northLabel);
const southLabel = createLabelSprite("S", "#66bdff", 0.42);
southLabel.position.set(-1.01, 0.91, 0);
rotor.add(southLabel);
// -------------------------------------------------------------------------
// Stylized dipole field lines
// -------------------------------------------------------------------------
const fieldGroup = new THREE.Group();
rotor.add(fieldGroup);
const fieldLineMaterial = new THREE.LineBasicMaterial({
color: 0x69d8ff,
transparent: true,
opacity: 0.2
});
const fieldArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x8ce6ff,
transparent: true,
opacity: 0.6
});
function fieldPoint(angle, height) {
return new THREE.Vector3(
0.82 * Math.cos(angle),
height * Math.sin(angle),
0.08 * Math.sin(angle * 2)
);
}
for (const direction of [1, -1]) {
for (let level = 0; level < 3; level++) {
const height = 0.9 + level * 0.34;
const points = [];
for (let i = 0; i <= 32; i++) {
const angle = direction * (i / 32) * Math.PI;
points.push(fieldPoint(angle, height));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, fieldLineMaterial);
fieldGroup.add(line);
for (let arrowIndex = 1; arrowIndex <= 3; arrowIndex++) {
const angle = direction * (arrowIndex / 4) * Math.PI;
const position = fieldPoint(angle, height);
const next = fieldPoint(angle + 0.01, height);
const tangent = next.sub(position).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.16, 3),
fieldArrowMaterial
);
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
fieldGroup.add(arrow);
}
}
}
// -------------------------------------------------------------------------
// Vertical linked-flux arrows
// -------------------------------------------------------------------------
const fluxLines = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0xffb45e,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(fluxLines);
const fluxLineSegments = [];
const fluxArrowData = [];
for (let ring = 0; ring < 3; ring++) {
const radius = 0.38 + ring * 0.25;
for (let side = 0; side < 4; side++) {
const angle = side * Math.PI / 2 + ring * 0.34;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
fluxLineSegments.push(
new THREE.Vector3(x, -0.83, z),
new THREE.Vector3(x, 0.83, z)
);
fluxArrowData.push({ x, z, offset: fluxArrowData.length * 0.137 });
}
}
fluxLines.geometry.dispose();
fluxLines.geometry = new THREE.BufferGeometry().setFromPoints(fluxLineSegments);
const fluxArrows = [];
for (const data of fluxArrowData) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.052, 0.16, 3),
fluxPositiveMaterial
);
arrow.position.set(data.x, 0, data.z);
scene.add(arrow);
fluxArrows.push(arrow);
}
// -------------------------------------------------------------------------
// Induced-voltage circulation arrows and halo
// -------------------------------------------------------------------------
const voltageArrows = new THREE.Group();
scene.add(voltageArrows);
const voltageArrowCount = 20;
for (let i = 0; i < voltageArrowCount; i++) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.052, 0.16, 4),
voltagePositiveMaterial
);
voltageArrows.add(arrow);
}
const voltageHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.36, 0.018, 4, 64),
new THREE.MeshBasicMaterial({
color: 0x50efd0,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
voltageHalo.rotation.x = Math.PI / 2;
voltageHalo.position.y = 0.51;
scene.add(voltageHalo);
const fluxOrb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
new THREE.MeshStandardMaterial({
color: 0xffb45e,
emissive: 0xff8d2e,
emissiveIntensity: 1.1,
roughness: 0.28,
metalness: 0.25,
flatShading: true
})
);
fluxOrb.position.set(-1.92, 0.48, 0);
scene.add(fluxOrb);
const voltageOrb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
new THREE.MeshStandardMaterial({
color: 0x50efd0,
emissive: 0x25d6b8,
emissiveIntensity: 1.1,
roughness: 0.28,
metalness: 0.25,
flatShading: true
})
);
voltageOrb.position.set(1.92, 0.48, 0);
scene.add(voltageOrb);
const fluxLabel = createLabelSprite("Φ", "#ffb45e", 0.5);
fluxLabel.position.set(-1.92, 0.88, 0);
scene.add(fluxLabel);
const voltageLabel = createLabelSprite("ε", "#50efd0", 0.5);
voltageLabel.position.set(1.92, 0.88, 0);
scene.add(voltageLabel);
const indicatorLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.38, 0.48, 0),
new THREE.Vector3(-1.72, 0.48, 0),
new THREE.Vector3(1.38, 0.48, 0),
new THREE.Vector3(1.72, 0.48, 0)
]);
const indicatorLines = new THREE.LineSegments(
indicatorLineGeometry,
new THREE.LineBasicMaterial({
color: 0x57737e,
transparent: true,
opacity: 0.48
})
);
scene.add(indicatorLines);
// -------------------------------------------------------------------------
// Background particles
// -------------------------------------------------------------------------
const backgroundPositions = [];
for (let i = 0; i < 150; i++) {
const angle = Math.random() * TAU;
const radius = 5 + Math.random() * 10;
const height = -1 + Math.random() * 8;
backgroundPositions.push(
Math.cos(angle) * radius,
height,
Math.sin(angle) * radius
);
}
const backgroundGeometry = new THREE.BufferGeometry();
backgroundGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(backgroundPositions, 3)
);
const backgroundParticles = new THREE.Points(
backgroundGeometry,
new THREE.PointsMaterial({
color: 0x7694a5,
size: 0.035,
transparent: true,
opacity: 0.42
})
);
scene.add(backgroundParticles);
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
function syncControlLabels() {
elements.ampOut.value = `${settings.amplitude.toFixed(1)} mWb-turn`;
elements.freqOut.textContent = `${settings.frequency.toFixed(2)} Hz`;
elements.freqOutText.value = `${settings.frequency.toFixed(2)} Hz`;
elements.phaseOut.value = `${Math.round(settings.phase)}°`;
}
function updatePlayButton() {
elements.playBtn.textContent = settings.running
? "Pause signal"
: "Resume signal";
}
elements.ampSlider.addEventListener("input", (event) => {
settings.amplitude = Number(event.target.value);
syncControlLabels();
});
elements.freqSlider.addEventListener("input", (event) => {
settings.frequency = Number(event.target.value);
syncControlLabels();
});
elements.phaseSlider.addEventListener("input", (event) => {
settings.phase = Number(event.target.value);
syncControlLabels();
});
elements.playBtn.addEventListener("click", () => {
settings.running = !settings.running;
updatePlayButton();
});
elements.resetSignal.addEventListener("click", () => {
simulationTime = 0;
settings.phase = 0;
elements.phaseSlider.value = "0";
syncControlLabels();
});
elements.resetView.addEventListener("click", () => {
Object.assign(cameraOrbit, defaultCamera);
updateCamera();
});
elements.fieldToggle.addEventListener("change", (event) => {
settings.showField = event.target.checked;
});
elements.arrowsToggle.addEventListener("change", (event) => {
settings.showArrows = event.target.checked;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
settings.running = !settings.running;
updatePlayButton();
}
if (event.key.toLowerCase() === "r") {
Object.assign(cameraOrbit, defaultCamera);
updateCamera();
}
});
syncControlLabels();
// -------------------------------------------------------------------------
// Oscilloscope
// -------------------------------------------------------------------------
const scopeWindow = 4;
let scopeWidth = 0;
let scopeHeight = 0;
let scopeDpr = 0;
function prepareScope() {
const rect = scope.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(1, Math.floor(rect.width * dpr));
const height = Math.max(1, Math.floor(rect.height * dpr));
if (scope.width !== width || scope.height !== height) {
scope.width = width;
scope.height = height;
}
scopeContext.setTransform(dpr, 0, 0, dpr, 0, 0);
scopeWidth = rect.width;
scopeHeight = rect.height;
scopeDpr = dpr;
}
function drawScope(flux, emf, emfMaximum) {
prepareScope();
const context = scopeContext;
const width = scopeWidth;
const height = scopeHeight;
const left = 29;
const right = 11;
const top = 13;
const bottom = 22;
const plotWidth = width - left - right;
const plotHeight = height - top - bottom;
const middle = top + plotHeight / 2;
context.clearRect(0, 0, width, height);
context.strokeStyle = "rgba(143, 168, 180, 0.12)";
context.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = top + (plotHeight * i) / 4;
context.beginPath();
context.moveTo(left, y + 0.5);
context.lineTo(width - right, y + 0.5);
context.stroke();
}
for (let i = 0; i <= 4; i++) {
const x = left + (plotWidth * i) / 4;
context.beginPath();
context.moveTo(x + 0.5, top);
context.lineTo(x + 0.5, height - bottom);
context.stroke();
}
context.strokeStyle = "rgba(183, 203, 210, 0.28)";
context.beginPath();
context.moveTo(left, middle + 0.5);
context.lineTo(width - right, middle + 0.5);
context.stroke();
const phase = THREE.MathUtils.degToRad(settings.phase);
const omega = TAU * settings.frequency;
const sampleCount = 180;
function drawTrace(valueFunction, maximum, color) {
context.beginPath();
for (let i = 0; i < sampleCount; i++) {
const fraction = i / (sampleCount - 1);
const worldTime = simulationTime - scopeWindow + fraction * scopeWindow;
const angle = phase + omega * worldTime;
const normalized = valueFunction(angle) / Math.max(maximum, 0.00001);
const x = left + fraction * plotWidth;
const y = middle - normalized * (plotHeight / 2) * 0.88;
if (i === 0) context.moveTo(x, y);
else context.lineTo(x, y);
}
context.strokeStyle = color;
context.lineWidth = 1.8;
context.lineJoin = "round";
context.shadowColor = color;
context.shadowBlur = 6;
context.stroke();
context.shadowBlur = 0;
}
drawScopeTrace:
drawTrace(
(angle) => Math.sin(angle),
1,
"#ffb45e"
);
drawTrace(
(angle) => -Math.cos(angle),
1,
"#50efd0"
);
context.fillStyle = "#ffb45e";
context.beginPath();
context.arc(
width - right,
middle - (flux / Math.max(settings.amplitude, 0.00001)) * (plotHeight / 2) * 0.88,
3,
0,
TAU
);
context.fill();
context.fillStyle = "#50efd0";
context.beginPath();
context.arc(
width - right,
middle - (emf / Math.max(emfMaximum, 0.00001)) * (plotHeight / 2) * 0.88,
3,
0,
TAU
);
context.fill();
context.font = "9px monospace";
context.fillStyle = "#718b98";
context.textAlign = "left";
context.fillText("+", 8, top + 4);
context.fillText("0", 13, middle + 3);
context.fillText("−", 8, top + plotHeight);
context.textAlign = "right";
context.fillStyle = "#ffb45e";
context.fillText(
`Φ ±${settings.amplitude.toFixed(1)} mWb`,
width - right,
top - 2
);
context.fillStyle = "#50efd0";
context.fillText(
`ε ±${emfMaximum.toFixed(1)} mV`,
width - right,
height - 5
);
}
scope.addEventListener("pointerdown", (event) => {
const rect = scope.getBoundingClientRect();
const fraction = THREE.MathUtils.clamp(
(event.clientX - rect.left - 29) / Math.max(rect.width - 40, 1),
0,
1
);
simulationTime = simulationTime - scopeWindow + fraction * scopeWindow;
settings.running = false;
updatePlayButton();
});
// -------------------------------------------------------------------------
// Scene animation
// -------------------------------------------------------------------------
const up = new THREE.Vector3(0, 1, 0);
const tangent = new THREE.Vector3();
const direction = new THREE.Vector3();
function signed(value, digits = 2) {
if (Math.abs(value) < 0.00001) value = 0;
return `${value >= 0 ? "+" : "−"}${Math.abs(value).toFixed(digits)}`;
}
function updateScene(flux, derivative, emf, fluxMaximum, emfMaximum) {
const fluxRatio = Math.abs(flux) / Math.max(fluxMaximum, 0.00001);
const emfRatio = Math.abs(emf) / Math.max(emfMaximum, 0.00001);
const positiveFlux = flux >= 0;
// The flux columns switch their direction and color with the signal.
fluxLines.material = positiveFlux
? new THREE.LineBasicMaterial({
color: 0xffb45e,
transparent: true,
opacity: 0.1 + fluxRatio * 0.28,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color: 0x63bdff,
transparent: true,
opacity: 0.1 + fluxRatio * 0.28,
depthWrite: false
});
fluxArrows.forEach((arrow, index) => {
const data = fluxArrowData[index];
const travel = positiveFlux ? 1 : -1;
let fraction = (data.offset + simulationTime * 0.13 * travel) % 1;
if (fraction < 0) fraction += 1;
arrow.position.y = -0.72 + fraction * 1.44;
arrow.material = positiveFlux
? fluxPositiveMaterial
: fluxNegativeMaterial;
direction.set(0, positiveFlux ? 1 : -1, 0);
arrow.quaternion.setFromUnitVectors(up, direction);
arrow.scale.setScalar(0.72 + fluxRatio * 0.45);
});
fluxPositiveMaterial.opacity = 0.35 + fluxRatio * 0.65;
fluxNegativeMaterial.opacity = 0.35 + fluxRatio * 0.65;
fluxOrb.material.color.set(positiveFlux ? 0xffb45e : 0x63bdff);
fluxOrb.material.emissive.set(positiveFlux ? 0xff8d2e : 0x1d79c7);
fluxOrb.material.emissiveIntensity = 0.45 + fluxRatio * 1.3;
fluxOrb.scale.setScalar(0.74 + fluxRatio * 0.55);
fluxOrb.rotation.y += 0.012;
fluxOrb.rotation.x += 0.007;
// Tangential arrows show the sign of the induced circulation.
voltageArrows.visible = settings.showArrows && emfRatio > 0.012;
voltageArrows.children.forEach((arrow, index) => {
const angle = (index / voltageArrowCount) * TAU;
const sign = emf >= 0 ? 1 : -1;
tangent.set(-Math.sin(angle) * sign, 0, Math.cos(angle) * sign);
arrow.position.set(
Math.cos(angle) * 1.36,
0.51,
Math.sin(angle) * 1.36
);
arrow.quaternion.setFromUnitVectors(up, tangent);
arrow.material = emf >= 0
? voltagePositiveMaterial
: voltageNegativeMaterial;
arrow.scale.setScalar(0.68 + emfRatio * 0.68);
});
voltagePositiveMaterial.opacity = 0.32 + emfRatio * 0.68;
voltageNegativeMaterial.opacity = 0.32 + emfRatio * 0.68;
voltageHalo.visible = settings.showArrows;
voltageHalo.material.color.set(emf >= 0 ? 0x50efd0 : 0xff609c);
voltageHalo.material.opacity = 0.08 + emfRatio * 0.48;
voltageHalo.scale.setScalar(1 + emfRatio * 0.035);
voltageOrb.material.color.set(emf >= 0 ? 0x50efd0 : 0xff609c);
voltageOrb.material.emissive.set(emf >= 0 ? 0x25d6b8 : 0xd92d6a);
voltageOrb.material.emissiveIntensity = 0.45 + emfRatio * 1.3;
voltageOrb.scale.setScalar(0.72 + emfRatio * 0.65);
voltageOrb.rotation.y -= 0.017;
coilMaterial.emissive.set(emf >= 0 ? 0x073d36 : 0x3d0924);
coilMaterial.emissiveIntensity = 0.18 + emfRatio * 0.78;
coilGlowMaterial.color.set(emf >= 0 ? 0x50efd0 : 0xff609c);
coilGlowMaterial.opacity = 0.025 + emfRatio * 0.14;
fieldGroup.visible = settings.showField;
fieldLineMaterial.opacity = 0.12 + fluxRatio * 0.17;
fieldArrowMaterial.opacity = 0.28 + fluxRatio * 0.45;
backgroundParticles.rotation.y += 0.00012;
}
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (settings.running) {
simulationTime += delta;
}
const phase = THREE.MathUtils.degToRad(settings.phase);
const omega = TAU * settings.frequency;
const angle = phase + omega * simulationTime;
const flux = settings.amplitude * Math.sin(angle);
const derivative = settings.amplitude * omega * Math.cos(angle);
const emf = -derivative;
const fluxMaximum = Math.max(settings.amplitude, 0.00001);
const emfMaximum = Math.max(settings.amplitude * omega, 0.00001);
rotor.rotation.y = -angle;
updateScene(flux, derivative, emf, fluxMaximum, emfMaximum);
elements.fluxValue.textContent = signed(flux);
elements.dFluxValue.textContent = signed(derivative);
elements.emfValue.textContent = signed(emf);
elements.clock.textContent = `${simulationTime.toFixed(2)} s`;
elements.fluxState.textContent =
Math.abs(flux) < settings.amplitude * 0.015
? "ZERO FLUX"
: flux > 0
? "POSITIVE FLUX"
: "NEGATIVE FLUX";
elements.emfState.textContent =
Math.abs(emf) < emfMaximum * 0.015
? "ZERO VOLTAGE"
: emf > 0
? "POSITIVE VOLTAGE"
: "NEGATIVE VOLTAGE";
elements.fluxValue.style.color = flux >= 0 ? "#ffb45e" : "#63bdff";
elements.dFluxValue.style.color = derivative >= 0 ? "#ffb45e" : "#63bdff";
elements.emfValue.style.color = emf >= 0 ? "#50efd0" : "#ff609c";
elements.fluxState.style.color = flux >= 0 ? "#ffb45e" : "#63bdff";
elements.emfState.style.color = emf >= 0 ? "#50efd0" : "#ff609c";
elements.scopeScale.textContent = `${emfMaximum.toFixed(1)} mV max`;
drawScope(flux, emf, emfMaximum);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```