Prompt specification
Build or customize the Three.js 3D scene "Period and group relationship display" 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: Period and group relationship display
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/period-and-group-relationship-display-x1970
Scene Description Prompt:
Create a standalone cutaway scene in one HTML file using Three.js from cdnjs. Arrange selected periodic-table rows and columns with simplified valence-pattern indicators; state that the representation is introductory and does not cover every transition-element exception.
Working Three.js Starter (period-and-group-relationship-display-x1970):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Periodic Table — Valence Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #061018;
--panel: rgba(7, 18, 27, 0.84);
--border: rgba(136, 213, 232, 0.2);
--text: #e9f7fb;
--muted: #91aab5;
--cyan: #65e6f2;
--blue: #72aaff;
--violet: #bd8cff;
--amber: #ffc45d;
--magenta: #ff73cb;
}
* {
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;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--border);
border-radius: 16px;
background:
linear-gradient(145deg, rgba(18, 39, 52, 0.82), rgba(5, 15, 23, 0.9));
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
#titlePanel {
top: 18px;
left: 18px;
width: min(350px, calc(100vw - 36px));
padding: 18px 18px 15px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 33px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 13px;
}
.control-label {
color: #c7dbe3;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.periods,
.groups {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 7px;
}
.groups {
display: grid;
grid-template-columns: repeat(9, minmax(0, 1fr));
}
button {
appearance: none;
border: 1px solid rgba(137, 190, 207, 0.18);
border-radius: 7px;
padding: 6px 8px;
background: rgba(11, 28, 39, 0.85);
color: #8fa9b5;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition:
color 140ms ease,
border-color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
button:hover {
color: white;
border-color: rgba(101, 230, 242, 0.55);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.active {
border-color: rgba(101, 230, 242, 0.72);
background: rgba(41, 149, 166, 0.28);
color: #e9feff;
box-shadow: inset 0 0 14px rgba(101, 230, 242, 0.08);
}
.group-button.active {
background: rgba(103, 69, 153, 0.34);
border-color: rgba(189, 140, 255, 0.7);
}
.actions {
display: flex;
gap: 7px;
margin-top: 14px;
}
.actions button {
flex: 1;
padding: 8px;
}
#focusSummary {
min-height: 15px;
margin-top: 12px;
color: #7895a2;
font-size: 10px;
line-height: 1.45;
}
#legendPanel {
top: 18px;
right: 18px;
width: min(300px, calc(100vw - 36px));
padding: 16px;
}
.legend-title {
margin-bottom: 10px;
color: #d8edf3;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: flex-start;
gap: 10px;
margin: 9px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.swatch {
flex: 0 0 auto;
width: 9px;
height: 9px;
margin-top: 3px;
border-radius: 50%;
box-shadow: 0 0 12px currentColor;
background: currentColor;
}
.cyan { color: var(--cyan); }
.amber { color: var(--amber); }
.magenta { color: var(--magenta); }
.cut-note {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(135, 204, 223, 0.12);
color: #9eb6c0;
font-size: 10px;
line-height: 1.5;
}
.cut-note strong {
display: block;
margin-bottom: 3px;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#hint {
position: absolute;
right: 18px;
bottom: 88px;
color: rgba(190, 219, 229, 0.62);
font-size: 10px;
letter-spacing: 0.04em;
text-shadow: 0 1px 8px black;
}
#disclaimer {
position: absolute;
right: 18px;
bottom: 18px;
left: 18px;
padding: 12px 15px;
border: 1px solid rgba(255, 196, 93, 0.25);
border-radius: 12px;
background: rgba(15, 20, 24, 0.88);
color: #b9c6cb;
font-size: 11px;
line-height: 1.5;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#disclaimer strong {
color: var(--amber);
}
@media (max-width: 760px) {
#titlePanel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
#titlePanel .subtitle {
margin-bottom: 10px;
}
#legendPanel {
display: none;
}
#hint {
right: 12px;
bottom: 100px;
font-size: 9px;
}
#disclaimer {
right: 10px;
bottom: 10px;
left: 10px;
font-size: 10px;
}
.groups {
grid-template-columns: repeat(9, 1fr);
}
button {
padding: 5px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<section id="titlePanel" class="panel">
<div class="eyebrow">Interactive teaching model</div>
<h1>Periodic table<br>valence cutaway</h1>
<p class="subtitle">
Select periods and groups. Bright intersections show an introductory
valence tally; the exposed window reveals the underlying pattern layer.
</p>
<div class="control-row">
<span class="control-label">Rows · periods</span>
</div>
<div id="periodButtons" class="periods"></div>
<div class="control-row">
<span class="control-label">Columns · groups</span>
</div>
<div id="groupButtons" class="groups"></div>
<div class="actions">
<button id="resetFocus" type="button">Reset focus</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="focusSummary"></div>
</section>
<aside id="legendPanel" class="panel">
<div class="legend-title">Pattern key</div>
<div class="legend-item">
<span class="swatch cyan"></span>
<span><strong>s-block:</strong> simple outer-shell count for groups 1–2.</span>
</div>
<div class="legend-item">
<span class="swatch amber"></span>
<span><strong>p-block:</strong> simple outer-shell count for groups 13–18.</span>
</div>
<div class="legend-item">
<span class="swatch magenta"></span>
<span><strong>d-block:</strong> simplified group-level family trend only.</span>
</div>
<div class="legend-item">
<span class="swatch" style="color:#b5c8d0"></span>
<span>One luminous mark equals one schematic valence-family count.
This is not an orbital diagram.</span>
</div>
<div class="cut-note">
<strong>Cutaway window</strong>
Rows 2–4 intersect groups 13–18. The translucent panes float above
the exposed pattern layer to suggest a removed front cover.
</div>
</aside>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<div id="disclaimer">
<strong>Introductory representation.</strong>
The d-block marks use group-level trends and omit many configuration and
oxidation-state exceptions, including notable cases such as Cr and Cu.
This model does not cover every transition-element exception; f-block,
hypervalent, and orbital-detail nuances are also intentionally simplified.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------
const app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061018);
scene.fog = new THREE.FogExp2(0x061018, 0.025);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.35, 0);
// Direct, dependency-free orbit controls.
const orbit = {
desiredTheta: 0.18,
desiredPhi: 1.23,
desiredRadius: 18,
theta: 0.18,
phi: 1.23,
radius: 18
};
function fittingRadius() {
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const horizontalFov =
2 * Math.atan(Math.tan(verticalFov / 2) * camera.aspect);
return Math.max(
17.8,
10.1 / Math.tan(horizontalFov / 2)
);
}
function resetCamera() {
orbit.desiredTheta = 0.18;
orbit.desiredPhi = 1.23;
orbit.desiredRadius = fittingRadius();
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
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.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.desiredTheta = THREE.MathUtils.clamp(
orbit.desiredTheta - dx * 0.006,
-1.25,
1.25
);
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.62,
1.56
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius + event.deltaY * 0.012,
11,
31
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.desiredTheta -= 0.08;
if (event.key === "ArrowRight") orbit.desiredTheta += 0.08;
if (event.key === "ArrowUp") orbit.desiredPhi -= 0.06;
if (event.key === "ArrowDown") orbit.desiredPhi += 0.06;
if (event.key === "+" || event.key === "=") {
orbit.desiredRadius = Math.max(11, orbit.desiredRadius - 1);
}
if (event.key === "-") {
orbit.desiredRadius = Math.min(31, orbit.desiredRadius + 1);
}
orbit.desiredTheta = THREE.MathUtils.clamp(
orbit.desiredTheta,
-1.25,
1.25
);
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi,
0.62,
1.56
);
});
// ------------------------------------------------------------
// Lighting and environment
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9ddfff, 0x061018, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.5);
keyLight.position.set(4, 8, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x42ddec, 48, 25, 2);
cyanLight.position.set(-6, 3, 6);
scene.add(cyanLight);
const magentaLight = new THREE.PointLight(0xe76acb, 32, 23, 2);
magentaLight.position.set(7, -3, 5);
scene.add(magentaLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x061018,
roughness: 0.94,
metalness: 0.05,
transparent: true,
opacity: 0.82
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -4.75;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x19404b, 0x0d2933);
grid.position.y = -4.72;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
const starGeometry = new THREE.BufferGeometry();
const starPositions = new Float32Array(320 * 3);
for (let i = 0; i < starPositions.length; i += 3) {
starPositions[i] = (Math.random() - 0.5) * 35;
starPositions[i + 1] = (Math.random() - 0.5) * 20;
starPositions[i + 2] = -6 + Math.random() * 12;
}
starGeometry.setAttribute(
"position",
new THREE.BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xa9d9e6,
size: 0.035,
transparent: true,
opacity: 0.4,
depthWrite: false
})
);
scene.add(stars);
// ------------------------------------------------------------
// Board and reusable geometry
// ------------------------------------------------------------
const board = new THREE.Group();
scene.add(board);
const backplate = new THREE.Mesh(
new THREE.BoxGeometry(18.7, 8.15, 0.42),
new THREE.MeshStandardMaterial({
color: 0x081820,
roughness: 0.55,
metalness: 0.48,
emissive: 0x031017,
emissiveIntensity: 0.35
})
);
backplate.position.set(0, -0.35, -0.34);
backplate.castShadow = true;
backplate.receiveShadow = true;
board.add(backplate);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x183541,
roughness: 0.35,
metalness: 0.7,
emissive: 0x071b22,
emissiveIntensity: 0.45
});
const frameBars = [
[0.16, 3.83, 18.7, 0.16],
[0.16, -4.53, 18.7, 0.16],
[9.28, -0.35, 0.16, 8.35],
[-9.28, -0.35, 0.16, 8.35]
];
for (const [x, y, width, height] of frameBars) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.24),
frameMaterial
);
bar.position.set(x, y, 0.05);
board.add(bar);
}
const cellGeometry = new THREE.BoxGeometry(0.93, 0.88, 0.18);
const cellEdgeGeometry = new THREE.EdgesGeometry(cellGeometry);
const paneGeometry = new THREE.BoxGeometry(0.88, 0.83, 0.028);
const paneEdgeGeometry = new THREE.EdgesGeometry(paneGeometry);
// ------------------------------------------------------------
// Canvas-based labels, using only Three.js core
// ------------------------------------------------------------
function makeElementTexture(symbol, atomicNumber, miniature = false) {
const canvas = document.createElement("canvas");
canvas.width = miniature ? 128 : 192;
canvas.height = miniature ? 112 : 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(196, 227, 236, 0.9)";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.font = `700 ${miniature ? 13 : 18}px system-ui`;
ctx.fillText(String(atomicNumber), miniature ? 7 : 11, 7);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f0fbff";
ctx.font = `750 ${miniature ? 36 : 60}px system-ui`;
ctx.fillText(
symbol,
canvas.width / 2,
canvas.height * 0.55
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeTextTexture(text, color = "#b9d5de") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 44px system-ui";
ctx.fillText(text, 128, 50);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeElementLabel(symbol, atomicNumber, miniature = false) {
return new THREE.Mesh(
new THREE.PlaneGeometry(
miniature ? 0.64 : 0.84,
miniature ? 0.5 : 0.7
),
new THREE.MeshBasicMaterial({
map: makeElementTexture(symbol, atomicNumber, miniature),
transparent: true,
depthWrite: false,
toneMapped: false
})
);
}
function makeTextPlane(
text,
width,
height,
color = "#b9d5de"
) {
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: makeTextTexture(text, color),
transparent: true,
depthWrite: false,
toneMapped: false
})
);
}
// ------------------------------------------------------------
// Periodic table data
// ------------------------------------------------------------
const periodElements = {
1: [
[1, 1, "H"], [18, 2, "He"]
],
2: [
[1, 3, "Li"], [2, 4, "Be"],
[13, 5, "B"], [14, 6, "C"], [15, 7, "N"],
[16, 8, "O"], [17, 9, "F"], [18, 10, "Ne"]
],
3: [
[1, 11, "Na"], [2, 12, "Mg"],
[13, 13, "Al"], [14, 14, "Si"], [15, 15, "P"],
[16, 16, "S"], [17, 17, "Cl"], [18, 18, "Ar"]
],
4: [
[1, 19, "K"], [2, 20, "Ca"], [3, 21, "Sc"],
[4, 22, "Ti"], [5, 23, "V"], [6, 24, "Cr"],
[7, 25, "Mn"], [8, 26, "Fe"], [9, 27, "Co"],
[10, 28, "Ni"], [11, 29, "Cu"], [12, 30, "Zn"],
[13, 31, "Ga"], [14, 32, "Ge"], [15, 33, "As"],
[16, 34, "Se"], [17, 35, "Br"], [18, 36, "Kr"]
],
5: [
[1, 37, "Rb"], [2, 38, "Sr"], [3, 39, "Y"],
[4, 40, "Zr"], [5, 41, "Nb"], [6, 42, "Mo"],
[7, 43, "Tc"], [8, 44, "Ru"], [9, 45, "Rh"],
[10, 46, "Pd"], [11, 47, "Ag"], [12, 48, "Cd"],
[13, 49, "In"], [14, 50, "Sn"], [15, 51, "Sb"],
[16, 52, "Te"], [17, 53, "I"], [18, 54, "Xe"]
],
6: [
[1, 55, "Cs"], [2, 56, "Ba"], [3, 57, "La"],
[4, 72, "Hf"], [5, 73, "Ta"], [6, 74, "W"],
[7, 75, "Re"], [8, 76, "Os"], [9, 77, "Ir"],
[10, 78, "Pt"], [11, 79, "Au"], [12, 80, "Hg"],
[13, 81, "Tl"], [14, 82, "Pb"], [15, 83, "Bi"],
[16, 84, "Po"], [17, 85, "At"], [18, 86, "Rn"]
],
7: [
[1, 87, "Fr"], [2, 88, "Ra"], [3, 89, "Ac"],
[4, 104, "Rf"], [5, 105, "Db"], [6, 106, "Sg"],
[7, 107, "Bh"], [8, 108, "Hs"], [9, 109, "Mt"],
[10, 110, "Ds"], [11, 111, "Rg"], [12, 112, "Cn"],
[13, 113, "Nh"], [14, 114, "Fl"], [15, 115, "Mc"],
[16, 116, "Lv"], [17, 117, "Ts"], [18, 118, "Og"]
]
};
const selectedRows = new Set([2, 3, 4]);
const selectedGroups = new Set([1, 2, 13, 14, 15, 16, 17, 18]);
const cells = [];
const groupLabels = [];
const periodLabels = [];
function groupX(group) {
return (group - 9.5) * 1.0;
}
function periodY(period) {
return 3.15 - (period - 1) * 0.98;
}
function simplifiedValenceCount(group) {
if (group <= 2) return group;
if (group >= 13) return group - 12;
// Introductory d-family trend: one mark per group position after group 2.
// This intentionally does not reproduce every transition-metal exception.
return group - 2;
}
function patternColor(group) {
if (group <= 2) return 0x65e6f2;
if (group >= 13) return 0xffc45d;
return 0xff73cb;
}
function makePattern(count, color) {
const group = new THREE.Group();
group.position.set(0, -0.285, 0.055);
const ellipsePoints = [];
for (let i = 0; i < 64; i++) {
const angle = (i / 64) * Math.PI * 2;
ellipsePoints.push(
new THREE.Vector3(
Math.cos(angle) * 0.18,
Math.sin(angle) * 0.105,
0
)
);
}
const ring = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(ellipsePoints),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.24,
depthWrite: false
})
);
group.add(ring);
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2 - Math.PI / 2;
positions[i * 3] = Math.cos(angle) * 0.18;
positions[i * 3 + 1] = Math.sin(angle) * 0.105;
positions[i * 3 + 2] = 0.006;
}
const pointGeometry = new THREE.BufferGeometry();
pointGeometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const points = new THREE.Points(
pointGeometry,
new THREE.PointsMaterial({
color,
size: 0.068,
sizeAttenuation: true,
transparent: true,
opacity: 0.98,
depthWrite: false
})
);
group.add(points);
group.visible = false;
return group;
}
for (let period = 1; period <= 7; period++) {
for (const [group, atomicNumber, symbol] of periodElements[period]) {
const cellGroup = new THREE.Group();
cellGroup.position.set(groupX(group), periodY(period), 0);
const material = new THREE.MeshStandardMaterial({
color: 0x0b1c25,
roughness: 0.48,
metalness: 0.38,
emissive: 0x02090d,
emissiveIntensity: 0.35
});
const base = new THREE.Mesh(cellGeometry, material);
base.position.z = -0.07;
base.castShadow = true;
base.receiveShadow = true;
cellGroup.add(base);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x183744,
transparent: true,
opacity: 0.5
});
const edge = new THREE.LineSegments(
cellEdgeGeometry,
edgeMaterial
);
edge.position.z = -0.07;
cellGroup.add(edge);
const label = makeElementLabel(symbol, atomicNumber);
label.position.set(0, 0.085, 0.04);
cellGroup.add(label);
const pattern = makePattern(
simplifiedValenceCount(group),
patternColor(group)
);
cellGroup.add(pattern);
// The pane is the removed outer cover in the cutaway region.
const paneMaterial = new THREE.MeshStandardMaterial({
color: 0x8be8f2,
roughness: 0.14,
metalness: 0.08,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const pane = new THREE.Mesh(paneGeometry, paneMaterial);
pane.position.set(0.25, 0.12, 0.95);
pane.rotation.set(-0.2, 0.16, 0);
pane.visible = false;
cellGroup.add(pane);
const paneEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x8be8f2,
transparent: true,
opacity: 0,
depthWrite: false
});
const paneEdge = new THREE.LineSegments(
paneEdgeGeometry,
paneEdgeMaterial
);
pane.add(paneEdge);
const cell = {
group: cellGroup,
period,
group,
atomicNumber,
symbol,
material,
edgeMaterial,
label,
pattern,
pane,
paneMaterial,
paneEdgeMaterial,
cut: false
};
cells.push(cell);
board.add(cellGroup);
}
}
// Group and period labels.
for (let group = 1; group <= 18; group++) {
const label = makeTextPlane(
String(group),
0.42,
0.32,
"#a9c6d1"
);
label.position.set(groupX(group), 3.58, 0.08);
board.add(label);
groupLabels.push({ group, label });
}
for (let period = 1; period <= 7; period++) {
const label = makeTextPlane(
String(period),
0.42,
0.32,
"#a9c6d1"
);
label.position.set(-9.61, periodY(period), 0.08);
board.add(label);
periodLabels.push({ period, label });
}
// Compact f-block strips; no shell-count patterns are assigned.
const lanthanides = [
["La", 57], ["Ce", 58], ["Pr", 59], ["Nd", 60], ["Pm", 61],
["Sm", 62], ["Eu", 63], ["Gd", 64], ["Tb", 65], ["Dy", 66],
["Ho", 67], ["Er", 68], ["Tm", 69], ["Yb", 70], ["Lu", 71]
];
const actinides = [
["Ac", 89], ["Th", 90], ["Pa", 91], ["U", 92], ["Np", 93],
["Pu", 94], ["Am", 95], ["Cm", 96], ["Bk", 97], ["Cf", 98],
["Es", 99], ["Fm", 100], ["Md", 101], ["No", 102], ["Lr", 103]
];
function makeMiniTile(symbol, atomicNumber, x, y) {
const group = new THREE.Group();
group.position.set(x, y, 0);
const tile = new THREE.Mesh(
new THREE.BoxGeometry(0.69, 0.53, 0.14),
new THREE.MeshStandardMaterial({
color: 0x10212b,
roughness: 0.56,
metalness: 0.28
})
);
tile.position.z = -0.03;
group.add(tile);
const label = makeElementLabel(symbol, atomicNumber, true);
label.position.z = 0.055;
group.add(label);
board.add(group);
}
lanthanides.forEach(([symbol, number], index) => {
makeMiniTile(symbol, number, (index - 7) * 0.76, -3.48);
});
actinides.forEach(([symbol, number], index) => {
makeMiniTile(symbol, number, (index - 7) * 0.76, -4.05);
});
const fBlockNote = makeTextPlane(
"F-BLOCK · PATTERNS OMITTED",
2.7,
0.34,
"#688895"
);
fBlockNote.position.set(-7.55, -3.76, 0.08);
board.add(fBlockNote);
// ------------------------------------------------------------
// Literal cutaway window in a translucent front casing
// ------------------------------------------------------------
const casingShape = new THREE.Shape();
casingShape.moveTo(-9.27, -4.46);
casingShape.lineTo(9.27, -4.46);
casingShape.lineTo(9.27, 3.73);
casingShape.lineTo(-9.27, 3.73);
casingShape.closePath();
// Opposite winding makes the rectangular hole.
const cutHole = new THREE.Path();
cutHole.moveTo(2.95, -0.28);
cutHole.lineTo(2.95, 2.68);
cutHole.lineTo(9.12, 2.68);
cutHole.lineTo(9.12, -0.28);
cutHole.closePath();
casingShape.holes.push(cutHole);
const casing = new THREE.Mesh(
new THREE.ShapeGeometry(casingShape),
new THREE.MeshPhysicalMaterial({
color: 0x8adce9,
roughness: 0.16,
metalness: 0.05,
transparent: true,
opacity: 0.052,
side: THREE.DoubleSide,
depthWrite: false
})
);
casing.position.z = 0.48;
board.add(casing);
const cutEdgeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(2.95, -0.28, 0.55),
new THREE.Vector3(2.95, 2.68, 0.55),
new THREE.Vector3(9.12, 2.68, 0.55),
new THREE.Vector3(9.12, -0.28, 0.55),
new THREE.Vector3(2.95, -0.28, 0.55)
]);
const cutEdge = new THREE.Line(
cutEdgeGeometry,
new THREE.LineDashedMaterial({
color: 0x65e6f2,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
cutEdge.computeLineDistances();
board.add(cutEdge);
// ------------------------------------------------------------
// Selection controls
// ------------------------------------------------------------
const periodButtonsContainer = document.getElementById("periodButtons");
const groupButtonsContainer = document.getElementById("groupButtons");
const focusSummary = document.getElementById("focusSummary");
const periodButtons = [];
const groupButtons = [];
for (let period = 1; period <= 7; period++) {
const button = document.createElement("button");
button.type = "button";
button.textContent = String(period);
button.title = `Period ${period}`;
button.dataset.row = String(period);
button.addEventListener("click", () => {
if (selectedRows.has(period)) selectedRows.delete(period);
else selectedRows.add(period);
updateSelection();
});
periodButtonsContainer.appendChild(button);
periodButtons.push(button);
}
for (let group = 1; group <= 18; group++) {
const button = document.createElement("button");
button.type = "button";
button.className = "group-button";
button.textContent = String(group);
button.title = `Group ${group}`;
button.dataset.group = String(group);
button.addEventListener("click", () => {
if (selectedGroups.has(group)) selectedGroups.delete(group);
else selectedGroups.add(group);
updateSelection();
});
groupButtonsContainer.appendChild(button);
groupButtons.push(button);
}
function updateSelection() {
for (const cell of cells) {
const rowSelected = selectedRows.has(cell.period);
const columnSelected = selectedGroups.has(cell.group);
const selected = rowSelected || columnSelected;
const intersection =
rowSelected &&
columnSelected &&
cell.period >= 2 &&
cell.period <= 4 &&
cell.group >= 13 &&
cell.group <= 18;
cell.cut = intersection;
if (selected && rowSelected && columnSelected) {
cell.material.color.setHex(0x0a5d68);
cell.material.emissive.setHex(0x063a42);
cell.material.emissiveIntensity = 0.72;
cell.edgeMaterial.color.setHex(0x65e6f2);
cell.edgeMaterial.opacity = 0.84;
} else if (selected && rowSelected) {
cell.material.color.setHex(0x153b5a);
cell.material.emissive.setHex(0x071b32);
cell.material.emissiveIntensity = 0.52;
cell.edgeMaterial.color.setHex(0x72aaff);
cell.edgeMaterial.opacity = 0.7;
} else if (selected && columnSelected) {
cell.material.color.setHex(0x3c2856);
cell.material.emissive.setHex(0x220f35);
cell.material.emissiveIntensity = 0.52;
cell.edgeMaterial.color.setHex(0xbd8cff);
cell.edgeMaterial.opacity = 0.7;
} else {
cell.material.color.setHex(0x0a1a23);
cell.material.emissive.setHex(0x02080c);
cell.material.emissiveIntensity = 0.22;
cell.edgeMaterial.color.setHex(0x15313d);
cell.edgeMaterial.opacity = 0.3;
}
cell.label.material.opacity = selected ? 0.98 : 0.34;
cell.pattern.visible = selected;
}
for (const { group, label } of groupLabels) {
label.material.opacity = selectedGroups.has(group) ? 1 : 0.38;
}
for (const { period, label } of periodLabels) {
label.material.opacity = selectedRows.has(period) ? 1 : 0.38;
}
periodButtons.forEach((button) => {
const period = Number(button.dataset.row);
button.classList.toggle("active", selectedRows.has(period));
button.setAttribute("aria-pressed", selectedRows.has(period));
});
groupButtons.forEach((button) => {
const group = Number(button.dataset.group);
button.classList.toggle("active", selectedGroups.has(group));
button.setAttribute("aria-pressed", selectedGroups.has(group));
});
const rowsText = [...selectedRows].sort().join(", ") || "none";
const groupsText = [...selectedGroups].sort().join(", ") || "none";
focusSummary.textContent =
`Selected periods: ${rowsText} · selected groups: ${groupsText}`;
}
document.getElementById("resetFocus").addEventListener("click", () => {
selectedRows.clear();
[2, 3, 4].forEach((period) => selectedRows.add(period));
selectedGroups.clear();
[1, 2, 13, 14, 15, 16, 17, 18].forEach((group) =>
selectedGroups.add(group)
);
updateSelection();
});
document.getElementById("resetView").addEventListener("click", resetCamera);
updateSelection();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
orbit.desiredTheta,
0.085
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
orbit.desiredPhi,
0.085
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.desiredRadius,
0.085
);
updateCamera();
board.position.y = Math.sin(elapsed * 0.42) * 0.035;
stars.rotation.z = elapsed * 0.004;
for (const cell of cells) {
const targetOpacity = cell.cut ? 0.16 : 0;
const targetEdgeOpacity = cell.cut ? 0.5 : 0;
cell.paneMaterial.opacity = THREE.MathUtils.lerp(
cell.paneMaterial.opacity,
targetOpacity,
0.09
);
cell.paneEdgeMaterial.opacity = THREE.MathUtils.lerp(
cell.paneEdgeMaterial.opacity,
targetEdgeOpacity,
0.09
);
const targetZ = cell.cut ? 0.95 : 0.38;
const targetX = cell.cut ? 0.25 : 0.02;
const targetY = cell.cut ? 0.12 : 0;
cell.pane.position.z = THREE.MathUtils.lerp(
cell.pane.position.z,
targetZ,
0.09
);
cell.pane.position.x = THREE.MathUtils.lerp(
cell.pane.position.x,
targetX,
0.09
);
cell.pane.position.y = THREE.MathUtils.lerp(
cell.pane.position.y,
targetY,
0.09
);
const targetRotationX = cell.cut ? -0.2 : -0.04;
const targetRotationY = cell.cut ? 0.16 : 0.02;
cell.pane.rotation.x = THREE.MathUtils.lerp(
cell.pane.rotation.x,
targetRotationX,
0.09
);
cell.pane.rotation.y = THREE.MathUtils.lerp(
cell.pane.rotation.y,
targetRotationY,
0.09
);
cell.pane.visible =
cell.cut ||
cell.paneMaterial.opacity > 0.008 ||
cell.paneEdgeMaterial.opacity > 0.008;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCamera();
orbit.radius = orbit.desiredRadius;
orbit.theta = orbit.desiredTheta;
orbit.phi = orbit.desiredPhi;
updateCamera();
animate();
</script>
</body>
</html>
```