Prompt specification
Build or customize the Three.js 3D scene "Switch threshold exploration board" 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: Switch threshold exploration board
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/switch-threshold-exploration-board-x1680
Scene Description Prompt:
Use Three.js from cdnjs to allow changing a synthetic sensor value and decision threshold; animate the resulting virtual circuit state while distinguishing this digital abstraction from continuous transistor operation. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (switch-threshold-exploration-board-x1680):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Threshold Lab — Digital Circuit Sandbox</title>
<style>
:root {
color-scheme: dark;
--bg: #070b12;
--panel: rgba(11, 18, 29, 0.88);
--panel-border: rgba(148, 180, 210, 0.16);
--text: #edf5ff;
--muted: #91a3b8;
--cyan: #62f5d2;
--blue: #62a8ff;
--amber: #ffbd66;
--red: #ff758a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
background:
radial-gradient(circle at 70% 15%, rgba(29, 78, 100, 0.20), transparent 38%),
radial-gradient(circle at 15% 85%, rgba(35, 71, 91, 0.18), transparent 34%),
var(--bg);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.brand-mark {
width: 38px;
height: 38px;
border: 1px solid rgba(98, 245, 210, 0.55);
background: rgba(98, 245, 210, 0.08);
display: grid;
place-items: center;
transform: rotate(45deg);
box-shadow: 0 0 24px rgba(98, 245, 210, 0.10);
}
.brand-mark::before {
content: "";
width: 13px;
height: 13px;
border: 2px solid var(--cyan);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.20em;
text-transform: uppercase;
}
h1 {
margin: 3px 0 0;
font-size: clamp(19px, 2vw, 27px);
line-height: 1;
letter-spacing: -0.035em;
font-weight: 760;
}
.brand-status {
margin-left: 10px;
padding: 7px 10px;
border: 1px solid rgba(255, 117, 138, 0.32);
border-radius: 999px;
background: rgba(255, 117, 138, 0.08);
color: var(--red);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
transition: 180ms ease;
}
body[data-state="high"] .brand-status {
color: var(--cyan);
border-color: rgba(98, 245, 210, 0.38);
background: rgba(98, 245, 210, 0.09);
box-shadow: 0 0 22px rgba(98, 245, 210, 0.10);
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(18px) saturate(120%);
-webkit-backdrop-filter: blur(18px) saturate(120%);
border-radius: 18px;
}
.controls {
top: 112px;
left: 24px;
width: 326px;
padding: 18px;
}
.telemetry {
top: 112px;
right: 24px;
width: 304px;
padding: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 17px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.10em;
text-transform: uppercase;
color: #c8d6e7;
font-weight: 800;
}
.panel-heading span {
color: var(--muted);
font-size: 10px;
}
.control-block + .control-block {
margin-top: 20px;
padding-top: 18px;
border-top: 1px solid rgba(148, 180, 210, 0.11);
}
.range-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
font-size: 12px;
color: #c9d5e3;
font-weight: 650;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-size: 13px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0 3px;
appearance: none;
-webkit-appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(90deg, #29475b, #397d77);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
-webkit-appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: #eafff9;
border: 4px solid var(--cyan);
box-shadow: 0 0 0 4px rgba(98, 245, 210, 0.10), 0 0 20px rgba(98, 245, 210, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border-radius: 50%;
background: #eafff9;
border: 4px solid var(--cyan);
box-shadow: 0 0 0 4px rgba(98, 245, 210, 0.10), 0 0 20px rgba(98, 245, 210, 0.35);
}
#threshold {
background: linear-gradient(90deg, #4b3d30, #8b683b);
}
#threshold::-webkit-slider-thumb {
border-color: var(--amber);
box-shadow: 0 0 0 4px rgba(255, 189, 102, 0.09), 0 0 20px rgba(255, 189, 102, 0.28);
}
#threshold::-moz-range-thumb {
border-color: var(--amber);
}
.range-ends {
display: flex;
justify-content: space-between;
color: #65778b;
font-size: 9px;
letter-spacing: 0.06em;
margin-top: 7px;
}
.logic-card {
padding: 13px;
border: 1px solid rgba(148, 180, 210, 0.13);
border-radius: 12px;
background: rgba(3, 8, 15, 0.38);
}
.logic-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}
.state-badge {
padding: 6px 9px;
border-radius: 7px;
background: rgba(255, 117, 138, 0.10);
color: var(--red);
border: 1px solid rgba(255, 117, 138, 0.22);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
transition: 180ms ease;
}
body[data-state="high"] .state-badge {
background: rgba(98, 245, 210, 0.11);
color: var(--cyan);
border-color: rgba(98, 245, 210, 0.26);
}
.voltage {
font-size: 24px;
font-weight: 780;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.equation {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(148, 180, 210, 0.10);
color: var(--muted);
font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.equation strong { color: #eaf4ff; }
.model-card {
padding: 13px;
border: 1px solid rgba(148, 180, 210, 0.13);
border-radius: 12px;
background: rgba(3, 8, 15, 0.34);
}
.model-card + .model-card {
margin-top: 11px;
}
.model-title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
font-size: 11px;
font-weight: 800;
color: #dce7f2;
}
.model-title small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.digital-row {
display: flex;
align-items: baseline;
gap: 8px;
margin-top: 10px;
}
.digital-row strong {
font-size: 23px;
letter-spacing: -0.04em;
}
.digital-row span {
color: var(--muted);
font-size: 10px;
}
.meter {
position: relative;
height: 43px;
margin: 9px 0 4px;
}
.meter-rail {
position: absolute;
left: 0;
right: 0;
top: 16px;
height: 5px;
border-radius: 999px;
background: linear-gradient(90deg, #263b4b, #315667);
overflow: visible;
}
.sensor-marker {
position: absolute;
top: 18px;
width: 12px;
height: 12px;
border-radius: 50%;
transform: translate(-50%, -50%);
background: #f4fbff;
border: 3px solid var(--blue);
box-shadow: 0 0 15px rgba(98, 168, 255, 0.45);
transition: left 70ms linear;
z-index: 2;
}
.threshold-marker {
position: absolute;
top: 7px;
width: 2px;
height: 23px;
transform: translateX(-50%);
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 189, 102, 0.55);
transition: left 70ms linear;
z-index: 1;
}
.meter-labels {
position: absolute;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: space-between;
color: #63768b;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.analog-value {
margin-top: 9px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 10px;
color: var(--muted);
}
.analog-value strong {
color: var(--amber);
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.analog-track {
height: 7px;
border-radius: 999px;
overflow: hidden;
background: rgba(255, 255, 255, 0.06);
}
.analog-fill {
width: 50%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #73583b, var(--amber));
box-shadow: 0 0 15px rgba(255, 189, 102, 0.25);
transition: width 90ms linear;
}
.note {
margin: 9px 0 0;
color: #8092a6;
font-size: 9px;
line-height: 1.55;
}
.warning {
margin-top: 12px;
padding: 10px 11px;
border-left: 2px solid var(--amber);
background: rgba(255, 189, 102, 0.055);
color: #aebdcd;
font-size: 9px;
line-height: 1.55;
}
.footer {
position: absolute;
left: 24px;
bottom: 22px;
max-width: min(530px, calc(100vw - 390px));
color: #75889d;
font-size: 10px;
line-height: 1.6;
pointer-events: none;
text-shadow: 0 2px 12px #000;
}
.footer strong { color: #b7c8d9; }
.camera-controls {
position: absolute;
right: 24px;
bottom: 22px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
border: 1px solid rgba(148, 180, 210, 0.20);
border-radius: 10px;
padding: 9px 12px;
background: rgba(11, 18, 29, 0.82);
color: #c6d4e2;
font: 700 10px/1 inherit;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
color: var(--cyan);
border-color: rgba(98, 245, 210, 0.35);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--bg);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
@media (max-width: 880px) {
.telemetry {
top: 100px;
right: 14px;
width: 270px;
}
.controls {
top: 100px;
left: 14px;
width: 295px;
}
.footer { display: none; }
.camera-controls { right: 14px; bottom: 14px; }
}
@media (max-width: 650px) {
.brand {
top: 14px;
left: 14px;
}
.brand-mark { width: 31px; height: 31px; }
h1 { font-size: 18px; }
.brand-status { display: none; }
.controls {
top: auto;
bottom: 14px;
left: 14px;
right: 14px;
width: auto;
max-height: 43vh;
overflow: auto;
padding: 14px;
}
.telemetry {
top: 76px;
right: 12px;
width: 220px;
padding: 12px;
}
.telemetry .warning,
.telemetry .note,
.telemetry .model-card:first-child .meter-labels {
display: none;
}
.camera-controls { display: none; }
}
</style>
</head>
<body data-state="low">
<canvas id="scene" aria-label="Interactive low-poly virtual circuit. Drag to orbit and scroll to zoom."></canvas>
<div class="hud">
<header class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="eyebrow">Virtual electronics lab</div>
<h1>Threshold Lab</h1>
</div>
<div id="brandStatus" class="brand-status">OUTPUT LOW</div>
</header>
<aside class="panel controls">
<div class="panel-heading">
<h2>Synthetic Inputs</h2>
<span>Live model</span>
</div>
<div class="control-block">
<label class="range-label" for="sensor">
<span>Sensor signal</span>
<output id="sensorValue" for="sensor">−0.18 V</output>
</label>
<input id="sensor" type="range" min="-1" max="1" step="0.01" value="-0.18">
<div class="range-ends"><span>−1.00 V</span><span>+1.00 V</span></div>
</div>
<div class="control-block">
<label class="range-label" for="threshold">
<span>Decision threshold</span>
<output id="thresholdValue" for="threshold">+0.20 V</output>
</label>
<input id="threshold" type="range" min="-0.75" max="0.75" step="0.01" value="0.20">
<div class="range-ends"><span>−0.75 V</span><span>+0.75 V</span></div>
</div>
<div class="control-block">
<div class="logic-card">
<div class="logic-top">
<div id="stateBadge" class="state-badge">LOW</div>
<div id="outputVoltage" class="voltage">0.0 V</div>
</div>
<div class="equation">
output = <strong id="comparisonText">sensor < threshold</strong><br>
margin = <strong id="marginText">−380 mV</strong>
</div>
</div>
</div>
</aside>
<aside class="panel telemetry">
<div class="panel-heading">
<h2>Two Different Models</h2>
<span>Do not conflate</span>
</div>
<div class="model-card">
<div class="model-title">
<span>Digital abstraction</span>
<small>ideal comparator</small>
</div>
<div class="digital-row">
<strong id="digitalState">LOW</strong>
<span>binary output</span>
</div>
<div class="meter">
<div class="meter-rail"></div>
<div id="thresholdMarker" class="threshold-marker"></div>
<div id="sensorMarker" class="sensor-marker"></div>
<div class="meter-labels">
<span>−1 V</span>
<span>sensor / threshold</span>
<span>+1 V</span>
</div>
</div>
<p class="note">The blue dot is the sensor. The amber line is the threshold. The decision snaps at equality.</p>
</div>
<div class="model-card">
<div class="model-title">
<span>Continuous transistor</span>
<small>conceptual proxy</small>
</div>
<div class="analog-value">
<span>Illustrative conduction tendency</span>
<strong id="analogValue">50%</strong>
</div>
<div class="analog-track"><div id="analogFill" class="analog-fill"></div></div>
<p class="note">This smooth amber response illustrates bias around the threshold. It is not a current, power, or SPICE calculation.</p>
</div>
<div class="warning">
A physical transistor changes continuously with bias, temperature, load, and nonidealities.
The digital model intentionally discards that detail and presents one bit.
</div>
</aside>
<div class="footer">
<strong>How to explore:</strong> drag the scene to orbit, scroll to zoom, then move either slider.
Cyan packets represent the ideal binary output; the amber transistor glow represents a smooth,
qualitative response—not a physical circuit simulation.
</div>
<div class="camera-controls">
<button id="resetCamera" type="button">Reset camera</button>
</div>
</div>
<div id="loading">Loading virtual circuit…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ canvas, 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.18;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x070b12);
scene.fog = new THREE.Fog(0x070b12, 12, 27);
const camera = new THREE.PerspectiveCamera(39, window.innerWidth / window.innerHeight, 0.1, 60);
const hemi = new THREE.HemisphereLight(0xa9d8ff, 0x101820, 1.5);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xd9efff, 3.1);
key.position.set(4, 9, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.bias = -0.0005;
scene.add(key);
const rim = new THREE.DirectionalLight(0x2e9cff, 1.4);
rim.position.set(-7, 4, -5);
scene.add(rim);
const cyanLight = new THREE.PointLight(0x62f5d2, 0, 5, 2);
cyanLight.position.set(3.55, 1.0, 0.25);
scene.add(cyanLight);
const world = new THREE.Group();
world.rotation.y = -0.04;
scene.add(world);
const materials = {
board: new THREE.MeshStandardMaterial({
color: 0x102b2c, roughness: 0.72, metalness: 0.18, flatShading: true
}),
chip: new THREE.MeshStandardMaterial({
color: 0x111721, roughness: 0.58, metalness: 0.22, flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x8fa1ae, roughness: 0.32, metalness: 0.78, flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x283846, roughness: 0.48, metalness: 0.65, flatShading: true
}),
gold: new THREE.MeshStandardMaterial({
color: 0xd6a354, roughness: 0.34, metalness: 0.72, flatShading: true
}),
trace: new THREE.MeshStandardMaterial({
color: 0x164c58, emissive: 0x0b4a54, emissiveIntensity: 0.8,
roughness: 0.4, metalness: 0.38, flatShading: true
})
};
function roundedShape(width, height, radius) {
const s = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
s.moveTo(x + radius, y);
s.lineTo(x + width - radius, y);
s.quadraticCurveTo(x + width, y, x + width, y + radius);
s.lineTo(x + width, y + height - radius);
s.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
s.lineTo(x + radius, y + height);
s.quadraticCurveTo(x, y + height, x, y + height - radius);
s.lineTo(x, y + radius);
s.quadraticCurveTo(x, y, x + radius, y);
return s;
}
const boardGeometry = new THREE.ExtrudeGeometry(roundedShape(9.2, 4.4, 0.28), {
depth: 0.22,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.07,
bevelThickness: 0.05,
curveSegments: 3,
steps: 1
});
boardGeometry.rotateX(-Math.PI / 2);
const board = new THREE.Mesh(boardGeometry, materials.board);
board.position.y = -0.02;
board.receiveShadow = true;
board.castShadow = true;
world.add(board);
const boardEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(boardGeometry, 32),
new THREE.LineBasicMaterial({ color: 0x2f6f68, transparent: true, opacity: 0.42 })
);
boardEdges.position.copy(board.position);
world.add(boardEdges);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(19, 48),
new THREE.MeshStandardMaterial({ color: 0x070b10, roughness: 1, metalness: 0 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
function addMesh(geometry, material, position, parent = world) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = world, segments = 6) {
const va = new THREE.Vector3(...a);
const vb = new THREE.Vector3(...b);
const direction = vb.clone().sub(va);
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material,
va.clone().add(vb).multiplyScalar(0.5).toArray(),
parent
);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.normalize());
return mesh;
}
function makeLabel(text, color = "#b9c9d9", width = 1.55) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 112;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(5, 11, 18, 0.82)";
ctx.strokeStyle = "rgba(148, 180, 210, 0.22)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.roundRect(4, 4, 504, 104, 16);
ctx.fill();
ctx.stroke();
const lines = text.split("\n");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = lines.length > 1
? "700 24px system-ui, sans-serif"
: "800 29px system-ui, sans-serif";
const startY = lines.length > 1 ? 38 : 56;
const lineHeight = 34;
lines.forEach((line, i) => ctx.fillText(line, 256, startY + i * lineHeight));
const texture = new THREE.CanvasTexture(c);
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 * 112 / 512, 1);
sprite.renderOrder = 10;
return sprite;
}
// Decorative fasteners.
const screwMaterial = new THREE.MeshStandardMaterial({
color: 0x9caab5, roughness: 0.35, metalness: 0.85, flatShading: true
});
for (const x of [-4.15, 4.15]) {
for (const z of [-1.78, 1.78]) {
addMesh(new THREE.CylinderGeometry(0.10, 0.10, 0.065, 8), screwMaterial, [x, 0.30, z]);
const slot = addMesh(
new THREE.BoxGeometry(0.12, 0.018, 0.022),
materials.darkMetal,
[x, 0.337, z]
);
slot.rotation.y = x * z > 0 ? 0.5 : -0.5;
}
}
// Synthetic low-poly sensor puck.
const sensor = new THREE.Group();
sensor.position.set(-3.2, 0, 0.25);
world.add(sensor);
addMesh(new THREE.CylinderGeometry(0.49, 0.54, 0.30, 8), materials.darkMetal, [0, 0.44, 0], sensor);
addMesh(new THREE.CylinderGeometry(0.36, 0.40, 0.11, 8), materials.chip, [0, 0.64, 0], sensor);
const sensorRingMaterial = new THREE.MeshStandardMaterial({
color: 0x62a8ff,
emissive: 0x2d7dff,
emissiveIntensity: 0.8,
roughness: 0.35,
metalness: 0.3,
flatShading: true
});
const sensorRing = addMesh(
new THREE.TorusGeometry(0.35, 0.045, 4, 16),
sensorRingMaterial,
[0, 0.72, 0],
sensor
);
sensorRing.rotation.x = Math.PI / 2;
const sensorLight = new THREE.PointLight(0x62a8ff, 0.65, 2.2, 2);
sensorLight.position.set(0, 0.85, 0);
sensor.add(sensorLight);
// Comparator IC.
const comparator = new THREE.Group();
comparator.position.set(-1.4, 0, -0.25);
world.add(comparator);
addMesh(new THREE.BoxGeometry(1.12, 0.44, 0.78), materials.chip, [0, 0.52, 0], comparator);
for (let i = 0; i < 4; i++) {
const px = -0.40 + i * 0.27;
addMesh(new THREE.BoxGeometry(0.12, 0.08, 0.23), materials.metal, [px, 0.31, -0.48], comparator);
addMesh(new THREE.BoxGeometry(0.12, 0.08, 0.23), materials.metal, [px, 0.31, 0.48], comparator);
}
addMesh(new THREE.CylinderGeometry(0.29, 0.29, 0.075, 12), materials.darkMetal, [0, 0.78, 0], comparator);
addMesh(new THREE.CylinderGeometry(0.235, 0.235, 0.082, 12), materials.gold, [0, 0.82, 0], comparator);
const thresholdPivot = new THREE.Group();
thresholdPivot.position.set(0, 0.87, 0);
comparator.add(thresholdPivot);
addMesh(new THREE.BoxGeometry(0.30, 0.035, 0.045), materials.chip, [0.12, 0, 0], thresholdPivot);
const comparatorLedMaterial = new THREE.MeshStandardMaterial({
color: 0x54202b,
emissive: 0x351018,
emissiveIntensity: 0.3,
roughness: 0.3,
flatShading: true
});
addMesh(new THREE.SphereGeometry(0.095, 10, 6), comparatorLedMaterial, [0.42, 0.82, 0.22], comparator);
// Transistor in a low-poly TO-220-like package.
const transistor = new THREE.Group();
transistor.position.set(0.65, 0, 0.25);
world.add(transistor);
const transistorMaterial = new THREE.MeshStandardMaterial({
color: 0x151a20,
emissive: 0x3b230c,
emissiveIntensity: 0.12,
roughness: 0.65,
metalness: 0.08,
flatShading: true
});
addMesh(new THREE.BoxGeometry(0.68, 0.58, 0.46), transistorMaterial, [0, 0.64, 0], transistor);
addMesh(new THREE.BoxGeometry(0.43, 0.075, 0.47), materials.metal, [0, 0.96, 0], transistor);
for (let i = 0; i < 3; i++) {
addMesh(
new THREE.BoxGeometry(0.10, 0.28, 0.08),
materials.metal,
[-0.20 + i * 0.20, 0.35, 0],
transistor
);
}
const conductionMaterial = new THREE.MeshStandardMaterial({
color: 0xffb14e,
emissive: 0xff8b21,
emissiveIntensity: 0.8,
roughness: 0.28,
metalness: 0.15,
flatShading: true
});
const conductionStrip = addMesh(
new THREE.BoxGeometry(0.52, 0.10, 0.055),
conductionMaterial,
[0, 0.65, 0.25],
transistor
);
const analogOrbs = [];
for (let i = 0; i < 6; i++) {
const a = (i / 6) * Math.PI * 2;
const material = new THREE.MeshBasicMaterial({
color: 0xffbb60,
transparent: true,
opacity: 0.35,
depthWrite: false
});
const orb = addMesh(
new THREE.IcosahedronGeometry(0.055 + (i % 2) * 0.015, 0),
material,
[Math.cos(a) * 0.48, 0.72 + (i % 2) * 0.20, Math.sin(a) * 0.36],
transistor
);
analogOrbs.push({ mesh: orb, angle: a, phase: i * 0.7 });
}
// Ideal relay / switch.
const relay = new THREE.Group();
relay.position.set(2.35, 0, -0.45);
world.add(relay);
addMesh(new THREE.BoxGeometry(0.92, 0.14, 0.72), materials.darkMetal, [0, 0.36, 0], relay);
addMesh(new THREE.CylinderGeometry(0.24, 0.24, 0.48, 10), materials.chip, [-0.16, 0.66, 0], relay);
addMesh(new THREE.CylinderGeometry(0.11, 0.11, 0.58, 10), materials.metal, [0.22, 0.91, 0], relay);
const lever = new THREE.Group();
lever.position.set(0.22, 0.99, 0);
relay.add(lever);
addMesh(new THREE.BoxGeometry(0.83, 0.075, 0.12), materials.gold, [0.39, 0, 0], lever);
addMesh(new THREE.SphereGeometry(0.095, 8, 5), materials.metal, [0.79, 0, 0], lever);
// Output lamp.
const ledMaterial = new THREE.MeshStandardMaterial({
color: 0x51232d,
emissive: 0x351018,
emissiveIntensity: 0.25,
roughness: 0.24,
metalness: 0.05,
flatShading: true
});
addMesh(new THREE.CylinderGeometry(0.25, 0.29, 0.14, 10), materials.darkMetal, [3.55, 0.35, 0.25]);
addMesh(new THREE.SphereGeometry(0.25, 10, 6), ledMaterial, [3.55, 0.52, 0.25]);
// Circuit traces.
const inputPath = [
[-2.68, 0.31, 0.25], [-2.28, 0.31, 0.25],
[-2.28, 0.31, -0.25], [-1.96, 0.31, -0.25]
];
const decisionPath = [
[-0.84, 0.31, -0.25], [-0.45, 0.31, -0.25],
[-0.45, 0.31, 0.25], [0.25, 0.31, 0.25]
];
const outputPath = [
[1.04, 0.31, 0.25], [1.53, 0.31, 0.25],
[1.53, 0.31, -0.78], [2.82, 0.31, -0.78],
[2.82, 0.31, 0.25], [3.30, 0.31, 0.25]
];
function drawPath(points, material) {
for (let i = 0; i < points.length - 1; i++) {
cylinderBetween(points[i], points[i + 1], 0.035, material, world, 6);
}
}
const inputTraceMaterial = materials.trace.clone();
const decisionTraceMaterial = materials.trace.clone();
const outputTraceMaterial = materials.trace.clone();
drawPath(inputPath, inputTraceMaterial);
drawPath(decisionPath, decisionTraceMaterial);
drawPath(outputPath, outputTraceMaterial);
// Small node pads.
const nodeMaterial = new THREE.MeshStandardMaterial({
color: 0x5cafaa, emissive: 0x174d4c, emissiveIntensity: 0.5,
roughness: 0.4, metalness: 0.5, flatShading: true
});
for (const p of [
[-2.28, 0.33, 0.25], [-0.45, 0.33, 0.25],
[1.53, 0.33, -0.78], [2.82, 0.33, 0.25]
]) {
addMesh(new THREE.CylinderGeometry(0.09, 0.09, 0.045, 8), nodeMaterial, p);
}
// Moving digital packets.
const pathVectors = outputPath.map(p => new THREE.Vector3(...p));
const pathLengths = [];
let totalPathLength = 0;
for (let i = 0; i < pathVectors.length - 1; i++) {
const length = pathVectors[i].distanceTo(pathVectors[i + 1]);
pathLengths.push(length);
totalPathLength += length;
}
function pointAlongPath(t) {
let remaining = THREE.MathUtils.clamp(t, 0, 1) * totalPathLength;
for (let i = 0; i < pathLengths.length; i++) {
if (remaining <= pathLengths[i]) {
return pathVectors[i].clone().lerp(
pathVectors[i + 1],
pathLengths[i] === 0 ? 0 : remaining / pathLengths[i]
);
}
remaining -= pathLengths[i];
}
return pathVectors[pathVectors.length - 1].clone();
}
const packetMaterial = new THREE.MeshBasicMaterial({
color: 0x9affdf,
transparent: true,
opacity: 0,
depthWrite: false
});
const packets = [];
for (let i = 0; i < 8; i++) {
const packet = addMesh(new THREE.OctahedronGeometry(0.065, 0), packetMaterial, [0, 0, 0]);
packet.castShadow = false;
packets.push(packet);
}
// World-space labels.
const labels = [
["01 SYNTHETIC SENSOR", "#9ccaff", -3.2, 1.18, 0.25, 1.55],
["02 COMPARATOR", "#b9c9d9", -1.4, 1.35, -0.25, 1.42],
["03 TRANSISTOR", "#ffbd66", 0.65, 1.38, 0.25, 1.42],
["04 IDEAL SWITCH", "#b9c9d9", 2.35, 1.43, -0.45, 1.52],
["OUTPUT LOAD", "#62f5d2", 3.55, 1.10, 0.25, 1.35]
];
for (const [text, color, x, y, z, width] of labels) {
const label = makeLabel(text, color, width);
label.position.set(x, y, z);
world.add(label);
}
// UI and state.
const ui = {
sensor: document.getElementById("sensor"),
threshold: document.getElementById("threshold"),
sensorValue: document.getElementById("sensorValue"),
thresholdValue: document.getElementById("thresholdValue"),
stateBadge: document.getElementById("stateBadge"),
outputVoltage: document.getElementById("outputVoltage"),
comparisonText: document.getElementById("comparisonText"),
marginText: document.getElementById("marginText"),
brandStatus: document.getElementById("brandStatus"),
digitalState: document.getElementById("digitalState"),
sensorMarker: document.getElementById("sensorMarker"),
thresholdMarker: document.getElementById("thresholdMarker"),
analogValue: document.getElementById("analogValue"),
analogFill: document.getElementById("analogFill")
};
let sensorValue = Number(ui.sensor.value);
let thresholdValue = Number(ui.threshold.value);
let digitalTarget = 0;
let analogTarget = 0.5;
let lastDigital = null;
function signed(value, digits = 2) {
const text = Math.abs(value).toFixed(digits);
return value < 0 ? `−${text}` : `+${text}`;
}
function refreshState() {
const margin = sensorValue - thresholdValue;
digitalTarget = sensorValue >= thresholdValue ? 1 : 0;
analogTarget = 1 / (1 + Math.exp(-margin * 8));
ui.sensorValue.textContent = `${signed(sensorValue)} V`;
ui.thresholdValue.textContent = `${signed(thresholdValue)} V`;
ui.stateBadge.textContent = digitalTarget ? "HIGH" : "LOW";
ui.outputVoltage.textContent = digitalTarget ? "5.0 V" : "0.0 V";
ui.comparisonText.textContent = sensorValue >= thresholdValue
? "sensor ≥ threshold"
: "sensor < threshold";
ui.marginText.textContent = `${signed(margin * 1000, 0)} mV`;
ui.brandStatus.textContent = digitalTarget ? "OUTPUT HIGH" : "OUTPUT LOW";
ui.digitalState.textContent = digitalTarget ? "HIGH" : "LOW";
document.body.dataset.state = digitalTarget ? "high" : "low";
const sensorPercent = THREE.MathUtils.clamp((sensorValue + 1) / 2, 0, 1) * 94 + 3;
const thresholdPercent = THREE.MathUtils.clamp((thresholdValue + 0.75) / 1.5, 0, 1) * 94 + 3;
ui.sensorMarker.style.left = `${sensorPercent}%`;
ui.thresholdMarker.style.left = `${thresholdPercent}%`;
ui.analogValue.textContent = `${Math.round(analogTarget * 100)}%`;
ui.analogFill.style.width = `${Math.max(2, analogTarget * 100)}%`;
thresholdPivot.rotation.y = -(thresholdValue / 0.75) * 1.08;
if (lastDigital !== digitalTarget) {
lastDigital = digitalTarget;
}
}
ui.sensor.addEventListener("input", () => {
sensorValue = Number(ui.sensor.value);
refreshState();
});
ui.threshold.addEventListener("input", () => {
thresholdValue = Number(ui.threshold.value);
refreshState();
});
refreshState();
// Camera controls implemented directly, without addons.
const cameraState = {
yaw: 0.64,
pitch: 0.50,
radius: 11.2,
target: new THREE.Vector3(0, 0.55, 0)
};
const defaultCamera = { ...cameraState, target: cameraState.target.clone() };
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.0045, 0.20, 1.08);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
7.2,
16
);
}, { passive: false });
document.getElementById("resetCamera").addEventListener("click", () => {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
});
function updateCamera() {
const cp = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * cp * cameraState.radius,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * cp * cameraState.radius
);
camera.lookAt(cameraState.target);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const offLed = new THREE.Color(0x51232d);
const onLed = new THREE.Color(0x62f5d2);
const offEmissive = new THREE.Color(0x351018);
const onEmissive = new THREE.Color(0x28d9ad);
const negativeSensor = new THREE.Color(0x4f9fff);
const positiveSensor = new THREE.Color(0x70f0d0);
const amber = new THREE.Color(0xffad43);
const deepAmber = new THREE.Color(0x7b4f21);
const tempColor = new THREE.Color();
let previousTime = performance.now();
let digitalMix = digitalTarget;
let analogMix = analogTarget;
let sensorMix = sensorValue;
function animate(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
const t = now * 0.001;
const digitalEase = 1 - Math.exp(-dt * 11);
const analogEase = 1 - Math.exp(-dt * 7);
const sensorEase = 1 - Math.exp(-dt * 8);
digitalMix += (digitalTarget - digitalMix) * digitalEase;
analogMix += (analogTarget - analogMix) * analogEase;
sensorMix += (sensorValue - sensorMix) * sensorEase;
// The lamp and relay express the ideal binary abstraction.
ledMaterial.color.lerpColors(offLed, onLed, digitalMix);
ledMaterial.emissive.lerpColors(offEmissive, onEmissive, digitalMix);
ledMaterial.emissiveIntensity = 0.25 + digitalMix * 2.0;
comparatorLedMaterial.color.copy(ledMaterial.color);
comparatorLedMaterial.emissive.copy(ledMaterial.emissive);
comparatorLedMaterial.emissiveIntensity = ledMaterial.emissiveIntensity;
cyanLight.intensity = 0.05 + digitalMix * 2.6;
lever.rotation.z = THREE.MathUtils.lerp(-0.34, 0.30, digitalMix);
decisionTraceMaterial.emissive.set(0x2ce0b5);
decisionTraceMaterial.emissiveIntensity = 0.25 + digitalMix * 1.6;
outputTraceMaterial.emissive.set(0x2ce0b5);
outputTraceMaterial.emissiveIntensity = 0.18 + digitalMix * 1.8;
// The transistor strip expresses a smooth qualitative proxy.
const stripScale = Math.max(0.025, analogMix);
conductionStrip.scale.x = stripScale;
conductionStrip.position.x = -0.26 + (0.52 * stripScale) / 2;
conductionMaterial.color.lerpColors(deepAmber, amber, analogMix);
conductionMaterial.emissiveIntensity = 0.16 + analogMix * 1.75;
transistorMaterial.emissive.set(0x4f2c0b);
transistorMaterial.emissiveIntensity = 0.06 + analogMix * 0.38;
for (const orb of analogOrbs) {
const angle = orb.angle + t * (0.45 + analogMix * 0.8);
const radius = 0.42 + analogMix * 0.12;
orb.mesh.position.x = Math.cos(angle) * radius;
orb.mesh.position.z = Math.sin(angle) * radius;
orb.mesh.position.y = 0.72 + (Math.sin(t * 2 + orb.phase) + 1) * 0.11;
orb.mesh.rotation.x = t * 0.8 + orb.phase;
orb.mesh.rotation.y = t * 1.1;
orb.mesh.material.opacity = 0.08 + analogMix * 0.65;
const size = 0.75 + analogMix * 0.55;
orb.mesh.scale.setScalar(size);
}
// Sensor illumination changes continuously with the signed synthetic input.
tempColor.lerpColors(negativeSensor, positiveSensor, (sensorMix + 1) / 2);
sensorRingMaterial.color.copy(tempColor);
sensorRingMaterial.emissive.copy(tempColor);
sensorRingMaterial.emissiveIntensity = 0.35 + Math.abs(sensorMix) * 1.35;
sensorLight.color.copy(tempColor);
sensorLight.intensity = 0.25 + Math.abs(sensorMix) * 1.15;
const sensorPulse = 1 + Math.sin(t * 2.5) * 0.025 * Math.abs(sensorMix);
sensorRing.scale.setScalar(sensorPulse);
// Digital packets exist only for the ideal high output.
packetMaterial.opacity = digitalMix * 0.92;
for (let i = 0; i < packets.length; i++) {
const progress = (t * 0.24 + i / packets.length) % 1;
packets[i].position.copy(pointAlongPath(progress));
packets[i].rotation.x = t * 2.4;
packets[i].rotation.y = t * 1.7;
const pulseScale = 0.72 + Math.sin(t * 8 - i) * 0.18;
packets[i].scale.setScalar(pulseScale);
packets[i].visible = digitalMix > 0.08;
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
requestAnimationFrame(animate);
const loading = document.getElementById("loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 320);
</script>
</body>
</html>
```