Prompt specification
Build or customize the Three.js 3D scene "Nucleus and electron-density schematic" 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: Nucleus and electron-density schematic
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nucleus-and-electron-density-schematic-x1929
Scene Description Prompt:
I'd like to see this as a cutaway Three.js scene: nucleus and electron-density schematic. Build a tiny nucleus marker inside a much larger translucent probability-density cloud; exaggerate the nucleus visibly and explain that electrons are not shown as miniature planets. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (nucleus-and-electron-density-schematic-x1929):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Cutaway: Nucleus and Electron Probability Density</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5ff;
--muted: #9caecc;
--cyan: #66e7ff;
--violet: #7882ff;
--orange: #ffad62;
--panel: rgba(8, 15, 34, 0.78);
--line: rgba(174, 205, 255, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, #111d3d 0%, #070c1e 48%, #030510 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
#scene:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -5px;
}
.header {
position: fixed;
z-index: 3;
top: 28px;
left: 32px;
max-width: 540px;
pointer-events: none;
text-shadow: 0 2px 24px rgba(0, 0, 0, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
font-weight: 620;
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 470px;
margin: 13px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.view-badge {
position: fixed;
z-index: 3;
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 13, 31, 0.58);
color: #c8d7f5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(12px);
pointer-events: none;
}
.view-badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.panel {
position: fixed;
z-index: 4;
left: 30px;
bottom: 28px;
width: min(370px, calc(100vw - 60px));
padding: 19px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(20px) saturate(125%);
}
.panel-kicker {
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 8px;
font-size: 21px;
font-weight: 620;
letter-spacing: -0.025em;
}
.panel p {
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.58;
}
.callout {
margin-top: 14px;
padding: 12px 13px;
border-left: 2px solid var(--orange);
border-radius: 0 10px 10px 0;
background: rgba(255, 141, 65, 0.065);
}
.callout strong {
display: block;
margin-bottom: 4px;
color: #ffd2aa;
font-size: 12.5px;
}
.callout span {
display: block;
color: #b7bdd0;
font-size: 11.5px;
line-height: 1.5;
}
.scale-note {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.scale-note strong {
display: block;
margin-bottom: 4px;
color: var(--ink);
font-size: 11.5px;
}
.scale-note p {
font-size: 11px;
}
.scale-bars {
display: grid;
gap: 7px;
margin-top: 11px;
}
.scale-row {
display: grid;
grid-template-columns: 78px 1fr;
align-items: center;
gap: 9px;
color: #8492af;
font-size: 9px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.scale-track {
position: relative;
height: 4px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.055);
}
.scale-track::before {
position: absolute;
inset: 0 auto 0 0;
width: 100%;
border-radius: inherit;
content: "";
background: linear-gradient(90deg, var(--cyan), var(--violet));
opacity: 0.72;
}
.scale-row.nucleus .scale-track::before {
width: 2%;
min-width: 2px;
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 173, 98, 0.75);
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
button {
min-height: 36px;
padding: 8px 11px;
border: 1px solid rgba(161, 193, 255, 0.19);
border-radius: 10px;
background: rgba(117, 139, 193, 0.09);
color: #dfe9ff;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(102, 231, 255, 0.48);
background: rgba(102, 231, 255, 0.11);
}
button:active {
transform: translateY(1px);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.toggle-row {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
color: #aebbd7;
font-size: 11px;
}
.toggle-row label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.range-wrap {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
color: #9eacc9;
font-size: 10px;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
#opacityValue {
width: 36px;
color: #d9e7ff;
text-align: right;
font-variant-numeric: tabular-nums;
}
.label {
position: fixed;
z-index: 2;
pointer-events: none;
opacity: 0;
transition: opacity 120ms linear;
white-space: nowrap;
}
.label .label-title {
display: block;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.13em;
text-transform: uppercase;
text-shadow: 0 2px 14px #000;
}
.label .label-detail {
display: block;
margin-top: 3px;
color: #aab8d6;
font-size: 9.5px;
letter-spacing: 0.03em;
text-shadow: 0 2px 12px #000;
}
#nucleusLabel {
transform: translate(-50%, calc(-100% - 18px));
}
#nucleusLabel::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
content: "";
background: linear-gradient(var(--orange), transparent);
box-shadow: 0 0 8px rgba(255, 173, 98, 0.55);
}
#nucleusLabel .label-title {
color: #ffc28c;
}
#cloudLabel {
transform: translate(-50%, -50%);
padding: 7px 10px;
border: 1px solid rgba(102, 231, 255, 0.18);
border-radius: 8px;
background: rgba(5, 12, 30, 0.56);
backdrop-filter: blur(8px);
}
#cloudLabel .label-title {
color: var(--cyan);
}
.gesture {
position: fixed;
z-index: 3;
right: 30px;
bottom: 30px;
color: rgba(184, 200, 232, 0.62);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 30px;
}
.subtitle {
max-width: 370px;
font-size: 12px;
}
.view-badge {
top: auto;
right: 16px;
bottom: 16px;
}
.panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 43vh;
padding: 15px;
overflow-y: auto;
border-radius: 15px;
}
.panel h2 {
font-size: 18px;
}
.panel p,
.callout span,
.scale-note p {
font-size: 11px;
}
.callout {
margin-top: 10px;
}
.scale-note {
margin-top: 10px;
padding-top: 10px;
}
.controls {
margin-top: 11px;
padding-top: 11px;
}
.gesture {
display: none;
}
#cloudLabel {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive cutaway schematic of a nucleus inside an electron probability-density cloud. Drag to orbit and scroll to zoom."
></canvas>
<header class="header">
<div class="eyebrow">Atomic structure / interpretive model</div>
<h1>Inside the probability cloud</h1>
<p class="subtitle">
A cutaway view of a tiny nucleus surrounded by a diffuse electron-density
distribution. The glowing center is deliberately enlarged to make it visible.
</p>
</header>
<div class="view-badge" id="viewBadge">Cutaway density cloud</div>
<aside class="panel" aria-label="Scene explanation and controls">
<div class="panel-kicker">Reading the model</div>
<h2>A cloud, not a track</h2>
<p>
The cyan particles sample where an electron is more likely to be found.
Brighter regions act as a density cue; individual points are not simultaneous
electron positions.
</p>
<div class="callout">
<strong>Electrons are not miniature planets.</strong>
<span>
No fixed orbit or tiny ball-on-a-track is shown. Electron position is
probabilistic, not a classical path around the nucleus.
</span>
</div>
<div class="scale-note">
<strong>Scale warning: the nucleus is greatly exaggerated.</strong>
<p>
An atom is roughly 10<sup>−10</sup> m across, while a nucleus is roughly
10<sup>−14</sup> m or smaller. At true scale, the nucleus would be an
almost invisible speck.
</p>
<div class="scale-bars" aria-hidden="true">
<div class="scale-row">
<span>Atom</span>
<div class="scale-track"></div>
</div>
<div class="scale-row nucleus">
<span>Nucleus</span>
<div class="scale-track"></div>
</div>
</div>
</div>
<div class="controls">
<button id="cutawayButton" type="button" aria-pressed="true">
Cutaway: On
</button>
<button id="resetButton" type="button">Reset view</button>
<div class="toggle-row">
<label>
<input id="autoRotate" type="checkbox" checked />
Slow camera drift
</label>
<span>Drag / scroll to inspect</span>
</div>
<div class="range-wrap">
<label for="densityOpacity">Density opacity</label>
<input
id="densityOpacity"
type="range"
min="0.15"
max="1"
step="0.01"
value="0.72"
/>
<output id="opacityValue">72%</output>
</div>
</div>
</aside>
<div id="nucleusLabel" class="label">
<span class="label-title">Nucleus</span>
<span class="label-detail">Visible marker enlarged</span>
</div>
<div id="cloudLabel" class="label">
<span class="label-title">Electron probability density</span>
<span class="label-detail">Statistical region, not an orbit</span>
</div>
<div class="gesture">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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.12;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x050916, 0.018);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
100
);
// -------------------------------------------------------------------------
// Direct camera controls: no Three.js examples or addons are imported.
// -------------------------------------------------------------------------
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const autoRotateInput = document.getElementById("autoRotate");
autoRotateInput.checked = !reducedMotion;
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 0.8 ? 20 : 14.2;
}
const orbit = {
theta: 0.76,
phi: 1.14,
radius: defaultRadius()
};
const orbitTarget = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
let dragging = false;
let activePointer = null;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbitTarget.theta -= deltaX * 0.006;
orbitTarget.phi = THREE.MathUtils.clamp(
orbitTarget.phi - deltaY * 0.005,
0.28,
Math.PI - 0.28
);
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitTarget.radius = THREE.MathUtils.clamp(
orbitTarget.radius * Math.exp(event.deltaY * 0.001),
8,
28
);
},
{ passive: false }
);
function resetView() {
orbitTarget.theta = 0.76;
orbitTarget.phi = 1.14;
orbitTarget.radius = defaultRadius();
}
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") orbitTarget.theta -= 0.09;
else if (key === "arrowright") orbitTarget.theta += 0.09;
else if (key === "arrowup") {
orbitTarget.phi = Math.max(0.28, orbitTarget.phi - 0.07);
} else if (key === "arrowdown") {
orbitTarget.phi = Math.min(Math.PI - 0.28, orbitTarget.phi + 0.07);
} else if (key === "+" || key === "=") {
orbitTarget.radius = Math.max(8, orbitTarget.radius - 0.8);
} else if (key === "-" || key === "_") {
orbitTarget.radius = Math.min(28, orbitTarget.radius + 0.8);
} else if (key === "r") {
resetView();
} else {
return;
}
event.preventDefault();
});
// -------------------------------------------------------------------------
// Lighting and scene.
// -------------------------------------------------------------------------
scene.add(new THREE.AmbientLight(0x8aa7d9, 0.55));
const keyLight = new THREE.DirectionalLight(0xb9d9ff, 1.6);
keyLight.position.set(5, 7, 8);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6677ff, 1.1);
rimLight.position.set(-8, 1, -5);
scene.add(rimLight);
// A soft, generated particle sprite keeps the density cloud translucent.
function createSoftParticleTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 64;
textureCanvas.height = 64;
const context = textureCanvas.getContext("2d");
const gradient = context.createRadialGradient(
32,
32,
0,
32,
32,
32
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.28, "rgba(255,255,255,0.72)");
gradient.addColorStop(0.62, "rgba(255,255,255,0.18)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 64, 64);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const softParticleTexture = createSoftParticleTexture();
// Deterministic random-number generator keeps the schematic reproducible.
function mulberry32(seed) {
return function random() {
let value = (seed += 0x6d2b79f5);
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(38173);
const pointCount = 28000;
const cloudRadius = 5.25;
const remainingPositions = [];
const remainingColors = [];
const removedPositions = [];
const removedColors = [];
const mistPositions = [];
const mistColors = [];
const removedMistPositions = [];
const removedMistColors = [];
const innerColor = new THREE.Color(0x6cf2ff);
const outerColor = new THREE.Color(0x6873ff);
const workingColor = new THREE.Color();
for (let index = 0; index < pointCount; index++) {
const azimuth = random() * Math.PI * 2;
const vertical = random() * 2 - 1;
const horizontal = Math.sqrt(1 - vertical * vertical);
// A nonuniform radial distribution suggests a probability-density envelope
// rather than a hollow shell or a fixed orbital ring.
const radius =
cloudRadius * Math.pow(random(), 0.62) *
(0.93 + 0.09 * (1 - vertical * vertical));
const x = radius * horizontal * Math.cos(azimuth);
const y = radius * vertical;
const z = radius * horizontal * Math.sin(azimuth);
const radialFraction = THREE.MathUtils.clamp(
radius / cloudRadius,
0,
1
);
workingColor.copy(innerColor).lerp(outerColor, radialFraction);
// The front-right quarter is omitted in cutaway mode.
const isRemovedSector = x > 0 && z > 0;
if (isRemovedSector) {
removedPositions.push(x, y, z);
removedColors.push(
workingColor.r,
workingColor.g,
workingColor.b
);
if (index % 8 === 0) {
removedMistPositions.push(x, y, z);
removedMistColors.push(
workingColor.r,
workingColor.g,
workingColor.b
);
}
} else {
remainingPositions.push(x, y, z);
remainingColors.push(
workingColor.r,
workingColor.g,
workingColor.b
);
if (index % 8 === 0) {
mistPositions.push(x, y, z);
mistColors.push(
workingColor.r,
workingColor.g,
workingColor.b
);
}
}
}
function createCloud(
positions,
colors,
size,
opacity
) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const material = new THREE.PointsMaterial({
size,
map: softParticleTexture,
transparent: true,
opacity,
alphaTest: 0.001,
depthWrite: false,
vertexColors: true,
sizeAttenuation: true,
blending: THREE.AdditiveBlending,
fog: true
});
const points = new THREE.Points(geometry, material);
scene.add(points);
return points;
}
const mainCloud = createCloud(
remainingPositions,
remainingColors,
0.12,
0.43
);
const removedCloud = createCloud(
removedPositions,
removedColors,
0.12,
0.43
);
const mistCloud = createCloud(
mistPositions,
mistColors,
0.36,
0.07
);
const removedMistCloud = createCloud(
removedMistPositions,
removedMistColors,
0.36,
0.07
);
// -------------------------------------------------------------------------
// Exaggerated nucleus marker.
// -------------------------------------------------------------------------
const nucleusGroup = new THREE.Group();
scene.add(nucleusGroup);
const nucleusMaterial = new THREE.MeshStandardMaterial({
color: 0xffb15d,
emissive: 0xff5b13,
emissiveIntensity: 2.15,
roughness: 0.34,
metalness: 0.08
});
const nucleusCore = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 48, 32),
nucleusMaterial
);
nucleusGroup.add(nucleusCore);
const nucleusWire = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.58, 2),
new THREE.MeshBasicMaterial({
color: 0xffc078,
wireframe: true,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
nucleusGroup.add(nucleusWire);
function createGlowTexture() {
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 256;
glowCanvas.height = 256;
const context = glowCanvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
128,
0,
128,
128,
128
);
gradient.addColorStop(0, "rgba(255,245,220,1)");
gradient.addColorStop(0.08, "rgba(255,184,90,0.95)");
gradient.addColorStop(0.26, "rgba(255,111,32,0.42)");
gradient.addColorStop(0.58, "rgba(255,77,8,0.11)");
gradient.addColorStop(1, "rgba(255,77,8,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(glowCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const nucleusGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xff9d50,
transparent: true,
opacity: 0.72,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
nucleusGlow.scale.set(3.15, 3.15, 1);
nucleusGroup.add(nucleusGlow);
const nucleusLight = new THREE.PointLight(0xff7b2d, 8, 7, 2);
nucleusGroup.add(nucleusLight);
// -------------------------------------------------------------------------
// UI controls.
// -------------------------------------------------------------------------
const cutawayButton = document.getElementById("cutawayButton");
const viewBadge = document.getElementById("viewBadge");
const opacityInput = document.getElementById("densityOpacity");
const opacityValue = document.getElementById("opacityValue");
const resetButton = document.getElementById("resetButton");
let cutawayEnabled = true;
let opacityFactor = Number(opacityInput.value);
function applyOpacity() {
mainCloud.material.opacity = 0.43 * opacityFactor;
removedCloud.material.opacity = 0.43 * opacityFactor;
mistCloud.material.opacity = 0.07 * opacityFactor;
removedMistCloud.material.opacity = 0.07 * opacityFactor;
opacityValue.value = `${Math.round(opacityFactor * 100)}%`;
opacityValue.textContent = `${Math.round(opacityFactor * 100)}%`;
}
function applyCutaway() {
removedCloud.visible = !cutawayEnabled;
removedMistCloud.visible = !cutawayEnabled;
cutawayButton.textContent = `Cutaway: ${cutawayEnabled ? "On" : "Off"}`;
cutawayButton.setAttribute("aria-pressed", String(cutawayEnabled));
viewBadge.textContent = cutawayEnabled
? "Cutaway density cloud"
: "Full probability cloud";
}
cutawayButton.addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
applyCutaway();
});
opacityInput.addEventListener("input", () => {
opacityFactor = Number(opacityInput.value);
applyOpacity();
});
resetButton.addEventListener("click", resetView);
applyOpacity();
applyCutaway();
// -------------------------------------------------------------------------
// DOM labels projected from 3D anchors.
// -------------------------------------------------------------------------
const nucleusLabel = document.getElementById("nucleusLabel");
const cloudLabel = document.getElementById("cloudLabel");
const nucleusAnchor = new THREE.Vector3(0, 0.72, 0);
const cloudAnchor = new THREE.Vector3(3.0, 2.15, -1.0);
const projected = new THREE.Vector3();
function placeLabel(element, anchor) {
projected.copy(anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Render loop.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (autoRotateInput.checked && !dragging) {
orbitTarget.theta += delta * 0.055;
}
const damping = 1 - Math.exp(-8 * delta);
orbit.theta += (orbitTarget.theta - orbit.theta) * damping;
orbit.phi += (orbitTarget.phi - orbit.phi) * damping;
orbit.radius += (orbitTarget.radius - orbit.radius) * damping;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.radius * Math.cos(orbit.phi),
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(0, 0, 0);
placeLabel(nucleusLabel, nucleusAnchor);
placeLabel(cloudLabel, cloudAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```