Prompt specification
Build or customize the Three.js 3D scene "Electrical measurement classroom 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: Electrical measurement classroom display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/electrical-measurement-classroom-display-x1659
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Ohm's law and voltage-current relationships. Compose a low-voltage virtual circuit board with symbolic meter placements and a live graph; distinguish series current measurement from parallel voltage measurement in the model. Voxel style.
Working Three.js Starter (electrical-measurement-classroom-display-x1659):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ohm's Law — Voxel Circuit Bench</title>
<style>
:root {
--ink: #10242c;
--panel: #132a33;
--panel-2: #193640;
--line: #31505a;
--paper: #e7e2d3;
--muted: #9db1b5;
--orange: #ffb34f;
--cyan: #43dfd0;
--red: #ff6b5c;
--green: #a8f0be;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--ink);
color: #edf5f2;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
.app {
height: 100dvh;
display: grid;
grid-template-rows: 70px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
background: #0d2028;
border-bottom: 1px solid var(--line);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
position: relative;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--orange);
box-shadow: 5px 5px 0 rgba(255, 179, 79, 0.25);
}
.brand-mark::before {
width: 18px;
height: 18px;
left: 2px;
top: 2px;
}
.brand-mark::after {
width: 13px;
height: 13px;
right: 1px;
bottom: 1px;
background: var(--cyan);
box-shadow: 5px 5px 0 rgba(67, 223, 208, 0.22);
}
.brand h1 {
margin: 0;
font-size: 17px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
white-space: nowrap;
}
.header-status {
display: flex;
align-items: center;
gap: 9px;
color: var(--green);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
white-space: nowrap;
}
.status-dot {
width: 8px;
height: 8px;
background: var(--green);
box-shadow: 0 0 0 4px rgba(168, 240, 190, 0.1);
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
min-height: 0;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d9d6c8;
}
#sceneHost {
position: absolute;
inset: 0;
}
#sceneHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#sceneHost canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 20px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 16px;
pointer-events: none;
}
.scene-readout {
display: flex;
align-items: stretch;
background: rgba(13, 32, 40, 0.94);
border: 1px solid #3f5b63;
box-shadow: 7px 7px 0 rgba(16, 36, 44, 0.13);
pointer-events: auto;
}
.readout-cell {
padding: 10px 13px;
border-right: 1px solid #38535c;
}
.readout-cell:last-child {
border-right: 0;
}
.readout-cell span {
display: block;
color: #91a9af;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
margin-bottom: 4px;
}
.readout-cell b {
font: 700 16px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mode-badge {
padding: 10px 12px;
background: var(--orange);
color: #17272c;
font: 800 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
display: flex;
align-items: center;
gap: 8px;
}
.mode-badge::before {
content: "";
width: 7px;
height: 7px;
background: #24383b;
}
.stage-bottom {
position: absolute;
left: 20px;
right: 20px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 15px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: 560px;
}
.legend-chip {
padding: 8px 10px;
background: rgba(13, 32, 40, 0.9);
color: #dce9e7;
border: 1px solid rgba(255, 255, 255, 0.14);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
box-shadow: 4px 4px 0 rgba(16, 36, 44, 0.12);
}
.legend-chip i {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
background: var(--orange);
}
.legend-chip.cyan i {
background: var(--cyan);
}
.view-help {
padding: 8px 10px;
background: rgba(231, 226, 211, 0.82);
color: #30434a;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
line-height: 1.5;
white-space: nowrap;
}
.view-controls {
position: absolute;
right: 20px;
top: 72px;
display: grid;
gap: 5px;
z-index: 5;
}
.view-controls button {
width: 35px;
height: 35px;
border: 1px solid #38535c;
background: rgba(13, 32, 40, 0.9);
color: white;
cursor: pointer;
font: 700 17px ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: 3px 3px 0 rgba(16, 36, 44, 0.15);
}
.view-controls button:hover {
background: var(--panel-2);
}
.callout {
position: absolute;
transform: translate(-50%, -115%);
min-width: 130px;
padding: 8px 10px;
background: rgba(13, 32, 40, 0.94);
border-left: 4px solid var(--orange);
box-shadow: 5px 5px 0 rgba(16, 36, 44, 0.14);
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
z-index: 3;
}
.callout::after {
content: "";
position: absolute;
width: 2px;
height: 16px;
left: 12px;
top: 100%;
background: rgba(13, 32, 40, 0.75);
}
.callout strong {
display: block;
color: white;
font: 800 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.callout span {
display: block;
color: #9eb2b6;
margin-top: 3px;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.callout.cyan {
border-left-color: var(--cyan);
}
.callout.inactive {
opacity: 0.45;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 22px;
background:
linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px),
var(--panel);
background-size: 20px 20px;
border-left: 1px solid #07171e;
scrollbar-width: thin;
scrollbar-color: #41606a var(--panel);
}
.eyebrow {
color: var(--cyan);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h2 {
margin: 8px 0 6px;
font-size: 23px;
letter-spacing: -0.03em;
}
.intro {
margin: 0 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel-section {
margin-top: 16px;
padding: 16px;
background: rgba(7, 23, 30, 0.58);
border: 1px solid var(--line);
box-shadow: 5px 5px 0 rgba(5, 17, 22, 0.28);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 16px;
color: #d7e4e3;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-title span {
color: #708990;
font-size: 9px;
}
.control + .control {
margin-top: 19px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control label {
color: #b9c9cb;
font-size: 12px;
font-weight: 650;
}
output {
color: white;
font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0;
appearance: none;
background: #34515a;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 17px;
height: 17px;
border: 3px solid var(--panel);
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange);
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid var(--panel);
border-radius: 0;
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange);
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
color: #718a91;
margin-top: 7px;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.mode-switch button {
min-height: 58px;
padding: 9px 6px;
border: 1px solid #3b5962;
background: #162f38;
color: #9fb4b7;
cursor: pointer;
text-align: left;
box-shadow: 3px 3px 0 #0a1a20;
transition: 120ms ease;
}
.mode-switch button b {
display: block;
font: 800 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.mode-switch button small {
display: block;
margin-top: 6px;
color: #718b91;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.mode-switch button[data-mode="current"] {
border-left: 4px solid var(--orange);
}
.mode-switch button[data-mode="voltage"] {
border-left: 4px solid var(--cyan);
}
.mode-switch button.active {
background: #203b43;
color: white;
transform: translate(-2px, -2px);
box-shadow: 5px 5px 0 #08171d;
}
.mode-description {
min-height: 56px;
margin: 12px 0 0;
color: #a9bdc0;
font-size: 12px;
line-height: 1.5;
}
.measure-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.measure-card {
min-height: 118px;
padding: 12px;
border: 1px solid #36535c;
background: #132a33;
}
.measure-card.amber {
border-top: 4px solid var(--orange);
}
.measure-card.teal {
border-top: 4px solid var(--cyan);
}
.measure-card .symbol {
display: inline-grid;
place-items: center;
width: 28px;
height: 28px;
margin-bottom: 9px;
background: #263f47;
color: white;
font: 800 15px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.measure-card b {
display: block;
font: 800 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.measure-card p {
margin: 7px 0 0;
color: #8fa8ad;
font-size: 11px;
line-height: 1.45;
}
.formula {
display: grid;
grid-template-columns: 1fr auto 1fr auto 1fr;
align-items: center;
gap: 7px;
margin-bottom: 15px;
}
.formula-value {
padding: 9px 4px;
background: #203b43;
border: 1px solid #3a5962;
text-align: center;
}
.formula-value b {
display: block;
color: var(--orange);
font: 800 19px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula-value small {
display: block;
color: #829ca2;
margin-top: 4px;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
}
.formula-op {
color: #6e8990;
font: 700 18px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.readout-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
}
.value-box {
padding: 10px 8px;
border: 1px solid #33515a;
background: #112730;
text-align: center;
}
.value-box span {
display: block;
color: #779198;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.value-box b {
display: block;
margin-top: 6px;
color: #eef8f4;
font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.value-box.warn b {
color: var(--red);
}
#graph {
display: block;
width: 100%;
height: 220px;
background: #0a1b22;
border: 1px solid #31505a;
}
.graph-key {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #779198;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.graph-key i {
display: inline-block;
width: 17px;
height: 3px;
margin-right: 6px;
vertical-align: middle;
background: var(--orange);
}
.graph-key .dot {
width: 7px;
height: 7px;
margin-right: 6px;
background: var(--cyan);
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
color: #9eb4b8;
font-size: 11px;
}
.toggle {
position: relative;
width: 38px;
height: 20px;
flex: 0 0 auto;
}
.toggle input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-track {
position: absolute;
inset: 0;
background: #36515a;
cursor: pointer;
}
.toggle-track::before {
content: "";
position: absolute;
width: 14px;
height: 14px;
left: 3px;
top: 3px;
background: #9eb2b6;
transition: 120ms ease;
}
.toggle input:checked + .toggle-track {
background: #725323;
}
.toggle input:checked + .toggle-track::before {
left: 21px;
background: var(--orange);
}
.assumption {
margin: 16px 2px 4px;
color: #728d94;
font: 10px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100dvh;
grid-template-rows: 64px auto;
}
main {
display: block;
}
#stage {
height: 62vh;
min-height: 460px;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid #07171e;
}
.view-help {
display: none;
}
}
@media (max-width: 600px) {
header {
padding: 0 14px;
}
.brand p,
.header-status {
display: none;
}
#stage {
height: 57vh;
min-height: 410px;
}
.stage-top {
top: 12px;
left: 12px;
right: 12px;
}
.readout-cell {
padding: 8px 9px;
}
.readout-cell b {
font-size: 13px;
}
.mode-badge {
display: none;
}
.stage-bottom {
left: 12px;
right: 12px;
bottom: 12px;
}
.legend-chip {
font-size: 8px;
}
.view-controls {
right: 12px;
top: 61px;
}
aside {
padding: 16px;
}
.callout {
min-width: 105px;
padding: 6px 8px;
}
.callout strong {
font-size: 8px;
}
.callout span {
font-size: 7px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Ohm's Law / Voxel Bench</h1>
<p>LOW-VOLTAGE VIRTUAL CIRCUIT LAB</p>
</div>
</div>
<div class="header-status">
<span class="status-dot"></span>
MODEL LIVE · IDEAL DC
</div>
</header>
<main>
<section id="stage" aria-label="Interactive three-dimensional circuit board">
<div id="sceneHost"></div>
<div class="stage-top">
<div class="scene-readout">
<div class="readout-cell">
<span>SUPPLY</span>
<b id="sceneVoltage">5.0 V</b>
</div>
<div class="readout-cell">
<span>SERIES CURRENT</span>
<b id="sceneCurrent">50.0 mA</b>
</div>
<div class="readout-cell">
<span>LOAD</span>
<b id="sceneResistance">100 Ω</b>
</div>
</div>
<div class="mode-badge" id="modeBadge">CURRENT / SERIES</div>
</div>
<div class="view-controls" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetView" type="button" aria-label="Reset camera" title="Reset camera">↺</button>
</div>
<div id="calloutA" class="callout">
<strong>AMMETER / A</strong>
<span>SERIES INSERTION</span>
</div>
<div id="calloutV" class="callout cyan">
<strong>VOLTMETER / V</strong>
<span>PARALLEL ACROSS R</span>
</div>
<div id="calloutR" class="callout inactive">
<strong>VARIABLE LOAD</strong>
<span id="loadLabel">R = 100 Ω</span>
</div>
<div id="calloutSource" class="callout inactive">
<strong>DC SOURCE</strong>
<span id="sourceLabel">5.0 V</span>
</div>
<div class="stage-bottom">
<div class="legend">
<div class="legend-chip"><i></i>ONE SERIES CURRENT PATH</div>
<div class="legend-chip cyan"><i></i>VOLTAGE BRANCH: ZERO IDEAL CURRENT</div>
</div>
<div class="view-help">
DRAG: ORBIT · SHIFT-DRAG: PAN · WHEEL: ZOOM<br>
DOUBLE-CLICK: RESET VIEW
</div>
</div>
</section>
<aside>
<div class="eyebrow">Control Deck / 01</div>
<h2>Voltage–Current Relationship</h2>
<p class="intro">
Tune the source and resistance. The ammeter measures the same current that
flows through the load; the voltmeter senses the potential difference
across that load.
</p>
<section class="panel-section">
<div class="section-title">Circuit Inputs <span>Live parameters</span></div>
<div class="control">
<div class="control-head">
<label for="voltageInput">Supply voltage</label>
<output id="voltageOutput" for="voltageInput">5.0 V</output>
</div>
<input id="voltageInput" type="range" min="0" max="12" step="0.1" value="5">
<div class="range-labels"><span>0 V</span><span>12 V</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="resistanceInput">Load resistance</label>
<output id="resistanceOutput" for="resistanceInput">100 Ω</output>
</div>
<input id="resistanceInput" type="range" min="20" max="1000" step="5" value="100">
<div class="range-labels"><span>20 Ω</span><span>1 kΩ</span></div>
</div>
</section>
<section class="panel-section">
<div class="section-title">Measurement Focus <span>Placement stays physical</span></div>
<div class="mode-switch">
<button type="button" class="active" data-mode="current">
<b>CURRENT</b>
<small>SERIES / A</small>
</button>
<button type="button" data-mode="voltage">
<b>VOLTAGE</b>
<small>PARALLEL / V</small>
</button>
</div>
<p class="mode-description" id="modeDescription">
The ammeter is inserted into the single series path, so it carries the
full load current. Its resistance is treated as zero.
</p>
</section>
<section class="panel-section">
<div class="section-title">Meter Logic <span>Symbolic placements</span></div>
<div class="measure-grid">
<div class="measure-card amber">
<span class="symbol">A</span>
<b>SERIES AMMETER</b>
<p>Inserted in the only current-carrying path. Measures loop current.</p>
</div>
<div class="measure-card teal">
<span class="symbol">V</span>
<b>PARALLEL VOLTMETER</b>
<p>Connected across R only. Ideal branch draws zero current.</p>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-title">Ohm's Law <span>Linear resistive load</span></div>
<div class="formula" aria-label="I equals V divided by R">
<div class="formula-value"><b id="formulaI">0.050</b><small>AMPERES</small></div>
<div class="formula-op">=</div>
<div class="formula-value"><b id="formulaV">5.0</b><small>VOLTS</small></div>
<div class="formula-op">÷</div>
<div class="formula-value"><b id="formulaR">100</b><small>OHMS</small></div>
</div>
<div class="readout-grid">
<div class="value-box">
<span>CURRENT</span>
<b id="currentValue">50.0 mA</b>
</div>
<div class="value-box">
<span>LOAD VOLTAGE</span>
<b id="voltageValue">5.0 V</b>
</div>
<div class="value-box" id="powerBox">
<span>POWER</span>
<b id="powerValue">250 mW</b>
</div>
</div>
</section>
<section class="panel-section">
<div class="section-title">Live I–V Graph <span>Selected resistance</span></div>
<canvas id="graph" aria-label="Current versus voltage graph"></canvas>
<div class="graph-key">
<span><i></i>Ohmic line</span>
<span><i class="dot"></i>Operating point</span>
</div>
<div class="toggle-row">
<span>Show series current flow</span>
<label class="toggle">
<input id="flowToggle" type="checkbox" checked>
<span class="toggle-track"></span>
</label>
</div>
</section>
<p class="assumption">
IDEAL MODEL: zero wire and ammeter resistance; infinite voltmeter
resistance; the source sees only the selected resistive load.
</p>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const stage = $("#stage");
const sceneHost = $("#sceneHost");
const state = {
voltage: 5,
resistance: 100,
current: 0.05,
mode: "current",
flow: true
};
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d6c8);
scene.fog = new THREE.Fog(0xd9d6c8, 43, 78);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Voxel circuit board visualization");
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff7df, 0x31505b, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d7, 3.1);
keyLight.position.set(9, 17, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -16;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8dd8dc, 0.7);
fillLight.position.set(-12, 8, -8);
scene.add(fillLight);
const boardGroup = new THREE.Group();
scene.add(boardGroup);
const material = (color, options = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
...options
});
const boardMaterial = material(0x174b50);
const boardEdgeMaterial = material(0x0b3037);
const groundMaterial = material(0xc8c3b2);
const copperMaterial = material(0xd89438, { metalness: 0.28, roughness: 0.48 });
const gridMaterial = new THREE.MeshBasicMaterial({
color: 0x7db4a9,
transparent: true,
opacity: 0.095,
depthWrite: false
});
const currentGlowMaterial = new THREE.MeshBasicMaterial({
color: 0xffb34f,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const voltageGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x43dfd0,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const ammeterMaterial = material(0xe8a43a, {
emissive: 0x633100,
emissiveIntensity: 0.12
});
const voltmeterMaterial = material(0x38c9bd, {
emissive: 0x073f3b,
emissiveIntensity: 0.08
});
const screenMaterial = material(0x102229, { roughness: 0.5 });
const darkMaterial = material(0x17262c);
const ceramicMaterial = material(0xeadfc3);
const redMaterial = material(0xe85d50);
const blueMaterial = material(0x327fc1);
const screwMaterial = material(0xaab5ad, { metalness: 0.55, roughness: 0.36 });
const ledMaterial = material(0xffcf76, {
emissive: 0xff9d25,
emissiveIntensity: 1.5
});
function box(width, height, depth, mat, x, y, z, parent = boardGroup, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and layered PCB.
box(80, 0.22, 80, groundMaterial, 0, -0.72, 0, scene, false);
box(20.4, 0.24, 13.8, boardEdgeMaterial, 0, -0.4, 0);
box(20, 0.56, 13.4, boardMaterial, 0, 0, 0);
// Etched grid.
for (let x = -9; x <= 9; x++) {
box(0.018, 0.018, 12.7, gridMaterial, x, 0.287, 0, boardGroup, false);
}
for (let z = -6; z <= 6; z++) {
box(19.4, 0.018, 0.018, gridMaterial, 0, 0.287, z, boardGroup, false);
}
// Corner voxel screws.
for (const x of [-9.15, 9.15]) {
for (const z of [-5.85, 5.85]) {
box(0.34, 0.22, 0.34, screwMaterial, x, 0.4, z);
box(0.22, 0.035, 0.055, darkMaterial, x, 0.525, z);
box(0.055, 0.035, 0.22, darkMaterial, x, 0.526, z);
}
}
// Decorative raised edge blocks.
const edgeBlockMaterial = material(0x205b5e);
for (const x of [-9.55, 9.55]) {
for (const z of [-5.9, 5.9]) {
box(0.32, 0.24, 0.7, edgeBlockMaterial, x, 0.42, z);
}
}
// Main current path and parallel voltage branch.
const currentPath = [
[-7, -2], [-5, -2], [-2, -2], [0, -2], [4.5, -2],
[7, -2], [7, 3], [-7, 3], [-7, 2], [-7, -2]
];
const voltagePath = [
[0, -2], [0, -6], [0.75, -6],
[3.75, -6], [4.5, -6], [4.5, -2]
];
function addTrace(points, overlayMaterial) {
for (let i = 0; i < points.length - 1; i++) {
const [ax, az] = points[i];
const [bx, bz] = points[i + 1];
const dx = bx - ax;
const dz = bz - az;
const horizontal = Math.abs(dx) > Math.abs(dz);
const width = horizontal ? Math.abs(dx) : 0.16;
const depth = horizontal ? 0.16 : Math.abs(dz);
const x = (ax + bx) / 2;
const z = (az + bz) / 2;
box(width, 0.13, depth, copperMaterial, x, 0.36, z);
box(width + 0.025, 0.025, depth + 0.025, overlayMaterial, x, 0.438, z, boardGroup, false);
}
}
addTrace(currentPath, currentGlowMaterial);
addTrace(voltagePath, voltageGlowMaterial);
function addPad(x, z, color = 0xf3b65e) {
const padMaterial = material(color, { metalness: 0.35, roughness: 0.42 });
box(0.46, 0.09, 0.46, padMaterial, x, 0.46, z);
}
addPad(-7, -2);
addPad(-7, 2);
addPad(0, -2);
addPad(4.5, -2);
addPad(0, -6);
addPad(4.5, -6);
// -------------------------------------------------------------------------
// Voxel source
// -------------------------------------------------------------------------
box(2.6, 0.66, 3.3, darkMaterial, -7, 0.59, 0);
box(2.15, 0.58, 2.5, boardEdgeMaterial, -7, 1.12, 0);
box(0.85, 0.28, 0.62, redMaterial, -7, 0.58, -1.8);
box(0.85, 0.28, 0.62, blueMaterial, -7, 0.58, 1.8);
// Raised plus and minus symbols.
box(0.72, 0.055, 0.14, redMaterial, -7, 1.44, -0.78);
box(0.14, 0.055, 0.72, redMaterial, -7, 1.445, -0.78);
box(0.72, 0.055, 0.14, blueMaterial, -7, 1.445, 0.78);
// -------------------------------------------------------------------------
// Voxel meters
// -------------------------------------------------------------------------
function makeMeter(x, z, bodyMaterial, unitLetter) {
box(3.15, 1.1, 1.72, bodyMaterial, x, 0.96, z);
box(3.35, 0.16, 1.88, darkMaterial, x, 0.42, z);
box(2.82, 0.07, 1.14, screenMaterial, x, 1.54, z);
const digitMaterial = new THREE.MeshStandardMaterial({
color: 0x79ffda,
emissive: 0x35d9be,
emissiveIntensity: 1.25,
roughness: 0.45
});
const segmentPatterns = {
"0": "abcdef",
"1": "bc",
"2": "abdeg",
"3": "abcdg",
"4": "bcfg",
"5": "acdfg",
"6": "acdefg",
"7": "abc",
"8": "abcdefg",
"9": "abcdfg"
};
function createDigit(digitX) {
const group = new THREE.Group();
group.position.set(digitX, 1.61, z);
boardGroup.add(group);
const segments = {};
const definitions = {
a: [0, -0.285, 0.29, 0.065],
g: [0, 0, 0.29, 0.065],
d: [0, 0.285, 0.29, 0.065],
f: [-0.145, -0.142, 0.065, 0.25],
b: [0.145, -0.142, 0.065, 0.25],
e: [-0.145, 0.142, 0.065, 0.25],
c: [0.145, 0.142, 0.065, 0.25]
};
for (const [name, [sx, sz, sw, sd]] of Object.entries(definitions)) {
const segment = new THREE.Mesh(
new THREE.BoxGeometry(sw, 0.055, sd),
digitMaterial.clone()
);
segment.position.set(sx, 0, sz);
segment.visible = false;
group.add(segment);
segments[name] = segment;
}
return { group, segments };
}
const digits = [];
for (let i = 0; i < 4; i++) {
digits.push(createDigit(x - 0.9 + i * 0.48));
}
const decimal = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.055, 0.07),
digitMaterial
);
decimal.position.set(x - 0.66, 1.61, z + 0.29);
decimal.visible = false;
boardGroup.add(decimal);
const letterPatterns = {
A: [
"01110",
"10001",
"10001",
"11111",
"10001",
"10001",
"10001"
],
V: [
"10001",
"10001",
"10001",
"10001",
"10001",
"01010",
"00100"
]
};
const pattern = letterPatterns[unitLetter];
for (let row = 0; row < pattern.length; row++) {
for (let col = 0; col < pattern[row].length; col++) {
if (pattern[row][col] === "1") {
box(
0.054,
0.055,
0.054,
digitMaterial,
x + 0.91 + col * 0.061,
1.61,
z - 0.18 + row * 0.061,
boardGroup,
false
);
}
}
}
function setDigit(digit, char) {
const active = segmentPatterns[char] || "";
for (const [name, mesh] of Object.entries(digit.segments)) {
mesh.visible = active.includes(name);
}
}
return {
setText(slots, decimalAfter = -1) {
slots.forEach((char, index) => setDigit(digits[index], char));
decimal.visible = decimalAfter >= 0;
if (decimalAfter >= 0) {
decimal.position.x = x - 0.66 + decimalAfter * 0.48;
}
}
};
}
const ammeterDisplay = makeMeter(-3.5, -2, ammeterMaterial, "A");
const voltmeterDisplay = makeMeter(2.25, -6, voltmeterMaterial, "V");
// Meter terminal collars.
box(0.42, 0.22, 0.58, copperMaterial, -5, 0.55, -2);
box(0.42, 0.22, 0.58, copperMaterial, -2, 0.55, -2);
box(0.42, 0.22, 0.58, copperMaterial, 0.75, 0.55, -6);
box(0.42, 0.22, 0.58, copperMaterial, 3.75, 0.55, -6);
// -------------------------------------------------------------------------
// Variable resistor
// -------------------------------------------------------------------------
box(4.5, 0.82, 1.12, ceramicMaterial, 2.25, 0.82, -2);
box(0.3, 0.89, 1.16, redMaterial, 0.7, 0.82, -2);
box(0.3, 0.89, 1.16, material(0x5b412c), 1.22, 0.82, -2);
box(0.34, 0.89, 1.16, copperMaterial, 3.25, 0.82, -2);
box(0.3, 0.89, 1.16, redMaterial, 3.82, 0.82, -2);
const resistorMarker = box(0.5, 0.17, 0.62, ledMaterial, 2.25, 1.3, -2);
// Small status LEDs on the board.
const statusLeds = [];
for (const [x, z] of [[-6.2, -2], [5.5, -2], [7, 0.6]]) {
statusLeds.push(box(0.2, 0.12, 0.2, ledMaterial, x, 0.5, z));
}
// -------------------------------------------------------------------------
// Moving series-current particles
// -------------------------------------------------------------------------
const particleMaterial = material(0xffd271, {
emissive: 0xffa52b,
emissiveIntensity: 2.1,
roughness: 0.35
});
const particles = [];
for (let i = 0; i < 28; i++) {
const particle = box(0.2, 0.17, 0.2, particleMaterial, 0, 0.58, 0, scene, false);
particles.push({ mesh: particle, phase: i / 28 });
}
const pathSegments = [];
let totalPathLength = 0;
for (let i = 0; i < currentPath.length - 1; i++) {
const a = currentPath[i];
const b = currentPath[i + 1];
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
pathSegments.push({ a, b, length, start: totalPathLength });
totalPathLength += length;
}
function samplePath(phase) {
const distance = ((phase % 1) + 1) % 1 * totalPathLength;
for (const segment of pathSegments) {
if (distance <= segment.start + segment.length) {
const local = (distance - segment.start) / segment.length;
return {
x: THREE.MathUtils.lerp(segment.a[0], segment.b[0], local),
z: THREE.MathUtils.lerp(segment.a[1], segment.b[1], local)
};
}
}
const last = pathSegments[pathSegments.length - 1];
return { x: last.b[0], z: last.b[1] };
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const anchors = [];
function addAnchor(element, x, y, z) {
const anchor = new THREE.Object3D();
anchor.position.set(x, y, z);
scene.add(anchor);
anchors.push({ element, anchor });
}
addAnchor($("#calloutA"), -3.5, 2.35, -2);
addAnchor($("#calloutV"), 2.25, 2.35, -6);
addAnchor($("#calloutR"), 2.25, 1.85, -2);
addAnchor($("#calloutSource"), -7, 2.25, 0);
const projected = new THREE.Vector3();
function updateProjectedLabels() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
for (const { element, anchor } of anchors) {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, wheel zoom, touch pinch
// -------------------------------------------------------------------------
const cameraState = {
azimuth: 0.72,
elevation: 0.78,
distance: 29,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const { azimuth, elevation, distance, target } = cameraState;
camera.position.set(
target.x + distance * Math.cos(elevation) * Math.sin(azimuth),
target.y + distance * Math.sin(elevation),
target.z + distance * Math.cos(elevation) * Math.cos(azimuth)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.azimuth = 0.72;
cameraState.elevation = 0.78;
cameraState.distance = 29;
cameraState.target.set(0, 0, 0);
updateCamera();
}
const pointers = new Map();
let previousPinchDistance = null;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
stage.addEventListener("pointerdown", (event) => {
if (event.target.closest("button, input")) return;
stage.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
previousPinchDistance = pointerDistance();
});
stage.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (previousPinchDistance / distance),
18,
43
);
updateCamera();
}
previousPinchDistance = distance;
return;
}
if (event.shiftKey || event.buttons === 2) {
const scale = cameraState.distance * 0.00135;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -9, 9);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -7, 7);
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.005,
0.28,
1.35
);
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointerDistance();
}
stage.addEventListener("pointerup", removePointer);
stage.addEventListener("pointercancel", removePointer);
stage.addEventListener("contextmenu", (event) => event.preventDefault());
stage.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
18,
43
);
updateCamera();
}, { passive: false });
stage.addEventListener("dblclick", resetCamera);
$("#zoomIn").addEventListener("click", () => {
cameraState.distance = Math.max(18, cameraState.distance - 2);
updateCamera();
});
$("#zoomOut").addEventListener("click", () => {
cameraState.distance = Math.min(43, cameraState.distance + 2);
updateCamera();
});
$("#resetView").addEventListener("click", resetCamera);
function resizeScene() {
const width = Math.max(1, sceneHost.clientWidth);
const height = Math.max(1, sceneHost.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeScene).observe(sceneHost);
resizeScene();
updateCamera();
// -------------------------------------------------------------------------
// Model and UI
// -------------------------------------------------------------------------
const voltageInput = $("#voltageInput");
const resistanceInput = $("#resistanceInput");
const flowToggle = $("#flowToggle");
function formatResistance(value) {
return value >= 1000 ? `${(value / 1000).toFixed(2)} kΩ` : `${value} Ω`;
}
function updateMeterDisplays() {
const currentMilliamps = Math.round(state.current * 1000);
const currentText = String(currentMilliamps).padStart(3, "0").slice(-3);
ammeterDisplay.setText([currentText[0], currentText[1], currentText[2], " "]);
const whole = Math.floor(state.voltage);
const decimalDigit = Math.floor((state.voltage - whole) * 10 + 0.0001);
if (state.voltage >= 10) {
voltmeterDisplay.setText([
String(whole),
String(whole % 10),
String(decimalDigit),
" "
], 1);
} else {
voltmeterDisplay.setText([
String(whole),
String(decimalDigit),
" ",
" "
], 0);
}
}
function updateModel() {
state.voltage = Number(voltageInput.value);
state.resistance = Number(resistanceInput.value);
state.current = state.voltage / state.resistance;
const currentMilliamps = state.current * 1000;
const powerMilliwatts = state.voltage * state.current * 1000;
const resistanceText = formatResistance(state.resistance);
$("#voltageOutput").textContent = `${state.voltage.toFixed(1)} V`;
$("#resistanceOutput").textContent = resistanceText;
$("#sceneVoltage").textContent = `${state.voltage.toFixed(1)} V`;
$("#sceneCurrent").textContent = `${currentMilliamps.toFixed(1)} mA`;
$("#sceneResistance").textContent = resistanceText;
$("#loadLabel").textContent = `R = ${resistanceText}`;
$("#sourceLabel").textContent = `${state.voltage.toFixed(1)} V`;
$("#formulaI").textContent = state.current.toFixed(3);
$("#formulaV").textContent = state.voltage.toFixed(1);
$("#formulaR").textContent = state.resistance.toLocaleString();
$("#currentValue").textContent = currentMilliamps < 1000
? `${currentMilliamps.toFixed(1)} mA`
: `${(state.current).toFixed(2)} A`;
$("#voltageValue").textContent = `${state.voltage.toFixed(1)} V`;
$("#powerValue").textContent = powerMilliwatts >= 1000
? `${(powerMilliwatts / 1000).toFixed(2)} W`
: `${powerMilliwatts.toFixed(0)} mW`;
$("#powerBox").classList.toggle("warn", powerMilliwatts > 250);
const markerNormalized = (state.resistance - 20) / 980;
resistorMarker.position.x = THREE.MathUtils.lerp(0.4, 4.05, markerNormalized);
const ledBrightness = state.voltage > 0 ? 1.15 + state.current * 1.8 : 0.12;
ledMaterial.emissiveIntensity = ledBrightness;
updateMeterDisplays();
drawGraph();
}
function setMode(mode) {
state.mode = mode;
document.querySelectorAll(".mode-switch button").forEach((button) => {
button.classList.toggle("active", button.dataset.mode === mode);
});
if (mode === "current") {
currentGlowMaterial.opacity = 0.9;
voltageGlowMaterial.opacity = 0.2;
ammeterMaterial.emissiveIntensity = 0.32;
voltmeterMaterial.emissiveIntensity = 0.05;
$("#modeBadge").textContent = "CURRENT / SERIES";
$("#modeBadge").style.background = "var(--orange)";
$("#calloutA").classList.remove("inactive");
$("#calloutV").classList.add("inactive");
$("#modeDescription").textContent =
"The ammeter is inserted into the single series path, so it carries the full load current. Its resistance is treated as zero.";
} else {
currentGlowMaterial.opacity = 0.28;
voltageGlowMaterial.opacity = 0.92;
ammeterMaterial.emissiveIntensity = 0.05;
voltmeterMaterial.emissiveIntensity = 0.3;
$("#modeBadge").textContent = "VOLTAGE / PARALLEL";
$("#modeBadge").style.background = "var(--cyan)";
$("#calloutA").classList.add("inactive");
$("#calloutV").classList.remove("inactive");
$("#modeDescription").textContent =
"The voltmeter is connected in parallel across the resistor only. It senses V without interrupting the current path; ideally its branch draws zero current.";
}
}
document.querySelectorAll(".mode-switch button").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
voltageInput.addEventListener("input", updateModel);
resistanceInput.addEventListener("input", updateModel);
flowToggle.addEventListener("change", () => {
state.flow = flowToggle.checked;
});
// -------------------------------------------------------------------------
// Live I-V graph
// -------------------------------------------------------------------------
const graphCanvas = $("#graph");
const graphContext = graphCanvas.getContext("2d");
function drawGraph() {
const rect = graphCanvas.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const pixelWidth = Math.round(rect.width * dpr);
const pixelHeight = Math.round(rect.height * dpr);
if (graphCanvas.width !== pixelWidth || graphCanvas.height !== pixelHeight) {
graphCanvas.width = pixelWidth;
graphCanvas.height = pixelHeight;
}
const ctx = graphContext;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, rect.width, rect.height);
const w = rect.width;
const h = rect.height;
const margin = { left: 43, right: 17, top: 17, bottom: 34 };
const plotWidth = w - margin.left - margin.right;
const plotHeight = h - margin.top - margin.bottom;
const maxVoltage = 12;
const maxCurrent = 600;
const xFor = (voltage) => margin.left + (voltage / maxVoltage) * plotWidth;
const yFor = (current) => margin.top + plotHeight - (current / maxCurrent) * plotHeight;
ctx.fillStyle = "#0a1b22";
ctx.fillRect(0, 0, w, h);
ctx.font = "9px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.lineWidth = 1;
// Grid.
for (let voltage = 0; voltage <= maxVoltage; voltage += 2) {
const x = xFor(voltage);
ctx.strokeStyle = "rgba(122, 164, 169, 0.13)";
ctx.beginPath();
ctx.moveTo(x, margin.top);
ctx.lineTo(x, margin.top + plotHeight);
ctx.stroke();
ctx.fillStyle = "#718c93";
ctx.textAlign = "center";
ctx.fillText(String(voltage), x, h - 14);
}
for (let current = 0; current <= maxCurrent; current += 100) {
const y = yFor(current);
ctx.strokeStyle = "rgba(122, 164, 169, 0.13)";
ctx.beginPath();
ctx.moveTo(margin.left, y);
ctx.lineTo(margin.left + plotWidth, y);
ctx.stroke();
ctx.fillStyle = "#718c93";
ctx.textAlign = "right";
ctx.fillText(String(current), margin.left - 8, y + 3);
}
ctx.strokeStyle = "#547078";
ctx.beginPath();
ctx.moveTo(margin.left, margin.top);
ctx.lineTo(margin.left, margin.top + plotHeight);
ctx.lineTo(margin.left + plotWidth, margin.top + plotHeight);
ctx.stroke();
ctx.fillStyle = "#8ca4aa";
ctx.textAlign = "right";
ctx.fillText("VOLTAGE (V)", w - 8, h - 2);
ctx.save();
ctx.translate(11, margin.top + plotHeight / 2);
ctx.rotate(-Math.PI / 2);
ctx.textAlign = "center";
ctx.fillText("CURRENT (mA)", 0, 0);
ctx.restore();
// Ohmic characteristic I = V/R.
const currentAtMaxVoltage = 1000 * maxVoltage / state.resistance;
ctx.strokeStyle = "#ffb34f";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(xFor(0), yFor(0));
ctx.lineTo(xFor(maxVoltage), yFor(Math.min(maxCurrent, currentAtMaxVoltage)));
ctx.stroke();
// Operating-point guides.
const operatingCurrent = Math.min(maxCurrent, state.current * 1000);
const pointX = xFor(state.voltage);
const pointY = yFor(operatingCurrent);
ctx.setLineDash([3, 4]);
ctx.strokeStyle = "rgba(67, 223, 208, 0.45)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(pointX, margin.top + plotHeight);
ctx.lineTo(pointX, pointY);
ctx.moveTo(margin.left, pointY);
ctx.lineTo(pointX, pointY);
ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = "#43dfd0";
ctx.strokeStyle = "#0a1b22";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(pointX, pointY, 5.5, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
ctx.fillStyle = "#b8cbc9";
ctx.textAlign = "left";
ctx.fillText(`${state.voltage.toFixed(1)} V`, Math.min(pointX + 8, w - 48), Math.max(pointY - 9, 12));
ctx.fillText(`${operatingCurrent.toFixed(1)} mA`, margin.left + 6, Math.max(pointY - 8, 12));
}
new ResizeObserver(drawGraph).observe(graphCanvas);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const normalizedCurrent = THREE.MathUtils.clamp(state.current / 0.6, 0, 1);
const phaseSpeed = state.flow && state.voltage > 0
? 0.025 + normalizedCurrent * 0.105
: 0;
for (const particle of particles) {
particle.phase = (particle.phase + dt * phaseSpeed) % 1;
const point = samplePath(particle.phase);
particle.mesh.position.set(point.x, 0.59, point.z);
particle.mesh.visible = state.flow && state.voltage > 0;
particle.mesh.rotation.y = elapsed * 0.8 + particle.phase * Math.PI * 2;
}
const subtlePulse = 1 + Math.sin(elapsed * 3.2) * 0.12;
currentGlowMaterial.opacity *= 0.985;
voltageGlowMaterial.opacity *= 0.985;
currentGlowMaterial.opacity = Math.min(
currentGlowMaterial.opacity + 0.015,
state.mode === "current" ? 0.9 * subtlePulse : 0.28
);
voltageGlowMaterial.opacity = Math.min(
voltageGlowMaterial.opacity + 0.015,
state.mode === "voltage" ? 0.92 * subtlePulse : 0.2
);
updateProjectedLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setMode("current");
updateModel();
animate();
</script>
</body>
</html>
```