Prompt specification
Build or customize the Three.js 3D scene "Atomic-number element tile rack" 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: Atomic-number element tile rack
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/atomic-number-element-tile-rack-x1969
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a technical cutaway teaching rack of a small ordered set of chemical elements. Give each tile a clear element symbol, atomic number, and a simple cutaway nucleus marker with the corresponding proton count; arrange the tiles by atomic number so neighboring positions can be inspected in order. Keep any atomic-mass information in a separately labeled area, visually distinct from the proton count. For one selected element, allow two isotope examples with the same proton count and different neutron counts.
Working Three.js Starter (atomic-number-element-tile-rack-x1969):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ordered Nucleus Teaching Rack</title>
<style>
:root {
color-scheme: dark;
--bg: #061018;
--panel: #0b1720;
--panel-2: #101f29;
--line: #223744;
--text: #edf8fb;
--muted: #91aab6;
--cyan: #38bdf8;
--cyan-soft: rgba(56, 189, 248, 0.12);
--purple: #c4b5fd;
--purple-soft: rgba(167, 139, 250, 0.12);
--amber: #fbbf24;
--amber-soft: rgba(251, 191, 36, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
button {
font: inherit;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 35%, #112733 0%, #07131c 48%, #040b10 100%);
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.brand {
position: absolute;
top: 22px;
left: 24px;
z-index: 3;
max-width: 440px;
pointer-events: none;
text-shadow: 0 2px 14px #000;
}
.eyebrow {
margin: 0 0 6px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(20px, 2.5vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.brand p {
margin: 8px 0 0;
max-width: 430px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.sequence {
position: absolute;
left: 20px;
bottom: 20px;
z-index: 3;
max-width: calc(100% - 185px);
padding: 10px 13px;
border: 1px solid rgba(115, 160, 177, 0.25);
border-radius: 10px;
background: rgba(5, 15, 21, 0.78);
backdrop-filter: blur(12px);
pointer-events: none;
}
.sequence-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
#sequence {
display: flex;
flex-wrap: wrap;
gap: 5px;
align-items: center;
font-size: 11px;
font-weight: 750;
line-height: 1;
}
.sequence-item {
padding: 4px 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.045);
}
.sequence-arrow {
color: #55717e;
}
.view-tools {
position: absolute;
right: 18px;
bottom: 20px;
z-index: 5;
display: flex;
gap: 6px;
}
.tool-button {
min-width: 36px;
height: 36px;
padding: 0 10px;
border: 1px solid #2a4351;
border-radius: 8px;
background: rgba(10, 25, 33, 0.92);
color: var(--text);
cursor: pointer;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.tool-button:hover {
border-color: var(--cyan);
background: #132a36;
transform: translateY(-1px);
}
.tool-button:focus-visible,
.isotope-option:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.stage-note {
position: absolute;
right: 20px;
top: 22px;
z-index: 3;
max-width: 220px;
color: #78929e;
font-size: 10px;
line-height: 1.45;
text-align: right;
pointer-events: none;
}
#panel {
position: relative;
min-width: 0;
min-height: 0;
overflow-y: auto;
padding: 20px;
border-left: 1px solid #203642;
background:
linear-gradient(180deg, rgba(16, 34, 44, 0.96), rgba(8, 19, 26, 0.98));
scrollbar-color: #34505e #0b1720;
}
.panel-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#orderBadge {
padding: 5px 8px;
border: 1px solid #294450;
border-radius: 999px;
color: var(--cyan);
letter-spacing: 0.08em;
}
.identity {
position: relative;
display: grid;
grid-template-columns: 82px 1fr;
gap: 14px;
align-items: center;
margin-bottom: 14px;
padding: 15px;
overflow: hidden;
border: 1px solid #294451;
border-radius: 13px;
background:
linear-gradient(135deg, rgba(56, 189, 248, 0.09), transparent 60%),
#0c1b24;
}
.identity::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--element-accent, var(--cyan));
}
#selectedSymbol {
display: grid;
place-items: center;
width: 82px;
height: 76px;
border: 1px solid color-mix(in srgb, var(--element-accent, var(--cyan)) 55%, #203642);
border-radius: 10px;
background: rgba(0, 0, 0, 0.19);
color: var(--element-accent, var(--cyan));
font-size: 47px;
font-weight: 850;
line-height: 1;
}
#selectedName {
margin: 0 0 4px;
font-size: 20px;
letter-spacing: -0.02em;
}
#selectedDescriptor {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.section {
margin-top: 12px;
padding: 15px;
border-radius: 12px;
}
.proton-card {
border: 1px solid rgba(56, 189, 248, 0.42);
background:
linear-gradient(145deg, rgba(56, 189, 248, 0.12), transparent 62%),
#0c1d27;
}
.mass-card {
border: 1px solid rgba(167, 139, 250, 0.45);
background:
linear-gradient(145deg, rgba(167, 139, 250, 0.12), transparent 62%),
#17182a;
}
.isotope-card {
border: 1px solid #2b414d;
background: #0c1a23;
}
.section-heading {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 13px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.proton-card .section-heading {
color: var(--cyan);
}
.mass-card .section-heading {
color: var(--purple);
}
.isotope-card .section-heading {
color: #d7e4ea;
}
.section-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 9px;
background: rgba(0, 0, 0, 0.15);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric strong {
color: var(--text);
font-size: 27px;
line-height: 1;
}
.section-note {
margin: 10px 0 0;
color: #9ab0ba;
font-size: 10px;
line-height: 1.5;
}
.mass-row {
display: flex;
justify-content: space-between;
gap: 12px;
align-items: baseline;
padding: 10px 0;
border-top: 1px solid rgba(196, 181, 253, 0.16);
}
.mass-row:first-of-type {
border-top: 0;
}
.mass-row span {
color: #b6aecf;
font-size: 11px;
}
.mass-row strong {
color: #f0eaff;
font-size: 14px;
white-space: nowrap;
}
#isotopeOptions {
display: grid;
gap: 9px;
}
.isotope-option {
width: 100%;
padding: 12px;
border: 1px solid #2b414d;
border-radius: 10px;
background: rgba(0, 0, 0, 0.14);
color: var(--text);
text-align: left;
cursor: pointer;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.isotope-option:hover {
border-color: #527384;
transform: translateY(-1px);
}
.isotope-option.active {
border-color: var(--amber);
background: var(--amber-soft);
}
.isotope-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
}
.isotope-name {
font-size: 15px;
font-weight: 850;
}
.example-tag {
color: #79909b;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.composition {
color: #a8bbc4;
font-size: 10px;
}
.composition strong {
color: var(--text);
}
.nucleus {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 10px;
padding: 9px;
border-radius: 8px;
background: rgba(0, 0, 0, 0.18);
}
.particle {
display: grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 50%;
font-size: 9px;
font-weight: 900;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.particle.proton {
background: #147ca6;
color: #e4f8ff;
}
.particle.neutron {
background: #9a6710;
color: #fff5cf;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 13px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
gap: 6px;
align-items: center;
}
.legend-chip {
width: 10px;
height: 10px;
border-radius: 50%;
}
.legend-chip.p {
background: var(--cyan);
}
.legend-chip.n {
background: var(--amber);
}
.help-box {
margin-top: 12px;
padding: 12px 14px;
border-left: 3px solid #375867;
color: #90a8b4;
background: rgba(255, 255, 255, 0.025);
font-size: 10px;
line-height: 1.55;
}
.help-box strong {
color: #d3e3e9;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 860px) {
body {
grid-template-columns: 1fr;
grid-template-rows: minmax(360px, 54vh) minmax(0, 46vh);
}
#panel {
border-top: 1px solid #203642;
border-left: 0;
}
.brand {
top: 15px;
left: 16px;
}
.brand p {
display: none;
}
.stage-note {
top: 17px;
right: 14px;
max-width: 155px;
font-size: 9px;
}
.sequence {
left: 12px;
bottom: 12px;
max-width: calc(100% - 158px);
}
.view-tools {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional teaching rack">
<div id="scene"></div>
<header class="brand">
<p class="eyebrow">Technical cutaway / atomic sequence</p>
<h1>Ordered Nucleus Teaching Rack</h1>
<p>
Select a tile to inspect its nucleus. The blue cutaway markers show
protons only; atomic mass is reported separately in the inspection panel.
</p>
</header>
<div class="stage-note">
Drag the scene to orbit.<br>
Scroll or use + / − to zoom.<br>
Click a tile to select it.
</div>
<div class="sequence">
<span class="sequence-label">Atomic-number order</span>
<div id="sequence"></div>
</div>
<div class="view-tools" aria-label="Camera controls">
<button class="tool-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="tool-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="tool-button" id="resetView" type="button" aria-label="Reset camera">Reset</button>
</div>
<div id="liveStatus" class="sr-only" aria-live="polite"></div>
</main>
<aside id="panel" aria-label="Selected element inspection">
<div class="panel-top">
<span>Selected specimen</span>
<span id="orderBadge">01 / 08</span>
</div>
<div class="identity" id="identityCard">
<div id="selectedSymbol">H</div>
<div>
<h2 id="selectedName">Hydrogen</h2>
<p id="selectedDescriptor">Atomic number 1</p>
</div>
</div>
<section class="section proton-card" aria-labelledby="protonHeading">
<div class="section-heading" id="protonHeading">
<span class="section-dot"></span>
Proton count / nucleus
</div>
<div class="metric-grid">
<div class="metric">
<span>Atomic number Z</span>
<strong id="atomicNumber">1</strong>
</div>
<div class="metric">
<span>Protons (p+)</span>
<strong id="protonCount">1</strong>
</div>
</div>
<p class="section-note">
The number of blue spheres on each 3D tile equals this element's
proton count. Atomic number Z is also the proton count.
</p>
</section>
<section class="section mass-card" aria-labelledby="massHeading">
<div class="section-heading" id="massHeading">
<span class="section-dot"></span>
Atomic-mass information
</div>
<div class="mass-row">
<span>Standard atomic mass</span>
<strong id="standardMass">1.008 u</strong>
</div>
<div class="mass-row">
<span id="selectedIsotopeMassLabel">Selected isotope H-1 mass</span>
<strong id="selectedIsotopeMass">1.007825 u</strong>
</div>
<p class="section-note">
Standard atomic mass is a weighted periodic-table value, not a
particle count. The selected isotope mass describes one nuclide.
This purple area is intentionally separate from the blue proton area.
</p>
</section>
<section class="section isotope-card" aria-labelledby="isotopeHeading">
<div class="section-heading" id="isotopeHeading">
<span class="section-dot"></span>
Two isotope examples / selected element
</div>
<div id="isotopeOptions"></div>
<p class="section-note">
Both examples have the same proton count and different neutron counts.
The isotope suffix is the mass number A = protons + neutrons, not a
measured atomic mass.
</p>
<div class="legend" aria-label="Particle legend">
<span class="legend-item">
<span class="legend-chip p"></span>
Proton (p+)
</span>
<span class="legend-item">
<span class="legend-chip n"></span>
Neutron (n⁰)
</span>
</div>
</section>
<div class="help-box">
<strong>Keyboard:</strong> focus the 3D view, then use ← / → to change
elements, + / − to zoom, and 0 to reset the camera. On narrow screens the
rack folds into two ordered rows.
</div>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const elements = [
{
symbol: "H", name: "Hydrogen", z: 1, standardMass: "1.008",
accent: "#7dd3fc",
isotopes: [
{ a: 1, n: 0, mass: "1.007825" },
{ a: 2, n: 1, mass: "2.014102" }
]
},
{
symbol: "He", name: "Helium", z: 2, standardMass: "4.002602",
accent: "#a7f3d0",
isotopes: [
{ a: 3, n: 1, mass: "3.016029" },
{ a: 4, n: 2, mass: "4.002603" }
]
},
{
symbol: "Li", name: "Lithium", z: 3, standardMass: "6.94",
accent: "#fca5a5",
isotopes: [
{ a: 6, n: 3, mass: "6.015123" },
{ a: 7, n: 4, mass: "7.016004" }
]
},
{
symbol: "Be", name: "Beryllium", z: 4, standardMass: "9.0121831",
accent: "#fde68a",
isotopes: [
{ a: 9, n: 5, mass: "9.012183" },
{ a: 10, n: 6, mass: "10.013534" }
]
},
{
symbol: "B", name: "Boron", z: 5, standardMass: "10.81",
accent: "#fbbf24",
isotopes: [
{ a: 10, n: 5, mass: "10.012937" },
{ a: 11, n: 6, mass: "11.009305" }
]
},
{
symbol: "C", name: "Carbon", z: 6, standardMass: "12.011",
accent: "#a78bfa",
isotopes: [
{ a: 12, n: 6, mass: "12.000000" },
{ a: 13, n: 7, mass: "13.003355" }
]
},
{
symbol: "N", name: "Nitrogen", z: 7, standardMass: "14.007",
accent: "#67e8f9",
isotopes: [
{ a: 14, n: 7, mass: "14.003074" },
{ a: 15, n: 8, mass: "15.000109" }
]
},
{
symbol: "O", name: "Oxygen", z: 8, standardMass: "15.999",
accent: "#f472b6",
isotopes: [
{ a: 16, n: 8, mass: "15.994915" },
{ a: 17, n: 9, mass: "16.999132" }
]
}
];
const $ = (id) => document.getElementById(id);
const stage = $("stage");
const mount = $("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061018);
scene.fog = new THREE.Fog(0x061018, 18, 42);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional ordered element rack. Use arrow keys to change elements."
);
mount.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc8efff, 0x152028, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-5, 9, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x38bdf8, 1.5);
rimLight.position.set(8, 3, -6);
scene.add(rimLight);
const floor = new THREE.GridHelper(30, 30, 0x2d6172, 0x19313d);
floor.position.y = -1.35;
floor.material.transparent = true;
floor.material.opacity = 0.28;
scene.add(floor);
const tileObjects = [];
const pickMeshes = [];
let rackGroup = null;
let selectedIndex = 0;
let activeIsotope = 0;
const cameraState = {
radius: 15,
minRadius: 8,
maxRadius: 24,
theta: 0,
phi: Math.PI / 2 - 0.07,
target: new THREE.Vector3(0, 0.1, 0),
fitRadius: 15
};
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTileTexture(element, index) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 768;
const ctx = canvas.getContext("2d");
const background = ctx.createLinearGradient(0, 0, 512, 768);
background.addColorStop(0, "#132833");
background.addColorStop(0.58, "#0b1c25");
background.addColorStop(1, "#07141c");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 512, 768);
ctx.strokeStyle = "#2a4654";
ctx.lineWidth = 5;
roundedRect(ctx, 8, 8, 496, 752, 24);
ctx.stroke();
ctx.fillStyle = "#7694a1";
ctx.font = "700 21px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(`ORDER ${String(index + 1).padStart(2, "0")}`, 36, 54);
ctx.fillStyle = "#102b37";
roundedRect(ctx, 376, 27, 98, 58, 11);
ctx.fill();
ctx.strokeStyle = "#2c6478";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = "#bdefff";
ctx.font = "800 17px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.fillText("ATOMIC Z", 425, 50);
ctx.font = "900 30px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(String(element.z), 425, 77);
ctx.textAlign = "left";
ctx.fillStyle = element.accent;
ctx.fillRect(36, 93, 72, 5);
ctx.fillStyle = "#f3fbff";
ctx.font = "850 178px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(element.symbol, 31, 276);
ctx.fillStyle = "#d8e8ee";
ctx.font = "750 34px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(element.name.toUpperCase(), 38, 329);
ctx.strokeStyle = "#294450";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(36, 362);
ctx.lineTo(476, 362);
ctx.stroke();
ctx.fillStyle = "#8fb1bf";
ctx.font = "800 20px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("NUCLEUS CUTAWAY", 38, 411);
ctx.fillStyle = "#55c9f4";
ctx.font = "700 17px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("BLUE MARKERS = PROTONS (p+)", 38, 452);
ctx.fillStyle = "rgba(0, 0, 0, 0.25)";
roundedRect(ctx, 38, 480, 436, 224, 18);
ctx.fill();
ctx.strokeStyle = "#234755";
ctx.lineWidth = 2;
ctx.stroke();
ctx.save();
ctx.strokeStyle = "rgba(56, 189, 248, 0.17)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(256, 592, 99, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(136, 592);
ctx.lineTo(376, 592);
ctx.moveTo(256, 492);
ctx.lineTo(256, 692);
ctx.stroke();
ctx.restore();
ctx.fillStyle = "#67d8fb";
ctx.font = "850 23px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.fillText(`${element.z} PROTONS`, 256, 742);
ctx.textAlign = "left";
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function protonCoordinates(count) {
switch (count) {
case 1:
return [[0, 0]];
case 2:
return [[-0.11, 0], [0.11, 0]];
case 3:
return [[-0.12, -0.11], [0.12, -0.11], [0, 0.12]];
case 4:
return [[-0.12, -0.12], [0.12, -0.12], [-0.12, 0.12], [0.12, 0.12]];
case 5:
return [[-0.15, 0.11], [0, 0.11], [0.15, 0.11], [-0.08, -0.12], [0.08, -0.12]];
case 6:
return [[-0.15, 0.11], [0, 0.11], [0.15, 0.11], [-0.15, -0.11], [0, -0.11], [0.15, -0.11]];
case 7:
return [[-0.15, 0.12], [0, 0.12], [0.15, 0.12], [-0.15, 0], [0.15, 0], [-0.08, -0.13], [0.08, -0.13]];
default:
return [[-0.15, 0.12], [0, 0.12], [0.15, 0.12], [-0.15, 0], [0.15, 0], [-0.15, -0.12], [0, -0.12], [0.15, -0.12]];
}
}
function createTile(element, index) {
const group = new THREE.Group();
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0x0a171f,
roughness: 0.68,
metalness: 0.28,
emissive: 0x03090c,
emissiveIntensity: 0.8
});
const backing = new THREE.Mesh(
new THREE.BoxGeometry(1.52, 2.28, 0.16),
backingMaterial
);
backing.castShadow = true;
backing.receiveShadow = true;
backing.userData.tileIndex = index;
group.add(backing);
pickMeshes.push(backing);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(1.38, 2.12),
new THREE.MeshBasicMaterial({
map: makeTileTexture(element, index),
toneMapped: false
})
);
label.position.z = 0.086;
group.add(label);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x315965,
roughness: 0.38,
metalness: 0.72,
emissive: 0x07171c,
emissiveIntensity: 0.75
});
const verticalFrameGeometry = new THREE.BoxGeometry(0.075, 2.31, 0.14);
const horizontalFrameGeometry = new THREE.BoxGeometry(1.55, 0.075, 0.14);
for (const x of [-0.742, 0.742]) {
const bar = new THREE.Mesh(verticalFrameGeometry, frameMaterial);
bar.position.set(x, 0, 0.135);
bar.castShadow = true;
group.add(bar);
}
for (const y of [-1.115, 1.115]) {
const bar = new THREE.Mesh(horizontalFrameGeometry, frameMaterial);
bar.position.set(0, y, 0.135);
bar.castShadow = true;
group.add(bar);
}
const markerGroup = new THREE.Group();
markerGroup.position.set(0, -0.58, 0.19);
group.add(markerGroup);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.265, 0.008, 8, 64),
new THREE.MeshBasicMaterial({
color: 0x38bdf8,
transparent: true,
opacity: 0.72
})
);
markerRing.position.z = 0.005;
markerGroup.add(markerRing);
const protonGeometry = new THREE.SphereGeometry(0.075, 18, 12);
const protonMaterial = new THREE.MeshStandardMaterial({
color: 0x38bdf8,
emissive: 0x087ca8,
emissiveIntensity: 1.05,
roughness: 0.25,
metalness: 0.15
});
for (const [x, y] of protonCoordinates(element.z)) {
const proton = new THREE.Mesh(protonGeometry, protonMaterial);
proton.position.set(x, y, 0.04);
proton.castShadow = true;
markerGroup.add(proton);
}
const halo = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(1.59, 2.35, 0.18)),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.9
})
);
halo.position.z = 0.12;
halo.visible = false;
group.add(halo);
scene.add(group);
tileObjects.push({
group,
backingMaterial,
frameMaterial,
markerGroup,
halo
});
}
elements.forEach(createTile);
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
}
function buildRackRails(rows, columns, rowPositions, spacingX) {
if (rackGroup) {
scene.remove(rackGroup);
disposeGroup(rackGroup);
}
rackGroup = new THREE.Group();
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x172c36,
roughness: 0.42,
metalness: 0.75
});
const clipMaterial = new THREE.MeshStandardMaterial({
color: 0xb88b31,
roughness: 0.38,
metalness: 0.72
});
const railWidth = (columns - 1) * spacingX + 1.72;
rowPositions.forEach((rowY) => {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(railWidth, 0.13, 0.22),
railMaterial
);
rail.position.set(0, rowY - 1.26, -0.18);
rail.castShadow = true;
rackGroup.add(rail);
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * spacingX;
const clip = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.3, 0.16),
clipMaterial
);
clip.position.set(x, rowY - 1.16, -0.04);
clip.castShadow = true;
rackGroup.add(clip);
}
for (let column = 0; column < columns - 1; column++) {
const x =
(column - (columns - 1) / 2) * spacingX +
spacingX / 2;
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.045, 0.13, 3),
clipMaterial
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(x, rowY - 1.11, 0.06);
rackGroup.add(arrow);
}
});
scene.add(rackGroup);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function layoutRack() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const useTwoRows = aspect < 1.05;
const columns = useTwoRows ? 4 : 8;
const rows = useTwoRows ? 2 : 1;
const spacingX = 1.72;
const spacingY = 2.55;
const rowPositions = useTwoRows
? [spacingY / 2, -spacingY / 2]
: [0];
tileObjects.forEach((tile, index) => {
const row = Math.floor(index / columns);
const column = index % columns;
const x = (column - (columns - 1) / 2) * spacingX;
const y = rowPositions[row] ?? 0;
tile.group.position.set(x, y, 0);
});
buildRackRails(rows, columns, rowPositions, spacingX);
floor.position.y = rowPositions[rowPositions.length - 1] - 1.42;
const rackWidth = (columns - 1) * spacingX + 1.65;
const rackHeight = (rows - 1) * spacingY + 2.4;
const halfVerticalFov = THREE.MathUtils.degToRad(camera.fov / 2);
const tangent = Math.tan(halfVerticalFov);
const radiusForWidth = rackWidth / (2 * tangent * aspect);
const radiusForHeight = rackHeight / (2 * tangent);
const fit = Math.max(radiusForWidth, radiusForHeight) * 1.14;
cameraState.fitRadius = fit;
cameraState.minRadius = fit * 0.66;
cameraState.maxRadius = fit * 1.75;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
cameraState.minRadius,
cameraState.maxRadius
);
cameraState.target.set(0, useTwoRows ? 0 : 0.08, 0);
updateCamera();
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
layoutRack();
}
function resetCamera() {
cameraState.theta = 0;
cameraState.phi = Math.PI / 2 - 0.07;
cameraState.radius = cameraState.fitRadius;
cameraState.target.set(0, 0.08, 0);
updateCamera();
}
function zoom(factor) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * factor,
cameraState.minRadius,
cameraState.maxRadius
);
updateCamera();
}
function updateTileHighlight() {
tileObjects.forEach((tile, index) => {
const isSelected = index === selectedIndex;
tile.frameMaterial.color.setHex(isSelected ? 0xd9a441 : 0x315965);
tile.frameMaterial.emissive.setHex(isSelected ? 0x4b3007 : 0x07171c);
tile.frameMaterial.emissiveIntensity = isSelected ? 0.85 : 0.75;
tile.backingMaterial.emissive.setHex(isSelected ? 0x102b36 : 0x03090c);
tile.backingMaterial.emissiveIntensity = isSelected ? 1.0 : 0.8;
tile.halo.visible = isSelected;
});
}
function particleMarkup(protons, neutrons) {
let markup = "";
for (let i = 0; i < protons; i++) {
markup += '<span class="particle proton" title="Proton">P</span>';
}
for (let i = 0; i < neutrons; i++) {
markup += '<span class="particle neutron" title="Neutron">N</span>';
}
return markup;
}
function renderPanel(announce = true) {
const element = elements[selectedIndex];
const isotope = element.isotopes[activeIsotope];
const isotopeName = `${element.symbol}-${isotope.a}`;
$("orderBadge").textContent =
`${String(selectedIndex + 1).padStart(2, "0")} / 08`;
$("identityCard").style.setProperty("--element-accent", element.accent);
$("selectedSymbol").textContent = element.symbol;
$("selectedName").textContent = element.name;
$("selectedDescriptor").textContent =
`Atomic number ${element.z} · ${element.z} proton${element.z === 1 ? "" : "s"}`;
$("atomicNumber").textContent = element.z;
$("protonCount").textContent = element.z;
$("standardMass").textContent = `${element.standardMass} u`;
$("selectedIsotopeMassLabel").textContent =
`Selected isotope ${isotopeName} mass`;
$("selectedIsotopeMass").textContent = `${isotope.mass} u`;
$("isotopeOptions").innerHTML = element.isotopes
.map((example, index) => {
const name = `${element.symbol}-${example.a}`;
const active = index === activeIsotope;
return `
<button
class="isotope-option${active ? " active" : ""}"
type="button"
data-isotope-index="${index}"
aria-pressed="${active}"
>
<span class="isotope-heading">
<span class="isotope-name">${name}</span>
<span class="example-tag">Example ${index === 0 ? "A" : "B"}</span>
</span>
<span class="composition">
<strong>${example.n} neutron${example.n === 1 ? "" : "s"}</strong>
· ${element.z} proton${element.z === 1 ? "" : "s"}
</span>
<span class="nucleus">
${particleMarkup(element.z, example.n)}
</span>
</button>
`;
})
.join("");
$("isotopeOptions")
.querySelectorAll("[data-isotope-index]")
.forEach((button) => {
button.addEventListener("click", () => {
activeIsotope = Number(button.dataset.isotopeIndex);
renderPanel(false);
const chosen = element.isotopes[activeIsotope];
$("liveStatus").textContent =
`${element.name} isotope ${element.symbol}-${chosen.a} selected. ` +
`${element.z} protons and ${chosen.n} neutrons.`;
});
});
if (announce) {
$("liveStatus").textContent =
`${element.name} selected. Atomic number ${element.z}. ` +
`${element.z} protons. Two isotope examples are available.`;
}
}
function selectElement(index, announce = true) {
selectedIndex = (index + elements.length) % elements.length;
activeIsotope = 0;
updateTileHighlight();
renderPanel(announce);
}
$("sequence").innerHTML = elements
.map((element, index) => {
const arrow = index < elements.length - 1
? '<span class="sequence-arrow">→</span>'
: "";
return `<span class="sequence-item">${element.symbol}</span>${arrow}`;
})
.join("");
$("zoomIn").addEventListener("click", () => zoom(0.86));
$("zoomOut").addEventListener("click", () => zoom(1.16));
$("resetView").addEventListener("click", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointer = {
id: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: false
};
function pickTile(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickMeshes, false)[0];
if (hit) selectElement(hit.object.userData.tileIndex);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointer.id = event.pointerId;
activePointer.startX = event.clientX;
activePointer.startY = event.clientY;
activePointer.lastX = event.clientX;
activePointer.lastY = event.clientY;
activePointer.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (activePointer.id !== event.pointerId) return;
const dx = event.clientX - activePointer.lastX;
const dy = event.clientY - activePointer.lastY;
if (
Math.hypot(
event.clientX - activePointer.startX,
event.clientY - activePointer.startY
) > 5
) {
activePointer.moved = true;
}
cameraState.theta = THREE.MathUtils.clamp(
cameraState.theta - dx * 0.006,
-0.82,
0.82
);
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
1.12,
1.56
);
activePointer.lastX = event.clientX;
activePointer.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (activePointer.id !== event.pointerId) return;
if (!activePointer.moved) pickTile(event);
activePointer.id = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
activePointer.id = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
event.preventDefault();
selectElement(selectedIndex - 1);
} else if (event.key === "ArrowRight") {
event.preventDefault();
selectElement(selectedIndex + 1);
} else if (event.key === "+" || event.key === "=") {
event.preventDefault();
zoom(0.86);
} else if (event.key === "-" || event.key === "_") {
event.preventDefault();
zoom(1.16);
} else if (event.key === "0") {
event.preventDefault();
resetCamera();
}
});
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
updateTileHighlight();
renderPanel();
resize();
function animate(time) {
requestAnimationFrame(animate);
const selectedTile = tileObjects[selectedIndex];
if (selectedTile) {
const pulse = 1 + Math.sin(time * 0.0035) * 0.025;
selectedTile.markerGroup.scale.setScalar(pulse);
selectedTile.halo.material.opacity =
0.65 + Math.sin(time * 0.0035) * 0.22;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```