Prompt specification
Build or customize the Three.js 3D scene "Camera-flash timing analogy exhibit" 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: Camera-flash timing analogy exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/camera-flash-timing-analogy-exhibit-x1663
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing charging and discharging in an RC circuit. Compose a stylized flash device beside a separate ideal RC model; connect delayed energy accumulation conceptually without describing construction of a real high-voltage flash circuit. Voxel style.
Working Three.js Starter (camera-flash-timing-analogy-exhibit-x1663):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Energy Lab — RC Charge & Discharge</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 21, 38, 0.88);
--panel-border: rgba(135, 213, 255, 0.18);
--text: #edf8ff;
--muted: #90a9bc;
--cyan: #53d9ff;
--amber: #ffc857;
--green: #70efad;
--red: #ff6f7d;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
max-width: min(540px, calc(100vw - 360px));
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(25px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.readout {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
width: 292px;
padding: 17px;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
.readout-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.readout-title {
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#state {
padding: 6px 9px;
border-radius: 999px;
color: #07111f;
background: var(--cyan);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 180ms ease;
}
#state[data-state="charging"] {
background: var(--amber);
}
#state[data-state="charged"] {
background: var(--green);
}
#state[data-state="discharging"] {
background: var(--red);
}
#state[data-state="reset"] {
background: #92a6b8;
}
.metric {
margin-top: 14px;
}
.metric-label {
display: flex;
justify-content: space-between;
align-items: baseline;
color: var(--muted);
font-size: 11px;
}
.metric-value {
color: var(--text);
font: 700 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bar {
height: 6px;
margin-top: 8px;
overflow: hidden;
border-radius: 8px;
background: rgba(255, 255, 255, 0.08);
}
.bar > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--cyan);
box-shadow: 0 0 12px currentColor;
transition: width 80ms linear;
}
#currentFill {
background: var(--amber);
}
.equation {
margin-top: 15px;
padding: 11px 12px;
border: 1px solid rgba(83, 217, 255, 0.12);
border-radius: 9px;
background: rgba(83, 217, 255, 0.055);
color: #c7efff;
font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.readout-foot {
display: flex;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.controls {
position: fixed;
z-index: 7;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
max-width: calc(100vw - 30px);
padding: 9px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(15px);
}
button,
select {
min-height: 38px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
background: rgba(255, 255, 255, 0.065);
color: var(--text);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
button {
padding: 0 13px;
}
button:hover,
select:hover {
border-color: rgba(83, 217, 255, 0.55);
background: rgba(83, 217, 255, 0.1);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(83, 217, 255, 0.4);
background: var(--cyan);
color: #07111f;
}
button.amber {
border-color: rgba(255, 200, 87, 0.36);
color: var(--amber);
}
button.red {
border-color: rgba(255, 111, 125, 0.36);
color: var(--red);
}
select {
padding: 0 28px 0 10px;
}
.separator {
width: 1px;
height: 26px;
margin: 0 2px;
background: rgba(255, 255, 255, 0.12);
}
.legend {
position: fixed;
z-index: 5;
left: 26px;
bottom: 25px;
display: grid;
gap: 7px;
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 9px currentColor;
}
.swatch.cyan {
color: var(--cyan);
background: var(--cyan);
}
.swatch.amber {
color: var(--amber);
background: var(--amber);
}
.swatch.white {
color: white;
background: white;
}
.note {
position: fixed;
z-index: 5;
right: 24px;
bottom: 25px;
max-width: 270px;
color: #758b9e;
font: 9px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
padding: 6px 8px;
border: 1px solid rgba(131, 211, 255, 0.22);
border-radius: 7px;
background: rgba(7, 17, 31, 0.72);
color: #d9f4ff;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(6px);
}
.world-label.small {
padding: 4px 6px;
border-color: rgba(255, 255, 255, 0.1);
color: #9db5c8;
font-size: 8px;
}
.world-label.concept {
border-color: rgba(255, 255, 255, 0.15);
color: #dce9f3;
font-size: 8px;
letter-spacing: 0.05em;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
@media (max-width: 820px) {
.brand {
top: 17px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 27px;
}
.subtitle {
max-width: 330px;
font-size: 11px;
}
.readout {
top: auto;
right: 14px;
bottom: 84px;
width: 230px;
padding: 13px;
}
.equation,
.readout-foot {
display: none;
}
.controls {
bottom: 13px;
width: calc(100vw - 26px);
overflow-x: auto;
justify-content: flex-start;
}
.legend,
.note {
display: none;
}
.world-label.small {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="loading">Building voxel energy lab…</div>
<header class="brand">
<div class="eyebrow">Voxel Energy Lab / 01</div>
<h1>Charge. Hold. Release.</h1>
<p class="subtitle">
A stylized flash device beside a separate ideal RC model.
Moving voxels visualize current, stored charge, and a conceptual delay.
</p>
</header>
<aside class="readout" aria-label="Circuit readout">
<div class="readout-head">
<span class="readout-title">Ideal RC Response</span>
<span id="state" data-state="ready">Ready</span>
</div>
<div class="metric">
<div class="metric-label">
<span>Capacitor voltage</span>
<span id="voltage" class="metric-value">0.00 V</span>
</div>
<div class="bar"><span id="voltageFill"></span></div>
</div>
<div class="metric">
<div class="metric-label">
<span>Circuit current</span>
<span id="current" class="metric-value">0.000 mA</span>
</div>
<div class="bar"><span id="currentFill"></span></div>
</div>
<div id="equation" class="equation">
Vc(t) = V(1 − e<sup>−t/RC</sup>)<br />
I(t) = (V/R)e<sup>−t/RC</sup>
</div>
<div class="readout-foot">
<span>R = 10 kΩ</span>
<span>C = 100 μF</span>
<span>τ = RC = 1 s</span>
</div>
</aside>
<div class="legend">
<div class="legend-row">
<span class="swatch cyan"></span>
<span>Stored charge / conceptual path</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span>Circuit current</span>
</div>
<div class="legend-row">
<span class="swatch white"></span>
<span>Delayed visual energy packet</span>
</div>
</div>
<div class="controls" aria-label="Animation controls">
<button id="play" class="primary" type="button">Pause</button>
<button id="charge" class="amber" type="button">Charge</button>
<button id="discharge" class="red" type="button">Discharge</button>
<button id="reset" type="button">Reset</button>
<span class="separator"></span>
<label for="speed" class="world-label small" style="position: static; transform: none;">
Speed
</label>
<select id="speed" aria-label="Animation speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
<span class="separator"></span>
<button id="cameraReset" type="button">Camera</button>
</div>
<div class="note">
CONCEPTUAL VISUALIZATION ONLY<br />
The dotted path is not a physical wire. The flash unit exposes no
real high-voltage circuitry.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, scene, camera, and direct camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 23, 42);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xa8dcff, 0x182033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xdaf4ff, 3.2);
keyLight.position.set(-5, 13, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4f7cff, 2.0);
rimLight.position.set(11, 7, -10);
scene.add(rimLight);
const target = new THREE.Vector3(0.2, 1.55, 0);
let yaw = 0.24;
let pitch = 1.13;
let radius = 18.7;
let targetYaw = yaw;
let targetPitch = pitch;
let targetRadius = radius;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const horizontal = Math.sin(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.cos(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
function resetCamera() {
targetYaw = 0.24;
targetPitch = 1.13;
targetRadius = 18.7;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
targetYaw -= dx * 0.006;
targetPitch = THREE.MathUtils.clamp(
targetPitch - dy * 0.005,
0.55,
1.36
);
});
function stopDragging(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
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();
targetRadius = THREE.MathUtils.clamp(
targetRadius * Math.exp(event.deltaY * 0.001),
11.5,
27
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Voxel construction helpers
// -------------------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.96,
metalness: 0
}),
plinth: new THREE.MeshStandardMaterial({
color: 0x102238,
roughness: 0.84,
metalness: 0.05
}),
board: new THREE.MeshStandardMaterial({
color: 0x102b38,
roughness: 0.76,
metalness: 0.08
}),
navy: new THREE.MeshStandardMaterial({
color: 0x17283b,
roughness: 0.72,
metalness: 0.08
}),
dark: new THREE.MeshStandardMaterial({
color: 0x0b1421,
roughness: 0.78,
metalness: 0.08
}),
blue: new THREE.MeshStandardMaterial({
color: 0x2478ac,
roughness: 0.58,
metalness: 0.14
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x53d9ff,
emissive: 0x1a9bc8,
emissiveIntensity: 0.65,
roughness: 0.42
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0xb76a00,
emissiveIntensity: 0.55,
roughness: 0.46
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff7448,
roughness: 0.66,
metalness: 0.03
}),
white: new THREE.MeshStandardMaterial({
color: 0xeaf8ff,
emissive: 0xbceaff,
emissiveIntensity: 0.6,
roughness: 0.4
}),
metal: new THREE.MeshStandardMaterial({
color: 0xa9c0cf,
roughness: 0.34,
metalness: 0.62
}),
wire: new THREE.MeshStandardMaterial({
color: 0x315269,
roughness: 0.55,
metalness: 0.35
}),
dimCyan: new THREE.MeshStandardMaterial({
color: 0x20495a,
emissive: 0x0c3746,
emissiveIntensity: 0.45,
roughness: 0.6
}),
red: new THREE.MeshStandardMaterial({
color: 0xff596d,
emissive: 0x7b1020,
emissiveIntensity: 0.55,
roughness: 0.45
})
};
function box(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, length, thickness),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addWirePath(points, material = materials.wire, thickness = 0.055) {
for (let i = 0; i < points.length - 1; i++) {
beamBetween(points[i], points[i + 1], thickness, material);
}
}
function pathCurve(points) {
const curve = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
curve.add(
new THREE.LineCurve3(
new THREE.Vector3(...points[i]),
new THREE.Vector3(...points[i + 1])
)
);
}
return curve;
}
// -------------------------------------------------------------------------
// Ground and separate display platforms
// -------------------------------------------------------------------------
box(34, 0.22, 25, 0, -0.17, 0, materials.floor, scene, false);
const gridMaterial = new THREE.MeshBasicMaterial({
color: 0x1c3b51,
transparent: true,
opacity: 0.2
});
for (let x = -16; x <= 16; x += 1) {
box(0.012, 0.006, 22, x, -0.052, 0, gridMaterial, scene, false);
}
for (let z = -11; z <= 11; z += 1) {
box(30, 0.006, 0.012, 0, -0.05, z, gridMaterial, scene, false);
}
box(4.65, 0.34, 4.25, -5, 0.08, 0, materials.plinth);
box(8.6, 0.34, 5.15, 3.25, 0.08, 0, materials.plinth);
box(4.25, 0.045, 0.08, -5, 0.275, 2.0, materials.cyan, scene, false);
box(8.2, 0.045, 0.08, 3.25, 0.275, 2.48, materials.cyan, scene, false);
// A small voxel divider emphasizes that the two displays are separate.
for (let i = 0; i < 7; i++) {
box(
0.13,
0.18 + (i % 3) * 0.09,
0.16,
-1.65,
0.31 + (i % 3) * 0.09,
-1.7 + i * 0.48,
i % 2 ? materials.dimCyan : materials.plinth
);
}
// -------------------------------------------------------------------------
// Stylized flash device — exterior only
// -------------------------------------------------------------------------
const flashGroup = new THREE.Group();
scene.add(flashGroup);
box(2.55, 2.18, 1.62, -5, 1.42, 0, materials.navy, flashGroup);
box(0.68, 2.23, 1.83, -6.46, 1.4, 0.02, materials.orange, flashGroup);
box(2.35, 0.16, 1.72, -5, 2.57, 0, materials.dark, flashGroup);
// Large block-shaped flash head.
box(3.05, 1.28, 1.98, -5, 3.08, 0, materials.navy, flashGroup);
box(3.22, 0.14, 2.08, -5, 3.78, 0, materials.dark, flashGroup);
box(0.12, 0.75, 1.52, -6.57, 3.08, 0, materials.dark, flashGroup);
const flashDiffuserMaterial = materials.cyan.clone();
const flashDiffuser = box(
2.35,
0.78,
0.09,
-5,
3.08,
1.025,
flashDiffuserMaterial,
flashGroup
);
// Pixelated grille.
for (let column = 0; column < 7; column++) {
for (let row = 0; row < 2; row++) {
box(
0.22,
0.18,
0.025,
-5.95 + column * 0.31,
2.9 + row * 0.28,
1.079,
materials.dark,
flashGroup,
false
);
}
}
// Front display.
box(1.18, 0.62, 0.075, -5.05, 1.69, 0.845, materials.dark, flashGroup);
box(0.83, 0.31, 0.035, -5.16, 1.73, 0.9, materials.dimCyan, flashGroup);
// Voxel buttons.
box(0.28, 0.19, 0.16, -5.9, 1.03, 0.9, materials.cyan, flashGroup);
box(0.28, 0.19, 0.16, -5.47, 1.03, 0.9, materials.amber, flashGroup);
// Charge indicator.
const deviceChargeBars = [];
for (let i = 0; i < 6; i++) {
const bar = box(
0.16,
0.19,
0.035,
-5.48 + i * 0.2,
1.35,
0.895,
materials.dimCyan.clone(),
flashGroup,
false
);
deviceChargeBars.push(bar);
}
const flashLight = new THREE.PointLight(0xd9f7ff, 0, 9, 2);
flashLight.position.set(-5, 3.1, 1.45);
flashGroup.add(flashLight);
// -------------------------------------------------------------------------
// Ideal RC model
// -------------------------------------------------------------------------
box(8.2, 0.28, 4.62, 3.25, 0.38, 0, materials.board);
// Board pixel border.
for (let x = -0.65; x <= 7.15; x += 0.28) {
box(0.12, 0.035, 0.045, x, 0.535, 2.23, materials.dimCyan, scene, false);
}
for (let z = -2.12; z <= 2.12; z += 0.28) {
box(0.045, 0.035, 0.12, 7.18, 0.535, z, materials.dimCyan, scene, false);
}
// Low-voltage source represented as a single block cell.
box(0.86, 1.12, 0.82, 0.96, 1.08, -1.25, materials.blue);
box(0.91, 0.14, 0.87, 0.96, 1.42, -1.25, materials.dimCyan);
box(0.18, 0.13, 0.28, 1.43, 1.67, -1.25, materials.metal);
box(0.18, 0.13, 0.28, 0.51, 1.67, -1.25, materials.dark);
box(0.13, 0.13, 0.035, 1.02, 1.2, -0.82, materials.white, scene, false);
function makeSwitch(x, z, accentMaterial) {
box(0.86, 0.13, 0.46, x, 0.61, z, materials.dark);
box(0.12, 0.12, 0.18, x - 0.32, 0.8, z, materials.metal);
box(0.12, 0.12, 0.18, x + 0.32, 0.8, z, accentMaterial);
const pivot = new THREE.Group();
pivot.position.set(x - 0.32, 0.87, z);
scene.add(pivot);
box(0.64, 0.075, 0.12, 0.32, 0, 0, materials.metal, pivot);
box(0.17, 0.15, 0.17, 0.58, 0.02, 0, accentMaterial, pivot);
return pivot;
}
const chargeSwitch = makeSwitch(1.95, -1.25, materials.amber);
const dischargeSwitch = makeSwitch(4.3, 1.25, materials.red);
// Resistor.
box(1.1, 0.35, 0.46, 3.3, 0.82, -1.25, materials.white);
box(0.15, 0.12, 0.49, 3.03, 0.82, -1.25, materials.orange);
box(0.15, 0.12, 0.49, 3.3, 0.82, -1.25, materials.amber);
box(0.15, 0.12, 0.49, 3.57, 0.82, -1.25, materials.red);
box(0.18, 0.1, 0.28, 2.69, 0.82, -1.25, materials.metal);
box(0.18, 0.1, 0.28, 3.91, 0.82, -1.25, materials.metal);
// Capacitor: two voxel plates with a visible gap.
const capacitorPlateMaterial = materials.metal.clone();
const capacitorLeftMaterial = materials.metal.clone();
const capacitorRightMaterial = materials.metal.clone();
box(0.13, 1.24, 1.02, 4.67, 1.15, -1.25, capacitorLeftMaterial);
box(0.13, 1.24, 1.02, 5.53, 1.15, -1.25, capacitorRightMaterial);
box(0.38, 0.82, 0.84, 5.1, 1.1, -1.25, materials.dimCyan);
box(0.16, 0.1, 0.29, 4.53, 1.0, -1.25, materials.metal);
box(0.16, 0.1, 0.29, 5.67, 1.0, -1.25, materials.metal);
// Load.
const loadMaterial = materials.amber.clone();
box(0.82, 0.68, 0.78, 2.95, 0.94, 1.25, materials.dark);
box(0.56, 0.45, 0.06, 2.95, 0.99, 1.68, loadMaterial);
box(0.18, 0.1, 0.27, 2.48, 0.86, 1.25, materials.metal);
box(0.18, 0.1, 0.27, 3.42, 0.86, 1.25, materials.metal);
// Charge path and return path.
const chargePathPoints = [
[1.43, 1.67, -1.25],
[1.63, 0.8, -1.25],
[2.27, 0.8, -1.25],
[2.69, 0.82, -1.25],
[3.91, 0.82, -1.25],
[4.53, 1.0, -1.25]
];
const chargeReturnPoints = [
[5.67, 1.0, -1.25],
[5.96, 0.59, -2.04],
[0.51, 0.59, -2.04],
[0.51, 1.67, -1.25]
];
const dischargePathPoints = [
[4.53, 1.0, -1.25],
[4.53, 0.73, 0.62],
[4.62, 0.8, 1.25],
[3.98, 0.8, 1.25],
[3.42, 0.86, 1.25],
[2.48, 0.86, 1.25],
[2.15, 0.59, 1.25],
[2.15, 0.59, -2.04],
[5.96, 0.59, -2.04],
[5.67, 1.0, -1.25]
];
addWirePath(chargePathPoints);
addWirePath(chargeReturnPoints);
addWirePath(dischargePathPoints);
const chargeCurve = pathCurve([
...chargePathPoints,
...chargeReturnPoints.slice(1)
]);
const dischargeCurve = pathCurve([
...dischargePathPoints,
...chargePathPoints.slice(0, 1)
]);
// -------------------------------------------------------------------------
// Stored-energy voxel column
// -------------------------------------------------------------------------
const energyBlocks = [];
for (let i = 0; i < 12; i++) {
const blockMaterial = materials.cyan.clone();
blockMaterial.transparent = true;
blockMaterial.opacity = 0;
const block = box(
0.42,
0.15,
0.42,
6.76,
0.64 + i * 0.215,
-1.25,
blockMaterial,
scene,
false
);
energyBlocks.push(block);
}
// Receiver crown.
box(0.67, 0.1, 0.67, 6.76, 3.29, -1.25, materials.metal);
box(0.1, 0.27, 0.67, 6.43, 3.17, -1.25, materials.metal);
box(0.1, 0.27, 0.67, 7.09, 3.17, -1.25, materials.metal);
box(0.67, 0.27, 0.1, 6.76, 3.17, -1.58, materials.metal);
box(0.67, 0.27, 0.1, 6.76, 3.17, -0.92, materials.metal);
// -------------------------------------------------------------------------
// Conceptual delayed-energy path: dotted, non-physical
// -------------------------------------------------------------------------
const conceptCurve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(-3.43, 3.77, 0.18),
new THREE.Vector3(0.35, 7.05, -1.38),
new THREE.Vector3(6.76, 3.43, -1.25)
);
const conceptDotMaterial = new THREE.MeshBasicMaterial({
color: 0x7bc9e8,
transparent: true,
opacity: 0.22
});
for (let i = 0; i <= 58; i++) {
const point = conceptCurve.getPoint(i / 58);
const size = i % 4 === 0 ? 0.075 : 0.045;
box(
size,
size,
size,
point.x,
point.y,
point.z,
conceptDotMaterial,
scene,
false
);
}
const packetMeshes = [];
for (let i = 0; i < 9; i++) {
const packetMaterial = materials.white.clone();
packetMaterial.transparent = true;
packetMaterial.opacity = 1;
const packet = box(
0.13,
0.13,
0.13,
0,
0,
0,
packetMaterial,
scene,
false
);
packet.visible = false;
packetMeshes.push(packet);
}
// Current voxels traveling around the separate RC paths.
const chargeCurrentMeshes = [];
const dischargeCurrentMeshes = [];
for (let i = 0; i < 12; i++) {
const currentMaterial = materials.amber.clone();
currentMaterial.transparent = true;
currentMaterial.opacity = 0.95;
const chargeParticle = box(
0.1,
0.1,
0.1,
0,
0,
0,
currentMaterial,
scene,
false
);
const dischargeParticle = box(
0.1,
0.1,
0.1,
0,
0,
0,
currentMaterial.clone(),
scene,
false
);
chargeCurrentMeshes.push(chargeParticle);
dischargeCurrentMeshes.push(dischargeParticle);
}
// -------------------------------------------------------------------------
// World-space labels
// -------------------------------------------------------------------------
const worldLabels = [];
function worldLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`.trim();
element.textContent = text;
document.body.appendChild(element);
worldLabels.push({
element,
position: new THREE.Vector3(...position)
});
}
worldLabel("Stylized Flash Device", [-5, 4.25, 0.15]);
worldLabel("Separate Ideal RC Model", [3.25, 4.2, -1.5]);
worldLabel("Conceptual delay — not a wire", [1.45, 6.08, -1.25], "concept");
worldLabel("Source", [0.96, 2.08, -1.25], "small");
worldLabel("R", [3.3, 1.54, -1.25], "small");
worldLabel("C", [5.1, 2.05, -1.25], "small");
worldLabel("Load", [2.95, 1.65, 1.25], "small");
function updateWorldLabels() {
const width = innerWidth;
const height = innerHeight;
for (const item of worldLabels) {
const projected = item.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
item.element.style.display = visible ? "block" : "none";
if (visible) {
item.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const R_OHMS = 10000;
const C_FARADS = 0.0001;
const TAU = R_OHMS * C_FARADS;
const SOURCE_VOLTAGE = 5;
const CHARGE_DURATION = 4.1;
const DISCHARGE_DURATION = 3.8;
const FULL_CHARGE_VOLTAGE =
SOURCE_VOLTAGE * (1 - Math.exp(-CHARGE_DURATION / TAU));
const phases = [
{ name: "ready", start: 0, end: 0.8 },
{ name: "charging", start: 0.8, end: 0.8 + CHARGE_DURATION },
{ name: "charged", start: 0.8 + CHARGE_DURATION, end: 5.7 },
{ name: "discharging", start: 5.7, end: 5.7 + DISCHARGE_DURATION },
{ name: "reset", start: 9.5, end: 10.0 }
];
const TOTAL_TIME = 10;
let cycleTime = 0;
let playing = true;
let speed = 1;
const stateElement = document.getElementById("state");
const voltageElement = document.getElementById("voltage");
const currentElement = document.getElementById("current");
const voltageFill = document.getElementById("voltageFill");
const currentFill = document.getElementById("currentFill");
const equationElement = document.getElementById("equation");
const playButton = document.getElementById("play");
function getPhase(time) {
for (const phase of phases) {
if (time >= phase.start && time < phase.end) {
return phase;
}
}
return phases[phases.length - 1];
}
function stateAt(time) {
const phase = getPhase(time);
const local = time - phase.start;
let voltage = 0;
let current = 0;
if (phase.name === "charging") {
voltage =
SOURCE_VOLTAGE * (1 - Math.exp(-local / TAU));
current =
(SOURCE_VOLTAGE / R_OHMS) * Math.exp(-local / TAU);
} else if (phase.name === "charged") {
voltage = FULL_CHARGE_VOLTAGE;
current = 0;
} else if (phase.name === "discharging") {
voltage =
FULL_CHARGE_VOLTAGE * Math.exp(-local / TAU);
current = -(voltage / R_OHMS);
} else if (phase.name === "reset") {
voltage =
FULL_CHARGE_VOLTAGE *
Math.exp(-(DISCHARGE_DURATION + local) / TAU);
current = -(voltage / R_OHMS);
}
return { phase, local, voltage, current };
}
function updateSceneState(state) {
const { phase, local, voltage, current } = state;
const voltageRatio = THREE.MathUtils.clamp(
voltage / SOURCE_VOLTAGE,
0,
1
);
const currentRatio = THREE.MathUtils.clamp(
Math.abs(current) / (SOURCE_VOLTAGE / R_OHMS),
0,
1
);
stateElement.textContent = phase.name;
stateElement.dataset.state = phase.name;
voltageElement.textContent = `${voltage.toFixed(2)} V`;
currentElement.textContent = `${(current * 1000).toFixed(3)} mA`;
voltageFill.style.width = `${voltageRatio * 100}%`;
currentFill.style.width = `${currentRatio * 100}%`;
if (phase.name === "charging") {
equationElement.innerHTML =
"Vc(t) = V(1 − e<sup>−t/RC</sup>)<br />" +
"I(t) = (V/R)e<sup>−t/RC</sup>";
} else if (phase.name === "discharging") {
equationElement.innerHTML =
"Vc(t) = V₀e<sup>−t/RC</sup><br />" +
"I(t) = −Vc(t)/R";
} else {
equationElement.innerHTML =
"Two-state RC model<br />" +
"Charge ↔ Hold ↔ Discharge";
}
// Switch positions.
const chargeClosed = phase.name === "charging";
const dischargeClosed = phase.name === "discharging";
chargeSwitch.rotation.z = THREE.MathUtils.lerp(
chargeSwitch.rotation.z,
chargeClosed ? 0 : 0.82,
0.18
);
dischargeSwitch.rotation.z = THREE.MathUtils.lerp(
dischargeSwitch.rotation.z,
dischargeClosed ? 0 : 0.82,
0.18
);
// Current particles.
chargeCurrentMeshes.forEach((particle, index) => {
particle.visible = chargeClosed;
if (!chargeClosed) return;
const progress = (local * 0.42 + index / chargeCurrentMeshes.length) % 1;
const point = chargeCurve.getPoint(progress);
particle.position.copy(point);
particle.position.y += 0.11;
particle.scale.setScalar(0.75 + currentRatio * 0.55);
});
dischargeCurrentMeshes.forEach((particle, index) => {
particle.visible = dischargeClosed;
if (!dischargeClosed) return;
const progress = (local * 0.46 + index / dischargeCurrentMeshes.length) % 1;
const point = dischargeCurve.getPoint(progress);
particle.position.copy(point);
particle.position.y += 0.11;
particle.scale.setScalar(0.72 + currentRatio * 0.65);
});
// Stored-energy column.
energyBlocks.forEach((block, index) => {
const threshold = (index + 0.1) / energyBlocks.length;
const amount = THREE.MathUtils.clamp(
voltageRatio - threshold + 0.18,
0,
1
);
block.material.opacity = amount * 0.95;
block.material.emissiveIntensity = 0.45 + amount * 1.15;
block.scale.y = 0.5 + amount * 0.5;
});
// Device charge bars.
deviceChargeBars.forEach((bar, index) => {
const threshold = (index + 0.5) / deviceChargeBars.length;
const amount = THREE.MathUtils.clamp(
voltageRatio - threshold + 0.2,
0,
1
);
bar.material.opacity = 0.15 + amount * 0.85;
bar.material.emissiveIntensity = 0.2 + amount * 1.1;
});
// Delayed conceptual packets.
const packetTravel = 1.35;
let packetsInTransit = 0;
let arrivalPulse = 0;
packetMeshes.forEach((packet, index) => {
const launch = index * 0.3;
const progress = (local - launch) / packetTravel;
const inFlight = progress >= 0 && progress <= 1;
packet.visible = phase.name === "charging" && inFlight;
if (inFlight) {
packetsInTransit++;
const point = conceptCurve.getPoint(progress);
packet.position.copy(point);
packet.rotation.x += 0.035;
packet.rotation.y += 0.045;
const fade =
Math.min(progress * 8, (1 - progress) * 8, 1);
packet.material.opacity = Math.max(0, fade);
packet.scale.setScalar(0.8 + Math.sin(progress * Math.PI) * 0.45);
}
const arrivalTime = launch + packetTravel;
if (local >= arrivalTime && local < arrivalTime + 0.6) {
arrivalPulse = Math.max(
arrivalPulse,
Math.exp(-(local - arrivalTime) * 9)
);
}
});
// Receiver crown pulse.
materials.metal.emissive = new THREE.Color(0x3fcfff);
materials.metal.emissiveIntensity = arrivalPulse * 1.8;
// Load glows during discharge.
loadMaterial.emissiveIntensity =
dischargeClosed ? 0.45 + currentRatio * 3.4 : 0.25;
loadMaterial.color.set(dischargeClosed ? 0xffd978 : 0xc59434);
// Capacitor plate glow follows stored voltage.
capacitorLeftMaterial.emissive = new THREE.Color(0x2bbdff);
capacitorRightMaterial.emissive = new THREE.Color(0x2bbdff);
capacitorLeftMaterial.emissiveIntensity = 0.08 + voltageRatio * 0.75;
capacitorRightMaterial.emissiveIntensity = 0.08 + voltageRatio * 0.75;
// Stylized flash output: brief bright pulse on discharge.
const flashPulse =
dischargeClosed ? Math.exp(-local * 7.5) : 0;
const flashGlow = flashPulse * 6.5 + currentRatio * 0.35;
flashDiffuserMaterial.emissiveIntensity = flashGlow + 0.25;
flashDiffuserMaterial.color.set(flashPulse > 0.3 ? 0xffffff : 0x53d9ff);
flashLight.intensity = flashPulse * 28;
// Keep a tiny conceptual status in the readout footer.
const transitLabel =
phase.name === "charging"
? `${packetsInTransit} packet${packetsInTransit === 1 ? "" : "s"} in transit`
: phase.name === "discharging"
? "stored charge returning"
: "RC loop";
document.querySelector(".readout-foot").lastElementChild.textContent =
transitLabel;
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
document.getElementById("charge").addEventListener("click", () => {
cycleTime = 0.8;
playing = true;
playButton.textContent = "Pause";
});
document.getElementById("discharge").addEventListener("click", () => {
cycleTime = 5.7;
playing = true;
playButton.textContent = "Pause";
});
document.getElementById("reset").addEventListener("click", () => {
cycleTime = 0;
});
document.getElementById("speed").addEventListener("change", (event) => {
speed = Number(event.target.value);
});
document.getElementById("cameraReset").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
cycleTime += dt * speed;
if (cycleTime >= TOTAL_TIME) {
cycleTime %= TOTAL_TIME;
}
}
// Smooth direct camera controls.
yaw = THREE.MathUtils.lerp(yaw, targetYaw, 0.12);
pitch = THREE.MathUtils.lerp(pitch, targetPitch, 0.12);
radius = THREE.MathUtils.lerp(radius, targetRadius, 0.12);
updateCamera();
updateSceneState(stateAt(cycleTime));
updateWorldLabels();
renderer.render(scene, camera);
}
updateCamera();
updateSceneState(stateAt(cycleTime));
animate();
requestAnimationFrame(() => {
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 260);
});
</script>
</body>
</html>
```