Prompt specification
Build or customize the Three.js 3D scene "Power-source classroom comparison scene" 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: Power-source classroom comparison scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/power-source-classroom-comparison-scene-x1603
Scene Description Prompt:
Compare voxel fictional battery and alternator models powering ideal loads, with current direction and waveforms visible. Three.js from cdnjs, one HTML file.
Working Three.js Starter (power-source-classroom-comparison-scene-x1603):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Current Lab — Battery vs Alternator</title>
<style>
:root {
color-scheme: dark;
--bg: #06101c;
--panel: rgba(10, 24, 39, 0.82);
--border: rgba(145, 213, 255, 0.2);
--cyan: #68f7ff;
--magenta: #ff62d8;
--yellow: #ffd166;
--green: #7cff9b;
--text: #e9f7ff;
--muted: #8ca7ba;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#app,
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: absolute;
z-index: 5;
pointer-events: none;
}
.brand {
top: 22px;
left: 26px;
max-width: 560px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
content: "";
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
top: 25px;
right: 26px;
display: flex;
gap: 17px;
padding: 11px 14px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(8, 20, 34, 0.65);
backdrop-filter: blur(12px);
font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 12px currentColor;
}
.dot.cyan {
color: var(--cyan);
background: var(--cyan);
}
.dot.magenta {
color: var(--magenta);
background: var(--magenta);
}
.scene-chip {
top: 128px;
padding: 7px 10px;
border-left: 2px solid var(--cyan);
background: linear-gradient(90deg, rgba(8, 24, 40, 0.8), transparent);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-chip.dc {
left: 5%;
color: var(--cyan);
}
.scene-chip.ac {
right: 5%;
color: var(--magenta);
border-right: 2px solid var(--magenta);
border-left: 0;
background: linear-gradient(270deg, rgba(8, 24, 40, 0.8), transparent);
text-align: right;
}
.wave-card {
position: absolute;
z-index: 6;
bottom: 22px;
width: min(360px, 29vw);
padding: 13px 14px 12px;
overflow: hidden;
border: 1px solid var(--border);
border-radius: 14px;
background:
linear-gradient(135deg, rgba(104, 247, 255, 0.035), transparent 42%),
var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
}
.wave-card.left {
left: 24px;
}
.wave-card.right {
right: 24px;
}
.wave-card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 20px var(--cyan);
}
.wave-card.right::before {
background: var(--magenta);
box-shadow: 0 0 20px var(--magenta);
}
.wave-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.wave-title {
display: flex;
align-items: center;
gap: 9px;
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.badge {
padding: 5px 7px;
border: 1px solid rgba(104, 247, 255, 0.35);
border-radius: 6px;
color: var(--cyan);
background: rgba(104, 247, 255, 0.08);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.right .badge {
border-color: rgba(255, 98, 216, 0.35);
color: var(--magenta);
background: rgba(255, 98, 216, 0.08);
}
.wave-readout {
color: var(--muted);
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.wave-readout strong {
color: var(--text);
font-size: 12px;
}
canvas.wave {
display: block;
width: 100%;
height: 88px;
border: 1px solid rgba(130, 190, 225, 0.1);
border-radius: 8px;
background: rgba(2, 9, 17, 0.58);
}
.wave-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
color: var(--muted);
font: 600 10px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.equation {
color: #d5efff;
}
.direction {
display: flex;
align-items: center;
gap: 6px;
color: var(--cyan);
white-space: nowrap;
}
.direction .arrow {
display: inline-block;
font-size: 19px;
line-height: 1;
transition: transform 80ms linear, color 80ms linear;
}
.controls {
position: absolute;
z-index: 10;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
transform: translateX(-50%);
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(8, 20, 34, 0.88);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(16px);
}
button {
min-height: 34px;
padding: 0 11px;
border: 1px solid rgba(145, 213, 255, 0.22);
border-radius: 8px;
color: var(--text);
background: rgba(131, 198, 231, 0.07);
cursor: pointer;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(145, 213, 255, 0.55);
background: rgba(131, 198, 231, 0.14);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
}
input[type="range"] {
width: 74px;
accent-color: var(--cyan);
}
#speedValue {
width: 31px;
color: var(--text);
text-align: right;
}
.help {
right: 26px;
bottom: 133px;
color: rgba(173, 204, 221, 0.62);
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-align: right;
}
@media (max-width: 1180px) {
.controls {
top: 22px;
bottom: auto;
}
.legend {
display: none;
}
.help {
bottom: 130px;
}
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.brand h1 {
font-size: 25px;
}
.subtitle {
max-width: 350px;
font-size: 11px;
}
.controls {
top: auto;
bottom: 12px;
gap: 5px;
padding: 6px;
}
button {
min-height: 31px;
padding: 0 8px;
font-size: 9px;
}
.speed-control {
padding: 0 3px;
}
input[type="range"] {
width: 54px;
}
.wave-card {
bottom: 72px;
width: calc(50vw - 20px);
padding: 9px;
}
.wave-card.left {
left: 10px;
}
.wave-card.right {
right: 10px;
}
.wave-head {
margin-bottom: 6px;
}
.wave-title {
font-size: 10px;
}
.badge,
.wave-footer .equation {
display: none;
}
.wave-readout {
font-size: 8px;
}
.wave-readout strong {
font-size: 10px;
}
canvas.wave {
height: 65px;
}
.wave-footer {
justify-content: flex-end;
margin-top: 5px;
font-size: 9px;
}
.scene-chip {
top: 112px;
font-size: 8px;
}
.scene-chip.dc {
left: 12px;
}
.scene-chip.ac {
right: 12px;
}
.help {
display: none;
}
}
@media (max-width: 480px) {
.scene-chip {
display: none;
}
.wave-card {
width: calc(50vw - 14px);
}
.wave-title span:last-child {
display: none;
}
#flowButton {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<div id="viewport"></div>
<header class="hud brand">
<div class="eyebrow">Voltage Lab / Voxel Comparison</div>
<h1>One load. Two currents.</h1>
<p class="subtitle">
Fictional VX-8 battery and AX-2 alternator powering identical ideal
2 Ω loads. Drag to orbit; scroll to zoom.
</p>
</header>
<div class="hud legend">
<div class="legend-item">
<span class="dot cyan"></span>
<span>FORWARD CURRENT</span>
</div>
<div class="legend-item">
<span class="dot magenta"></span>
<span>REVERSED CURRENT</span>
</div>
</div>
<div class="hud scene-chip dc">01 / Constant voltage source</div>
<div class="hud scene-chip ac">02 / Alternating voltage source</div>
<section class="wave-card left">
<div class="wave-head">
<div class="wave-title">
<span class="badge">DC</span>
<span>BATTERY LINK</span>
</div>
<div class="wave-readout">
I = <strong>4.00 A</strong>
</div>
</div>
<canvas
class="wave"
id="dcWave"
aria-label="Constant direct current waveform"
></canvas>
<div class="wave-footer">
<span class="equation">I = V/R = 8/2</span>
<span class="direction">
<span class="arrow">→</span>
<span>ONE DIRECTION</span>
</span>
</div>
</section>
<section class="wave-card right">
<div class="wave-head">
<div class="wave-title">
<span class="badge">AC</span>
<span>ALTERNATOR LINK</span>
</div>
<div class="wave-readout">
i = <strong id="acValue">0.00 A</strong>
</div>
</div>
<canvas
class="wave"
id="acWave"
aria-label="Alternating current sine waveform"
></canvas>
<div class="wave-footer">
<span class="equation">i(t) = 4 sin(4πt), RMS = 2.83 A</span>
<span class="direction" id="acDirectionBox">
<span class="arrow" id="acArrow">→</span>
<span id="acDirection">FORWARD</span>
</span>
</div>
</section>
<div class="controls">
<button id="pauseButton" type="button">PAUSE</button>
<div class="speed-control">
<span>SPEED</span>
<input
id="speedSlider"
type="range"
min="0.25"
max="2"
value="1"
step="0.05"
aria-label="Simulation speed"
/>
<span id="speedValue">1.0×</span>
</div>
<button id="flowButton" type="button" aria-pressed="true">FLOW ON</button>
<button id="resetButton" type="button">RESET CAM</button>
</div>
<div class="hud help">
DRAG / ORBIT · WHEEL / ZOOM<br />
SPACE / PAUSE · R / RESET
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const dcCanvas = document.querySelector("#dcWave");
const acCanvas = document.querySelector("#acWave");
const acValue = document.querySelector("#acValue");
const acDirection = document.querySelector("#acDirection");
const acDirectionBox = document.querySelector("#acDirectionBox");
const acArrow = document.querySelector("#acArrow");
const pauseButton = document.querySelector("#pauseButton");
const speedSlider = document.querySelector("#speedSlider");
const speedValue = document.querySelector("#speedValue");
const flowButton = document.querySelector("#flowButton");
const resetButton = document.querySelector("#resetButton");
const COLORS = {
cyan: 0x68f7ff,
cyanDark: 0x117f9c,
magenta: 0xff62d8,
magentaDark: 0x8e2d7e,
yellow: 0xffd166,
green: 0x7cff9b,
red: 0xff5f6d,
blue: 0x4287ff,
navy: 0x102b46,
steel: 0x526679,
darkSteel: 0x1c2a39,
copper: 0xd88942,
cream: 0xdce5e8,
black: 0x08111c
};
// Renderer ---------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel battery and alternator electrical comparison"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06101c);
scene.fog = new THREE.Fog(0x06101c, 22, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const orbit = {
theta: 0.08,
phi: 1.02,
radius: 20,
zoom: 1
};
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
orbit.theta = 0.08;
orbit.phi = 1.02;
orbit.radius = 20;
orbit.zoom = 1;
updateCamera();
}
// Lighting ---------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc8edff, 0x08101c, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(6, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3b9cff, 1.5);
rimLight.position.set(-9, 6, -8);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(COLORS.cyan, 18, 9, 2);
cyanLight.position.set(-4.5, 3.8, 2.2);
scene.add(cyanLight);
const magentaLight = new THREE.PointLight(COLORS.magenta, 16, 9, 2);
magentaLight.position.set(5.4, 3.8, 1.8);
scene.add(magentaLight);
// Voxel primitives -------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitEdges = new THREE.EdgesGeometry(unitBox);
function block(
parent,
size,
position,
color,
options = {}
) {
const {
edge = false,
emissive = 0x000000,
emissiveIntensity = 0,
metalness = 0,
roughness = 0.72,
castShadow = true,
receiveShadow = true
} = options;
const material = new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity,
metalness,
roughness
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
if (edge) {
const outline = new THREE.LineSegments(
unitEdges,
new THREE.LineBasicMaterial({
color: 0x020711,
transparent: true,
opacity: 0.52
})
);
outline.scale.copy(mesh.scale);
outline.position.copy(mesh.position);
parent.add(outline);
}
return mesh;
}
function makeCanvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabelSprite(title, subtitle, accent = COLORS.cyan) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 630, 170, 22);
ctx.fillStyle = "rgba(6, 18, 31, 0.91)";
ctx.fill();
ctx.strokeStyle = "rgba(165, 221, 247, 0.35)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = `#${new THREE.Color(accent).getHexString()}`;
ctx.fillRect(24, 25, 8, 130);
ctx.shadowColor = ctx.fillStyle;
ctx.shadowBlur = 18;
ctx.fillRect(24, 25, 8, 130);
ctx.shadowBlur = 0;
ctx.fillStyle = "#edf9ff";
ctx.font = "800 39px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(title, 52, 78);
ctx.fillStyle = "#91adbf";
ctx.font = "600 23px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(subtitle, 52, 121);
const texture = makeCanvasTexture(canvas);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.65, 1.03, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTerminalSprite(symbol, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(64, 64, 49, 0, Math.PI * 2);
ctx.fillStyle = "rgba(4, 13, 24, 0.92)";
ctx.fill();
ctx.strokeStyle = `#${new THREE.Color(color).getHexString()}`;
ctx.lineWidth = 8;
ctx.stroke();
ctx.fillStyle = `#${new THREE.Color(color).getHexString()}`;
ctx.font = "900 68px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(symbol, 64, 67);
const material = new THREE.SpriteMaterial({
map: makeCanvasTexture(canvas),
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.5, 0.5, 1);
sprite.renderOrder = 21;
return sprite;
}
// Environment -----------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(31, 19),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.93,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x23465c, 0x142c3e);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
block(
scene,
[9.2, 0.12, 4.2],
[-3.7, 0.06, 0],
0x0d2233,
{ edge: true }
);
block(
scene,
[9.25, 0.12, 4.2],
[5.7, 0.06, 0],
0x182033,
{ edge: true }
);
block(
scene,
[0.07, 0.018, 3.8],
[0.85, 0.135, 0],
COLORS.steel,
{ metalness: 0.7, roughness: 0.35 }
);
// Fictional battery -----------------------------------------------------
function makeBattery() {
const group = new THREE.Group();
group.position.set(-5.2, 0.13, -0.9);
scene.add(group);
block(group, [3.15, 0.24, 2.18], [0, 0.12, 0], 0x172a3c, {
edge: true,
metalness: 0.35
});
const cellColors = [0x145275, 0x17648a, 0x1b7097];
for (let x = 0; x < 3; x++) {
for (let y = 0; y < 3; y++) {
for (let z = 0; z < 2; z++) {
block(
group,
[0.62, 0.58, 0.64],
[
(x - 1) * 0.68,
0.61 + y * 0.65,
(z - 0.5) * 0.7
],
cellColors[(x + y + z) % cellColors.length],
{ edge: true, metalness: 0.18, roughness: 0.56 }
);
}
}
}
block(group, [2.38, 0.16, 1.76], [0, 2.07, 0], 0x0d314a, {
edge: true
});
block(group, [1.75, 0.12, 0.78], [0, 2.19, 0], 0x287ca0, {
edge: true
});
// Front cell seams and status lights.
for (let x = -1; x <= 1; x++) {
block(
group,
[0.08, 1.76, 0.055],
[x * 0.68, 1.25, 0.71],
0x09273b
);
}
for (let i = 0; i < 5; i++) {
block(
group,
[0.18, 0.09, 0.07],
[-0.74 + i * 0.37, 1.61, 0.755],
COLORS.green,
{
emissive: COLORS.green,
emissiveIntensity: 1.4,
castShadow: false
}
);
}
// Pixel lightning emblem.
const boltPixels = [
[0.06, 0.31, 0.3, 0.16],
[-0.02, 0.17, 0.3, 0.16],
[-0.1, 0.03, 0.3, 0.16],
[-0.18, -0.11, 0.3, 0.16],
[-0.1, -0.25, 0.3, 0.16]
];
boltPixels.forEach(([x, y, w, h]) => {
block(
group,
[w, h, 0.065],
[x, 1.1 + y, 0.76],
COLORS.yellow,
{
emissive: COLORS.yellow,
emissiveIntensity: 0.9,
castShadow: false
}
);
});
// Terminals.
block(group, [0.3, 0.28, 0.34], [0.7, 2.45, 0], COLORS.red, {
edge: true,
emissive: COLORS.red,
emissiveIntensity: 0.35
});
block(group, [0.3, 0.28, 0.34], [-0.7, 2.45, 0], COLORS.blue, {
edge: true,
emissive: COLORS.blue,
emissiveIntensity: 0.35
});
block(group, [0.2, 0.16, 0.2], [0.7, 2.64, 0], 0xcbd7dc, {
metalness: 0.8,
roughness: 0.3
});
block(group, [0.2, 0.16, 0.2], [-0.7, 2.64, 0], 0xcbd7dc, {
metalness: 0.8,
roughness: 0.3
});
const plus = makeTerminalSprite("+", COLORS.red);
plus.position.set(0.7, 3.03, 0);
group.add(plus);
const minus = makeTerminalSprite("−", COLORS.blue);
minus.position.set(-0.7, 3.03, 0);
group.add(minus);
const label = makeLabelSprite(
"VX-8 CELL",
"FICTIONAL DC SOURCE / 8.0 V",
COLORS.cyan
);
label.position.set(0, 3.58, 0);
group.add(label);
const smallLabel = makeLabelSprite(
"8 V",
"REGULATED",
COLORS.yellow
);
smallLabel.scale.set(1.45, 0.41, 1);
smallLabel.position.set(0.83, 1.12, 0.78);
group.add(smallLabel);
return {
group,
positiveLocal: new THREE.Vector3(0.7, 2.64, 0),
negativeLocal: new THREE.Vector3(-0.7, 2.64, 0)
};
}
// Ideal load ------------------------------------------------------------
function makeIdealLoad(x, z, accent, labelText) {
const group = new THREE.Group();
group.position.set(x, 0.13, z);
scene.add(group);
block(group, [2.05, 0.18, 1.25], [0, 0.09, 0], 0x1a2938, {
edge: true,
metalness: 0.35
});
const core = block(
group,
[1.32, 0.7, 0.8],
[0, 0.54, 0],
0xcbd7d8,
{
edge: true,
emissive: accent,
emissiveIntensity: 0.04,
roughness: 0.48
}
);
for (let i = -1; i <= 1; i++) {
block(
group,
[0.09, 0.76, 0.86],
[i * 0.4, 0.54, 0],
0x223344,
{ edge: true }
);
}
const glow = block(
group,
[0.78, 0.075, 0.12],
[0, 0.95, 0],
accent,
{
emissive: accent,
emissiveIntensity: 1,
castShadow: false
}
);
block(group, [0.24, 0.24, 0.28], [-0.82, 0.54, 0], COLORS.red, {
edge: true,
emissive: COLORS.red,
emissiveIntensity: 0.25
});
block(group, [0.24, 0.24, 0.28], [0.82, 0.54, 0], COLORS.blue, {
edge: true,
emissive: COLORS.blue,
emissiveIntensity: 0.25
});
const label = makeLabelSprite(
labelText,
"IDEAL RESISTIVE LOAD / R = 2 Ω",
accent
);
label.scale.set(2.65, 0.75, 1);
label.position.set(0, 1.55, 0);
group.add(label);
return {
group,
core,
glow,
leftLocal: new THREE.Vector3(-0.82, 0.54, 0),
rightLocal: new THREE.Vector3(0.82, 0.54, 0)
};
}
// Fictional alternator --------------------------------------------------
function makeAlternator() {
const group = new THREE.Group();
group.position.set(3.55, 0.13, -1.0);
scene.add(group);
block(group, [3.85, 0.24, 2.7], [0, 0.12, 0], 0x202a39, {
edge: true,
metalness: 0.45
});
// Block-built housing around the rotor.
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const housing = block(
group,
[1.72, 0.38, 0.38],
[
0,
1.48 + Math.cos(angle) * 1.08,
Math.sin(angle) * 1.08
],
i % 2 ? 0x4c5d6d : 0x3b4b5c,
{
edge: true,
metalness: 0.52,
roughness: 0.5
}
);
housing.rotation.x = angle;
}
// Copper stator blocks.
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const winding = block(
group,
[1.32, 0.26, 0.26],
[
0,
1.48 + Math.cos(angle) * 0.76,
Math.sin(angle) * 0.76
],
i % 2 ? COLORS.copper : 0xb86532,
{
edge: true,
metalness: 0.7,
roughness: 0.38
}
);
winding.rotation.x = angle;
}
// Rotor, rotating around the X axis.
const rotor = new THREE.Group();
rotor.position.set(0, 1.48, 0);
group.add(rotor);
block(
rotor,
[2.95, 0.19, 0.19],
[0, 0, 0],
0xb9c5cc,
{
edge: true,
metalness: 0.9,
roughness: 0.25
}
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const rotorBlock = block(
rotor,
[1.46, 0.24, 0.24],
[
0,
Math.cos(angle) * 0.47,
Math.sin(angle) * 0.47
],
i % 2 ? 0xf09b42 : COLORS.copper,
{
edge: true,
emissive: 0x3b1305,
emissiveIntensity: 0.15,
metalness: 0.62,
roughness: 0.38
}
);
rotorBlock.rotation.x = angle;
}
// A bright rotor key makes rotation easy to see.
block(
rotor,
[0.28, 0.18, 0.34],
[0.25, 0.48, 0],
COLORS.yellow,
{
emissive: COLORS.yellow,
emissiveIntensity: 1.8,
castShadow: false
}
);
// End supports and feet.
block(group, [0.28, 1.55, 0.42], [-1.15, 1.3, 0], 0x344555, {
edge: true,
metalness: 0.5
});
block(group, [0.28, 1.55, 0.42], [1.15, 1.3, 0], 0x344555, {
edge: true,
metalness: 0.5
});
block(group, [0.8, 0.62, 1.55], [0.72, 2.54, -0.08], 0x26394b, {
edge: true,
metalness: 0.38
});
block(group, [0.24, 0.24, 0.28], [0.9, 2.64, -0.05], COLORS.red, {
edge: true,
emissive: COLORS.red,
emissiveIntensity: 0.35
});
block(group, [0.24, 0.24, 0.28], [1.45, 2.64, 0.05], COLORS.blue, {
edge: true,
emissive: COLORS.blue,
emissiveIntensity: 0.35
});
const plus = makeTerminalSprite("+", COLORS.red);
plus.position.set(0.9, 3.03, -0.05);
group.add(plus);
const minus = makeTerminalSprite("−", COLORS.blue);
minus.position.set(1.45, 3.03, 0.05);
group.add(minus);
const label = makeLabelSprite(
"AX-2 FIELD",
"FICTIONAL AC SOURCE / 4 A PEAK",
COLORS.magenta
);
label.position.set(0, 3.58, 0);
group.add(label);
return {
group,
rotor,
positiveLocal: new THREE.Vector3(0.9, 2.64, -0.05),
negativeLocal: new THREE.Vector3(1.45, 2.64, 0.05)
};
}
const battery = makeBattery();
const dcLoad = makeIdealLoad(-1.5, 1.15, COLORS.cyan, "DC LOAD");
const alternator = makeAlternator();
const acLoad = makeIdealLoad(7.25, 1.15, COLORS.magenta, "AC LOAD");
scene.updateMatrixWorld(true);
function worldPoint(object, localPoint) {
return object.localToWorld(localPoint.clone());
}
const batteryPositive = worldPoint(battery.group, battery.positiveLocal);
const batteryNegative = worldPoint(battery.group, battery.negativeLocal);
const dcLoadLeft = worldPoint(dcLoad.group, dcLoad.leftLocal);
const dcLoadRight = worldPoint(dcLoad.group, dcLoad.rightLocal);
const alternatorPositive = worldPoint(
alternator.group,
alternator.positiveLocal
);
const alternatorNegative = worldPoint(
alternator.group,
alternator.negativeLocal
);
const acLoadLeft = worldPoint(acLoad.group, acLoad.leftLocal);
const acLoadRight = worldPoint(acLoad.group, acLoad.rightLocal);
const dcCurve = new THREE.CatmullRomCurve3(
[
batteryPositive,
new THREE.Vector3(-3.9, 3.13, 0.0),
new THREE.Vector3(-2.95, 2.45, 0.8),
dcLoadLeft,
dcLoadRight,
new THREE.Vector3(-0.15, 0.52, 0.45),
new THREE.Vector3(-1.2, 0.42, -1.25),
new THREE.Vector3(-3.8, 0.42, -2.18),
batteryNegative,
new THREE.Vector3(-5.3, 2.55, -0.9),
batteryPositive
],
true,
"catmullrom",
0.25
);
const acCurve = new THREE.CatmullRomCurve3(
[
alternatorPositive,
new THREE.Vector3(5.0, 3.18, -0.08),
new THREE.Vector3(5.82, 2.48, 0.8),
acLoadLeft,
acLoadRight,
new THREE.Vector3(8.7, 0.52, 0.42),
new THREE.Vector3(7.25, 0.42, -1.3),
new THREE.Vector3(5.75, 0.42, -2.2),
alternatorNegative,
new THREE.Vector3(4.72, 2.58, -1.0),
alternatorPositive
],
true,
"catmullrom",
0.25
);
// Pixel-style current arrows --------------------------------------------
function makePixelArrow() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: COLORS.cyan,
emissive: COLORS.cyan,
emissiveIntensity: 2.2,
roughness: 0.28,
metalness: 0.1
});
const pixels = [
[-0.18, 0],
[-0.06, 0],
[0.05, 0],
[0.14, 0],
[0.04, 0.09],
[0.12, 0.1],
[0.04, -0.09],
[0.12, -0.1]
];
pixels.forEach(([x, y]) => {
const pixel = new THREE.Mesh(unitBox, material);
pixel.scale.set(0.1, 0.1, 0.1);
pixel.position.set(x, y, 0);
group.add(pixel);
});
group.userData.material = material;
group.scale.setScalar(1.35);
return group;
}
function createFlow(curve, alternating = false) {
const group = new THREE.Group();
scene.add(group);
const baseWire = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 0.036, 7, true),
new THREE.MeshStandardMaterial({
color: 0x33495b,
roughness: 0.46,
metalness: 0.68
})
);
baseWire.castShadow = true;
group.add(baseWire);
const currentGroup = new THREE.Group();
group.add(currentGroup);
const signalMaterial = new THREE.MeshBasicMaterial({
color: alternating ? COLORS.magenta : COLORS.cyan,
transparent: true,
opacity: 0.25,
depthWrite: false,
toneMapped: false
});
const signal = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 0.064, 7, true),
signalMaterial
);
currentGroup.add(signal);
const markers = [];
const markerCount = alternating ? 24 : 20;
for (let i = 0; i < markerCount; i++) {
const material = new THREE.MeshBasicMaterial({
color: alternating ? COLORS.magenta : COLORS.cyan,
toneMapped: false
});
const marker = new THREE.Mesh(unitBox, material);
marker.scale.setScalar(alternating ? 0.105 : 0.12);
marker.castShadow = false;
currentGroup.add(marker);
markers.push(marker);
}
const arrows = [];
const arrowPositions = alternating
? [0.055, 0.12, 0.19, 0.26, 0.57, 0.65, 0.73, 0.8]
: [0.075, 0.15, 0.225, 0.59, 0.67, 0.75];
arrowPositions.forEach((u) => {
const arrow = makePixelArrow();
currentGroup.add(arrow);
arrows.push({ arrow, u });
});
return {
group,
currentGroup,
signalMaterial,
markers,
arrows,
alternating
};
}
const dcFlow = createFlow(dcCurve, false);
const acFlow = createFlow(acCurve, true);
const xAxis = new THREE.Vector3(1, 0, 0);
function updateFlow(flow, time, phase) {
const current = flow.alternating
? Math.sin(phase)
: 1;
const direction = current >= 0 ? 1 : -1;
const color = direction > 0 ? COLORS.cyan : COLORS.magenta;
flow.signalMaterial.color.setHex(color);
flow.signalMaterial.opacity = flow.alternating ? 0.33 : 0.22;
flow.markers.forEach((marker, index) => {
let u;
if (flow.alternating) {
// The integral of sine gives reversible motion around the circuit.
u =
(index / flow.markers.length +
(1 - Math.cos(phase)) * 0.42) %
1;
} else {
u = (index / flow.markers.length + time * 0.052) % 1;
}
marker.position.copy(flow.curve?.getPointAt?.(u) ?? curvePoint(u));
marker.material.color.setHex(color);
});
flow.arrows.forEach(({ arrow, u }) => {
const point = curvePoint(flow === dcFlow ? dcCurve : acCurve, u);
const tangent = (
flow === dcFlow ? dcCurve : acCurve
).getTangentAt(u);
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(
xAxis,
tangent.clone().multiplyScalar(direction).normalize()
);
const material = arrow.userData.material;
material.color.setHex(color);
material.emissive.setHex(color);
material.emissiveIntensity = 2.3;
});
}
// Helpers kept separate so both flows share identical point calculations.
function curvePoint(curve, u) {
return curve.getPointAt(((u % 1) + 1) % 1);
}
// The first implementation above intentionally uses a stable fallback;
// overwrite marker positions with explicit curve-specific values.
function updateFlowCurves(flow, time, phase) {
const curve = flow === dcFlow ? dcCurve : acCurve;
const current = flow.alternating ? Math.sin(phase) : 1;
const direction = current >= 0 ? 1 : -1;
const color = direction > 0 ? COLORS.cyan : COLORS.magenta;
flow.signalMaterial.color.setHex(color);
flow.signalMaterial.opacity = flow.alternating ? 0.33 : 0.22;
flow.markers.forEach((marker, index) => {
let u;
if (flow.alternating) {
u =
(index / flow.markers.length +
(1 - Math.cos(phase)) * 0.42) %
1;
} else {
u = (index / flow.markers.length + time * 0.052) % 1;
}
marker.position.copy(curve.getPointAt(u));
marker.material.color.setHex(color);
});
flow.arrows.forEach(({ arrow, u }) => {
const point = curve.getPointAt(u);
const tangent = curve.getTangentAt(u);
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(
xAxis,
tangent.multiplyScalar(direction).normalize()
);
const material = arrow.userData.material;
material.color.setHex(color);
material.emissive.setHex(color);
material.emissiveIntensity = 2.3;
});
}
// Background voxel motes ------------------------------------------------
const moteGroup = new THREE.Group();
scene.add(moteGroup);
const moteMaterial = new THREE.MeshBasicMaterial({
color: 0x31546b,
transparent: true,
opacity: 0.38,
toneMapped: false
});
const moteMesh = new THREE.InstancedMesh(unitBox, moteMaterial, 42);
const moteMatrix = new THREE.Matrix4();
const motePosition = new THREE.Vector3();
const moteScale = new THREE.Vector3();
const moteQuaternion = new THREE.Quaternion();
let seed = 9481;
function seededRandom() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 42; i++) {
motePosition.set(
-13 + seededRandom() * 26,
1.2 + seededRandom() * 7,
-7 - seededRandom() * 3
);
const s = 0.025 + seededRandom() * 0.055;
moteScale.set(s, s, s);
moteMatrix.compose(motePosition, moteQuaternion, moteScale);
moteMesh.setMatrixAt(i, moteMatrix);
}
moteMesh.instanceMatrix.needsUpdate = true;
moteGroup.add(moteMesh);
// Waveform rendering ----------------------------------------------------
function prepareCanvas(canvas) {
const rect = canvas.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(1, Math.floor(rect.width));
const height = Math.max(1, Math.floor(rect.height));
const targetWidth = Math.floor(width * dpr);
const targetHeight = Math.floor(height * dpr);
if (canvas.width !== targetWidth || canvas.height !== targetHeight) {
canvas.width = targetWidth;
canvas.height = targetHeight;
}
const ctx = canvas.getContext("2d");
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, width, height);
return { ctx, width, height };
}
function drawGrid(ctx, width, height) {
ctx.strokeStyle = "rgba(120, 178, 207, 0.09)";
ctx.lineWidth = 1;
for (let x = 0; x <= width; x += width / 6) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
ctx.stroke();
}
for (let y = 0; y <= height; y += height / 4) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
}
function drawDCWave(time) {
const { ctx, width, height } = prepareCanvas(dcCanvas);
drawGrid(ctx, width, height);
const y = height * 0.48;
const gradient = ctx.createLinearGradient(0, 0, width, 0);
gradient.addColorStop(0, "rgba(104,247,255,0.12)");
gradient.addColorStop(0.5, "rgba(104,247,255,0.75)");
gradient.addColorStop(1, "rgba(104,247,255,0.12)");
ctx.strokeStyle = gradient;
ctx.lineWidth = 2.5;
ctx.shadowColor = "#68f7ff";
ctx.shadowBlur = 10;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
ctx.shadowBlur = 0;
const markerX = (time * 0.17) % 1 * width;
ctx.fillStyle = "#d8fdff";
ctx.shadowColor = "#68f7ff";
ctx.shadowBlur = 14;
ctx.beginPath();
ctx.arc(markerX, y, 3.5, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = "rgba(169, 207, 224, 0.7)";
ctx.font = "700 9px ui-monospace, monospace";
ctx.fillText("4 A", 8, 13);
ctx.fillText("t", width - 10, height - 7);
}
function drawACWave(phase) {
const { ctx, width, height } = prepareCanvas(acCanvas);
drawGrid(ctx, width, height);
const zero = height * 0.56;
const amplitude = height * 0.29;
const cycles = 2;
const pointAt = (x) => ({
x,
y:
zero -
Math.sin(phase + (x / width) * Math.PI * 2 * cycles) *
amplitude
});
// Soft filled area under the waveform.
const fill = ctx.createLinearGradient(0, 0, 0, height);
fill.addColorStop(0, "rgba(255,98,216,0.12)");
fill.addColorStop(1, "rgba(255,98,216,0)");
ctx.fillStyle = fill;
ctx.beginPath();
ctx.moveTo(0, zero);
for (let x = 0; x <= width; x += 2) {
const p = pointAt(x);
ctx.lineTo(p.x, p.y);
}
ctx.lineTo(width, zero);
ctx.closePath();
ctx.fill();
// Draw positive and negative portions in different colors.
for (let x = 0; x < width - 2; x += 2) {
const p1 = pointAt(x);
const p2 = pointAt(x + 2);
const value = Math.sin(phase + (x / width) * Math.PI * 2 * cycles);
ctx.strokeStyle = value >= 0 ? "#68f7ff" : "#ff62d8";
ctx.shadowColor = ctx.strokeStyle;
ctx.shadowBlur = 8;
ctx.lineWidth = 2.2;
ctx.beginPath();
ctx.moveTo(p1.x, p1.y);
ctx.lineTo(p2.x, p2.y);
ctx.stroke();
}
ctx.shadowBlur = 0;
const probeX = width * 0.72;
const probe = pointAt(probeX);
ctx.strokeStyle = "rgba(230,248,255,0.26)";
ctx.setLineDash([3, 4]);
ctx.beginPath();
ctx.moveTo(probeX, 0);
ctx.lineTo(probeX, height);
ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = "#ffffff";
ctx.shadowColor = "#ff62d8";
ctx.shadowBlur = 12;
ctx.beginPath();
ctx.arc(probe.x, probe.y, 3.6, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = "rgba(194, 215, 226, 0.75)";
ctx.font = "700 9px ui-monospace, monospace";
ctx.fillText("+4 A", 7, 13);
ctx.fillText("0", 7, zero + 3);
ctx.fillText("−4 A", 7, height - 6);
}
// Controls --------------------------------------------------------------
let paused = false;
let simulationSpeed = 1;
let flowEnabled = true;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
});
speedSlider.addEventListener("input", () => {
simulationSpeed = Number(speedSlider.value);
speedValue.textContent = `${simulationSpeed.toFixed(1)}×`;
});
flowButton.addEventListener("click", () => {
flowEnabled = !flowEnabled;
dcFlow.currentGroup.visible = flowEnabled;
acFlow.currentGroup.visible = flowEnabled;
flowButton.textContent = flowEnabled ? "FLOW ON" : "FLOW OFF";
flowButton.setAttribute("aria-pressed", String(flowEnabled));
});
resetButton.addEventListener("click", resetCamera);
// Direct camera controls, implemented without external addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.38,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * (event.deltaY > 0 ? 0.9 : 1.1),
0.68,
1.75
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const viewHeight = aspect < 1.05 ? 24 / aspect : 13.2;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Simulation loop -------------------------------------------------------
let simulationTime = 0;
let previousTime = performance.now();
function animate(now) {
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (!paused) {
simulationTime += delta * simulationSpeed;
}
const frequency = 2;
const phase = simulationTime * Math.PI * 2 * frequency;
const acCurrent = Math.sin(phase);
alternator.rotor.rotation.x = phase;
updateFlowCurves(dcFlow, simulationTime, phase);
updateFlowCurves(acFlow, simulationTime, phase);
// Ideal-load visual response.
dcLoad.glow.material.emissiveIntensity = 1.7;
dcLoad.core.material.emissiveIntensity = 0.055;
const acPower = Math.abs(acCurrent);
acLoad.glow.material.emissiveIntensity = 0.18 + acPower * 2.0;
acLoad.core.material.emissiveIntensity = 0.025 + acPower * 0.12;
const displayCurrent = Math.abs(acCurrent) < 0.00125 ? 0 : 4 * acCurrent;
acValue.textContent = `${displayCurrent >= 0 ? "+" : ""}${displayCurrent.toFixed(2)} A`;
acDirection.textContent = displayCurrent >= 0 ? "FORWARD" : "REVERSE";
acDirectionBox.style.color =
displayCurrent >= 0 ? "#68f7ff" : "#ff62d8";
acArrow.style.transform =
displayCurrent >= 0 ? "scaleX(1)" : "scaleX(-1)";
drawDCWave(simulationTime);
drawACWave(phase);
moteGroup.rotation.y = simulationTime * 0.018;
moteGroup.position.y = Math.sin(simulationTime * 0.3) * 0.05;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```