Three.js Atomic Structure (Bohr Model Electron Shells)
Interactive Bohr-model atom in Three.js with a packed proton/neutron nucleus, tilted electron shells filled in aufbau order, orbiting electrons, and an optional probability cloud.
Key topics: three.js atom, bohr model, electron shells, atomic structure, chemistry visualization, nucleus
Game Over
What this code does
- Shell Occupancy: electrons fill shells 2 · 8 · 8 · 18 with the 4s-before-3d exception for K through Kr.
- Nucleus Packing: nucleons sit on a Fibonacci sphere whose radius scales with A^(1/3), like real nuclear radii.
- Orbit Tilts: every shell gets its own rotation, so orbits read as 3D instead of concentric circles.
- Glow Sprites: additive `Sprite` halos built from a radial-gradient `CanvasTexture` make electrons pop.
- Probability Cloud: toggle a point cloud that hints at the quantum picture, where electrons are a density, not a dot.
- Controls: pick an element, change electron speed and shell spacing, and toggle orbits or the cloud.
Related Demos
Continue Learning
JavaScript Implementation
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(50, width / height, 0.1, 200)
camera.position.set(0, 6, 18)
camera.lookAt(0, 0, 0)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)
scene.add(new THREE.AmbientLight(0xffffff, 0.5))
const light = new THREE.PointLight(0xffffff, 60, 0, 1.6)
light.position.set(6, 8, 10)
scene.add(light)
// Carbon: 6 protons, 6 neutrons, shells [2, 4]
const nucleus = new THREE.Group()
const nucleon = new THREE.SphereGeometry(0.32, 16, 12)
for (let i = 0; i < 12; i++) {
const m = new THREE.Mesh(nucleon, new THREE.MeshStandardMaterial({ color: i < 6 ? 0xef4444 : 0x9ca3af }))
m.position.randomDirection().multiplyScalar(0.5)
nucleus.add(m)
}
scene.add(nucleus)
const electrons = []
;[2, 4].forEach((count, s) => {
const r = 2.4 + s * 2.2
const shell = new THREE.Group()
shell.rotation.set(0.4 + s * 0.7, s * 1.1, 0)
const ring = new THREE.Mesh(new THREE.TorusGeometry(r, 0.02, 6, 128), new THREE.MeshBasicMaterial({ color: 0x64748b }))
ring.rotation.x = Math.PI / 2
shell.add(ring)
for (let e = 0; e < count; e++) {
const el = new THREE.Mesh(new THREE.SphereGeometry(0.18), new THREE.MeshBasicMaterial({ color: 0x38bdf8 }))
el.userData = { r, phase: (e / count) * Math.PI * 2, speed: 1.6 / Math.sqrt(s + 1) }
shell.add(el)
electrons.push(el)
}
scene.add(shell)
})
function animate (t) {
requestAnimationFrame(animate)
electrons.forEach(e => {
const a = e.userData.phase + (t / 1000) * e.userData.speed
e.position.set(Math.cos(a) * e.userData.r, 0, Math.sin(a) * e.userData.r)
})
nucleus.rotation.y += 0.005
renderer.render(scene, camera)
}
animate(0)