Prompt specification
Build or customize the Three.js 3D scene "Expanding spherical wave shell" 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: Expanding spherical wave shell
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/expanding-spherical-wave-shell-x1553
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the inverse-square relationship for a point source. Build concentric transparent shells around a point source with equal total power distributed over each surface; label the ideal isotropic lossless assumption. Low-poly.
Working Three.js Starter (expanding-spherical-wave-shell-x1553):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Inverse-Square Point Source</title>
<style>
:root {
color-scheme: dark;
--bg: #050a12;
--panel: rgba(9, 18, 31, 0.76);
--panel-border: rgba(133, 205, 255, 0.16);
--text: #eaf7ff;
--muted: #91a9bb;
--cyan: #62e6ff;
--blue: #6e9cff;
--violet: #b984ff;
--gold: #ffe3a3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 46%, #12273b 0%, #08111d 34%, #03070d 74%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 6;
top: 26px;
left: 30px;
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.24em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(27px, 3.2vw, 46px);
font-weight: 560;
letter-spacing: -0.045em;
line-height: 1;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.02em;
}
.panel {
border: 1px solid var(--panel-border);
border-radius: 16px;
background:
linear-gradient(145deg, rgba(22, 43, 62, 0.62), rgba(7, 14, 24, 0.82)),
var(--panel);
box-shadow:
0 20px 55px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(15px) saturate(125%);
-webkit-backdrop-filter: blur(15px) saturate(125%);
}
#model-panel {
position: fixed;
z-index: 7;
top: 154px;
left: 30px;
width: min(340px, calc(100vw - 60px));
padding: 18px;
}
.assumption-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 17px;
padding: 7px 10px;
border: 1px solid rgba(98, 230, 255, 0.22);
border-radius: 999px;
background: rgba(46, 190, 225, 0.08);
color: #bdefff;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.assumption-badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
content: "";
}
.formula {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-style: italic;
letter-spacing: -0.02em;
}
.formula span {
color: var(--cyan);
font-family: inherit;
}
.formula-note {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.conservation {
margin: 16px 0;
padding: 12px 13px;
border-left: 2px solid var(--cyan);
background: rgba(98, 230, 255, 0.055);
color: #c9e8f6;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
}
.assumption-note {
margin: 0 0 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.power-control {
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.075);
}
.power-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#power-output {
color: var(--gold);
font-size: 12px;
letter-spacing: 0.04em;
}
#power-slider {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
appearance: none;
background: linear-gradient(90deg, #58dcff, #7b83ff, #b57cff);
cursor: pointer;
}
#power-slider::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid #dff8ff;
border-radius: 50%;
appearance: none;
background: #17364c;
box-shadow: 0 0 14px rgba(98, 230, 255, 0.7);
}
#power-slider::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #dff8ff;
border-radius: 50%;
background: #17364c;
box-shadow: 0 0 14px rgba(98, 230, 255, 0.7);
}
#audit-panel {
position: fixed;
z-index: 7;
top: 26px;
right: 30px;
width: 330px;
padding: 17px;
}
.audit-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.audit-header h2 {
margin: 0 0 4px;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.audit-header p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.equal-badge {
flex: 0 0 auto;
padding: 5px 8px;
border: 1px solid rgba(255, 227, 163, 0.25);
border-radius: 7px;
background: rgba(255, 227, 163, 0.07);
color: var(--gold);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.audit-row {
padding: 11px 0;
border-top: 1px solid rgba(255, 255, 255, 0.065);
}
.audit-head,
.audit-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.audit-head {
color: #dff5ff;
font-size: 12px;
}
.audit-head i {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--tone);
box-shadow: 0 0 10px var(--tone);
}
.audit-head b {
font-weight: 650;
}
.audit-head .total {
color: var(--gold);
font-size: 11px;
font-weight: 650;
}
.audit-meta {
margin: 5px 0 7px;
color: var(--muted);
font-size: 10px;
}
.meter {
height: 3px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.075);
}
.meter span {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--tone), color-mix(in srgb, var(--tone), white 32%));
box-shadow: 0 0 10px var(--tone);
transition: width 180ms ease;
}
.bottom-ui {
position: fixed;
z-index: 7;
right: 30px;
bottom: 24px;
left: 30px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.toolbar,
.legend {
pointer-events: auto;
}
.toolbar {
display: flex;
align-items: center;
gap: 6px;
padding: 7px;
}
.toolbar button {
min-height: 34px;
padding: 0 12px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--muted);
font-size: 11px;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
.toolbar button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.045);
}
.toolbar button.active {
border-color: rgba(98, 230, 255, 0.2);
background: rgba(98, 230, 255, 0.09);
color: #c9f4ff;
}
.toolbar .separator {
width: 1px;
height: 21px;
margin: 0 2px;
background: rgba(255, 255, 255, 0.09);
}
.legend {
max-width: 470px;
padding: 11px 14px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.legend strong {
color: #d9effa;
font-weight: 650;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.legend-symbol {
width: 8px;
height: 8px;
border: 1px solid var(--cyan);
border-radius: 50%;
background: rgba(98, 230, 255, 0.25);
}
.legend-symbol.packet {
width: 5px;
height: 5px;
border: 0;
background: #e7fbff;
box-shadow: 0 0 8px #7aeaff;
}
.legend-symbol.ray {
width: 13px;
height: 1px;
border: 0;
border-radius: 0;
background: #73dfff;
box-shadow: none;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.source-label,
.shell-tag {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
transition: opacity 100ms ease;
}
.source-label {
padding: 7px 10px;
border: 1px solid rgba(255, 227, 163, 0.22);
border-radius: 8px;
background: rgba(12, 18, 24, 0.76);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.source-label span {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.15em;
}
.source-label b {
color: var(--gold);
font-size: 11px;
}
.shell-tag {
padding: 5px 8px;
border: 1px solid color-mix(in srgb, var(--tone), transparent 65%);
border-radius: 7px;
background: rgba(5, 13, 22, 0.7);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
transform: translate(-50%, -50%);
}
.shell-tag span {
color: var(--tone);
font-size: 10px;
font-weight: 700;
}
.shell-tag b {
margin-left: 6px;
color: #dcebf2;
font-size: 9px;
font-weight: 500;
}
@media (max-width: 820px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
#model-panel {
top: 102px;
left: 18px;
width: min(315px, calc(100vw - 36px));
padding: 14px;
}
#audit-panel {
top: auto;
right: 18px;
bottom: 78px;
width: min(315px, calc(100vw - 36px));
max-height: 235px;
overflow: auto;
}
.bottom-ui {
right: 18px;
bottom: 16px;
left: 18px;
}
.legend {
display: none;
}
.toolbar {
width: 100%;
overflow-x: auto;
}
.toolbar button {
flex: 0 0 auto;
padding: 0 10px;
}
}
@media (max-height: 700px) and (min-width: 821px) {
#model-panel {
top: 132px;
}
.assumption-note {
display: none;
}
.legend {
max-width: 380px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive three-dimensional inverse-square point source visualization"></div>
<div id="labels" aria-hidden="true">
<div id="source-label" class="source-label">
<span>POINT SOURCE</span>
<b>Φ₀ = <span id="source-label-value">100</span> W</b>
</div>
</div>
<header class="brand">
<div class="eyebrow">Radiation field / study 01</div>
<h1>Inverse-square field</h1>
<p>Equal total power. Increasing area. Decreasing flux density.</p>
</header>
<section id="model-panel" class="panel">
<div class="assumption-badge">Ideal isotropic · lossless</div>
<p class="formula">
I(r) = <span>Φ₀ / 4πr²</span>
</p>
<p class="formula-note">
Flux density falls with the square of radius in an ideal, source-free region.
</p>
<div class="conservation">
∮ I(r) dA = Φ₀ = <span id="equation-power">100 W</span>
</div>
<p class="assumption-note">
Isotropic: equal power per unit solid angle. Lossless: no absorption or
scattering. The faceted surfaces are a low-poly visual approximation of
ideal spherical shells.
</p>
<div class="power-control">
<div class="power-heading">
<label for="power-slider">Source power</label>
<output id="power-output" for="power-slider">100 W</output>
</div>
<input
id="power-slider"
type="range"
min="20"
max="240"
step="5"
value="100"
aria-label="Source power in watts"
/>
</div>
</section>
<section id="audit-panel" class="panel">
<div class="audit-header">
<div>
<h2>Power audit</h2>
<p>Power crossing every complete spherical shell.</p>
</div>
<div class="equal-badge">All equal</div>
</div>
<div id="audit-rows"></div>
</section>
<div class="bottom-ui">
<nav class="toolbar panel" aria-label="Visualization controls">
<button id="toggle-shells" class="active" type="button" aria-pressed="true">Shells</button>
<button id="toggle-packets" class="active" type="button" aria-pressed="true">Power packets</button>
<button id="toggle-rays" class="active" type="button" aria-pressed="true">Ray flow</button>
<span class="separator"></span>
<button id="pause-motion" type="button">Pause motion</button>
<button id="reset-view" type="button">Reset view</button>
</nav>
<div class="legend panel">
<div class="legend-row">
<span class="legend-item"><i class="legend-symbol"></i><strong>Transparent shell</strong> spherical area</span>
<span class="legend-item"><i class="legend-symbol packet"></i><strong>Equal-count samples</strong> same represented power</span>
<span class="legend-item"><i class="legend-symbol ray"></i><strong>Equal-power directions</strong> isotropic emission</span>
</div>
<div>Drag to orbit · scroll to zoom · R resets the camera</div>
</div>
</div>
<noscript>This visualization requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
yaw: 0.72,
pitch: 0.39,
distance: 13.7,
target: new THREE.Vector3(0, 0, 0)
};
const initialCameraState = { ...cameraState };
function updateCamera() {
const cosPitch = Math.cos(cameraState.pitch);
const sinPitch = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.distance * cosPitch * Math.sin(cameraState.yaw),
cameraState.distance * sinPitch,
cameraState.distance * cosPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
updateCamera();
scene.add(new THREE.HemisphereLight(0x8bc9ee, 0x06101c, 1.25));
const keyLight = new THREE.DirectionalLight(0xd8efff, 1.7);
keyLight.position.set(5, 8, 4);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7d73ff, 1.1);
rimLight.position.set(-6, 2, -5);
scene.add(rimLight);
// A quiet spatial reference beneath the spherical field.
const grid = new THREE.GridHelper(28, 28, 0x24566b, 0x173447);
grid.position.y = -5.55;
const gridMaterials = Array.isArray(grid.material)
? grid.material
: [grid.material];
gridMaterials.forEach((material) => {
material.transparent = true;
material.opacity = 0.24;
material.depthWrite = false;
});
scene.add(grid);
const radii = [2, 3, 4, 5];
const shellColors = [0x55e5ff, 0x48bfff, 0x7b91ff, 0xb47dff];
const wireColors = [0x9af4ff, 0x8bdcff, 0xafb8ff, 0xd4adff];
let sourcePower = 100;
const maxRadius = Math.max(...radii);
/*
* Physical model:
*
* An ideal isotropic lossless point source emits Φ₀ watts uniformly
* into 4π steradians. At spherical radius r:
*
* I(r) = Φ₀ / (4πr²)
*
* Therefore every complete shell has:
*
* ∮ I(r) dA = Φ₀
*
* The low-poly geometry is only a visual approximation of each sphere.
*/
const shellRoot = new THREE.Group();
scene.add(shellRoot);
const baseShellGeometry = new THREE.IcosahedronGeometry(1, 1);
const wireGeometry = new THREE.WireframeGeometry(baseShellGeometry);
// Create uniformly distributed, equal-count samples on the low-poly shell.
// Every shell receives the same number and brightness of packets.
function makePacketGeometry(sourceGeometry, count) {
const position = sourceGeometry.attributes.position;
const index = sourceGeometry.index;
const faces = [];
if (index) {
for (let i = 0; i < index.count; i += 3) {
faces.push([
index.getX(i),
index.getX(i + 1),
index.getX(i + 2)
]);
}
} else {
for (let i = 0; i < position.count; i += 3) {
faces.push([i, i + 1, i + 2]);
}
}
let seed = 0x6d2b79f5;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
const samples = [];
const a = new THREE.Vector3();
const b = new THREE.Vector3();
const c = new THREE.Vector3();
for (let i = 0; i < count; i++) {
const face = faces[Math.floor(random() * faces.length)];
a.fromBufferAttribute(position, face[0]);
b.fromBufferAttribute(position, face[1]);
c.fromBufferAttribute(position, face[2]);
// Uniform barycentric sampling of a triangle.
const r1 = random();
const r2 = random();
const s = Math.sqrt(r1);
const w0 = 1 - s;
const w1 = s * (1 - r2);
const w2 = s * r2;
samples.push(
a.x * w0 + b.x * w1 + c.x * w2,
a.y * w0 + b.y * w1 + c.y * w2,
a.z * w0 + b.z * w1 + c.z * w2
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(samples, 3)
);
return geometry;
}
const packetGeometry = makePacketGeometry(baseShellGeometry, 180);
// Radial-gradient texture used for packets and the source glow.
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 64;
canvas.height = 64;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(32, 32, 0, 32, 32, 32);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.18, "rgba(255,255,255,0.95)");
gradient.addColorStop(0.48, "rgba(255,255,255,0.30)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 64, 64);
return new THREE.CanvasTexture(canvas);
}
const glowTexture = makeGlowTexture();
const shells = [];
radii.forEach((radius, index) => {
const group = new THREE.Group();
group.rotation.set(index * 0.11, index * 0.23, index * 0.07);
const surfaceMaterial = new THREE.MeshStandardMaterial({
color: shellColors[index],
emissive: shellColors[index],
emissiveIntensity: 0.35,
metalness: 0.03,
roughness: 0.48,
flatShading: true,
transparent: true,
opacity: 0.07,
depthWrite: false,
side: THREE.DoubleSide
});
const surface = new THREE.Mesh(baseShellGeometry, surfaceMaterial);
surface.scale.setScalar(radius);
surface.renderOrder = 10 + index;
const wireMaterial = new THREE.LineBasicMaterial({
color: wireColors[index],
transparent: true,
opacity: 0.42,
depthWrite: false
});
const wire = new THREE.LineSegments(wireGeometry, wireMaterial);
wire.scale.setScalar(radius);
wire.renderOrder = 30 + index;
const packetMaterial = new THREE.PointsMaterial({
color: 0xd9faff,
map: glowTexture,
size: 0.075,
sizeAttenuation: true,
transparent: true,
opacity: 0.9,
alphaTest: 0.01,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const packets = new THREE.Points(packetGeometry, packetMaterial);
packets.scale.setScalar(radius);
packets.renderOrder = 50 + index;
group.add(surface, wire, packets);
shellRoot.add(group);
shells.push({
radius,
group,
surface,
wire,
packets,
surfaceMaterial,
wireMaterial,
packetMaterial
});
});
// Equally spaced directions approximate an ideal isotropic source.
const rayCount = 36;
const rayDirections = [];
const rayPositions = [];
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < rayCount; i++) {
const y = 1 - ((i + 0.5) * 2) / rayCount;
const radial = Math.sqrt(Math.max(0, 1 - y * y));
const theta = goldenAngle * i;
const direction = new THREE.Vector3(
Math.cos(theta) * radial,
y,
Math.sin(theta) * radial
);
rayDirections.push(direction);
rayPositions.push(
0, 0, 0,
direction.x * (maxRadius + 0.6),
direction.y * (maxRadius + 0.6),
direction.z * (maxRadius + 0.6)
);
}
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(rayPositions, 3)
);
const rayMaterial = new THREE.LineBasicMaterial({
color: 0x66cbe8,
transparent: true,
opacity: 0.065,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const rayLines = new THREE.LineSegments(rayGeometry, rayMaterial);
scene.add(rayLines);
// Small moving markers make the radial energy flow readable.
const beadsPerRay = 2;
const flowCount = rayCount * beadsPerRay;
const flowPositions = new Float32Array(flowCount * 3);
const flowGeometry = new THREE.BufferGeometry();
flowGeometry.setAttribute(
"position",
new THREE.BufferAttribute(flowPositions, 3)
);
const flowMaterial = new THREE.PointsMaterial({
color: 0xbef8ff,
map: glowTexture,
size: 0.09,
sizeAttenuation: true,
transparent: true,
opacity: 0.42,
alphaTest: 0.01,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const flowPoints = new THREE.Points(flowGeometry, flowMaterial);
flowPoints.renderOrder = 80;
scene.add(flowPoints);
function updateFlow(time) {
let offset = 0;
for (let ray = 0; ray < rayCount; ray++) {
const direction = rayDirections[ray];
for (let bead = 0; bead < beadsPerRay; bead++) {
const phase = (
time * 0.105 +
bead / beadsPerRay +
ray * 0.0137
) % 1;
const radius = 0.12 + phase * (maxRadius + 0.7);
flowPositions[offset++] = direction.x * radius;
flowPositions[offset++] = direction.y * radius;
flowPositions[offset++] = direction.z * radius;
}
}
flowGeometry.attributes.position.needsUpdate = true;
}
// Point source core.
const sourceLight = new THREE.PointLight(0xffd996, 70, 0, 2);
scene.add(sourceLight);
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 1),
new THREE.MeshBasicMaterial({ color: 0xfff4cf })
);
scene.add(core);
const sourceGlowMaterial = new THREE.SpriteMaterial({
map: glowTexture,
color: 0xffd58a,
transparent: true,
opacity: 0.78,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const sourceGlow = new THREE.Sprite(sourceGlowMaterial);
sourceGlow.scale.setScalar(1.7);
scene.add(sourceGlow);
// Projected DOM labels.
const labelsContainer = document.getElementById("labels");
const sourceLabel = document.getElementById("source-label");
const shellLabels = [];
radii.forEach((radius, index) => {
const label = document.createElement("div");
label.className = "shell-tag";
label.style.setProperty("--tone", `#${wireColors[index].toString(16).padStart(6, "0")}`);
label.innerHTML = `
<span>r = ${radius} m</span>
<b class="tag-total">Φ₀ = ${sourcePower} W</b>
`;
labelsContainer.appendChild(label);
shellLabels.push(label);
});
const auditRows = document.getElementById("audit-rows");
const maxFlux = sourcePower / (4 * Math.PI * radii[0] ** 2);
auditRows.innerHTML = radii
.map(
(radius, index) => `
<div class="audit-row" style="--tone: #${wireColors[index]
.toString(16)
.padStart(6, "0")}">
<div class="audit-head">
<span><i></i>r = <b>${radius} m</b></span>
<span class="total">${sourcePower} W total</span>
</div>
<div class="audit-meta">
<span>Area ${(4 * Math.PI * radius ** 2).toFixed(1)} m²</span>
<span class="flux"></span>
</div>
<div class="meter"><span></span></div>
</div>
`
)
.join("");
function updateReadouts() {
document.getElementById("power-output").textContent = `${sourcePower} W`;
document.getElementById("equation-power").textContent = `${sourcePower} W`;
document.getElementById("source-label-value").textContent = sourcePower;
shellLabels.forEach((label) => {
label.querySelector(".tag-total").textContent = `Φ₀ = ${sourcePower} W`;
});
const rows = auditRows.querySelectorAll(".audit-row");
rows.forEach((row, index) => {
const radius = radii[index];
const area = 4 * Math.PI * radius ** 2;
const flux = sourcePower / area;
row.querySelector(".total").textContent = `${sourcePower} W total`;
row.querySelector(".flux").textContent = `Flux ${flux.toFixed(2)} W/m²`;
row.querySelector(".meter span").style.width =
`${(flux / maxFlux) * 100}%`;
});
}
function applyPower() {
const scale = sourcePower / 100;
sourceLight.intensity = 70 * scale;
sourceGlowMaterial.opacity = Math.min(0.95, 0.78 * scale);
rayMaterial.opacity = 0.065 * Math.min(1.5, scale);
flowMaterial.opacity = 0.42 * Math.min(1.5, scale);
shells.forEach((shell) => {
shell.packetMaterial.opacity = Math.min(1, 0.55 + 0.35 * scale);
});
updateReadouts();
}
const powerSlider = document.getElementById("power-slider");
powerSlider.addEventListener("input", (event) => {
sourcePower = Number(event.target.value);
applyPower();
});
/*
* Surface opacity is proportional to 1/r². Since spherical area grows as
* r², the integrated visual surface density remains equal on every shell.
*/
shells.forEach((shell) => {
const relativeFlux = radii[0] ** 2 / shell.radius ** 2;
shell.surfaceMaterial.opacity = 0.07 * relativeFlux;
shell.wireMaterial.opacity = 0.42 * relativeFlux;
});
// Direct camera controls: no external controls addon.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.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.005,
-0.12,
1.2
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
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();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
9.5,
22
);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraState.yaw = initialCameraState.yaw;
cameraState.pitch = initialCameraState.pitch;
cameraState.distance = initialCameraState.distance;
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
function toggleButton(button, active) {
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
const shellsButton = document.getElementById("toggle-shells");
const packetsButton = document.getElementById("toggle-packets");
const raysButton = document.getElementById("toggle-rays");
shellsButton.addEventListener("click", () => {
const visible = !shellsButton.classList.contains("active");
shells.forEach((shell) => {
shell.surface.visible = visible;
shell.wire.visible = visible;
});
toggleButton(shellsButton, visible);
});
packetsButton.addEventListener("click", () => {
const visible = !packetsButton.classList.contains("active");
shells.forEach((shell) => {
shell.packets.visible = visible;
});
toggleButton(packetsButton, visible);
});
raysButton.addEventListener("click", () => {
const visible = !raysButton.classList.contains("active");
rayLines.visible = visible;
flowPoints.visible = visible;
toggleButton(raysButton, visible);
});
let paused = false;
const pauseButton = document.getElementById("pause-motion");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
pauseButton.click();
}
});
const projected = new THREE.Vector3();
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
const labelDirection = new THREE.Vector3();
const sourceLabelPosition = new THREE.Vector3();
function positionLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x + offsetX}px`;
element.style.top = `${y + offsetY}px`;
}
function updateLabels() {
cameraRight.setFromMatrixColumn(camera.matrixWorld, 0).normalize();
cameraUp.setFromMatrixColumn(camera.matrixWorld, 1).normalize();
shellLabels.forEach((label, index) => {
labelDirection
.copy(cameraRight)
.addScaledVector(cameraUp, 0.22)
.normalize()
.multiplyScalar(radii[index]);
positionLabel(label, labelDirection);
});
sourceLabelPosition
.copy(cameraUp)
.multiplyScalar(0.18);
positionLabel(sourceLabel, sourceLabelPosition, 12, -18);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
applyPower();
updateFlow(0);
const clock = new THREE.Clock();
let flowTime = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
flowTime += delta;
shells.forEach((shell, index) => {
const direction = index % 2 === 0 ? 1 : -1;
shell.group.rotation.y += delta * 0.028 * direction;
shell.group.rotation.x += delta * 0.008 * direction;
});
}
const pulse = 1 + Math.sin(flowTime * 2.3) * 0.075;
sourceGlow.scale.setScalar(1.7 * pulse);
core.rotation.y += paused ? 0 : delta * 0.45;
core.rotation.x += paused ? 0 : delta * 0.23;
updateFlow(flowTime);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```