Visualizing the Invisible: Simulating Electron Orbitals in py5
2026/7/16
“Quantum Orbital Electron Cloud” is a generative media art piece that bridges the gap between deep particle physics and cinematic visual design. In classical mechanics, we often imagine electrons as tiny planets orbiting a central sun. However, quantum mechanics dictates that electrons exist not as distinct points on a path, but as “clouds” of probability density. This artwork attempts to visualize that counterintuitive reality. By modeling 50,000 independent particles in spherical coordinates and applying a mathematical probability bias to their positions, the simulation organically forms the beautiful, lobed shapes characteristic of complex atomic orbitals. Built with Python, py5, and NumPy, the piece is a breathtaking look into the probabilistic heart of matter.
Visual & Aesthetic Approach
The aesthetic of “Quantum Orbital Electron Cloud” is designed to feel simultaneously scientific and ethereal. Set in a deep, void-like space, the center of the composition is anchored by a bright, pulsing white sphere representing the atomic nucleus. Surrounding this core is an immense, swirling cloud of 50,000 glowing neon points.
Rather than moving in clean ellipses, these points jitter and swarm chaotically. However, because of the underlying mathematical functions governing their probability, their collective density naturally forms highly organized, symmetrical shapes — specifically, the iconic flower-like lobes of $d$ or $f$ electron orbitals. To emphasize this density, the artwork relies heavily on additive blending (py5.blend_mode(py5.ADD)). Where the electrons are most likely to be found, the points overlap, burning into blindingly bright, colorful regions of high probability. Conversely, areas where electrons are forbidden to exist (nodal planes) remain dark and empty. The hue of the cloud transitions smoothly from hot inner colors to cool outer colors, directly mapping the electrons’ energy levels (distance from the nucleus) to the visible spectrum.
Code & Technical Breakdown
Simulating an electron cloud effectively requires abandoning classical Cartesian $(X, Y, Z)$ space in favor of spherical coordinates $(r, \theta, \phi)$. This makes it significantly easier to apply mathematical transformations based on angles and rotation.
# From global scope
# We use spherical coordinates (r, theta, phi) to model the electron cloud
radii = np.random.normal(300, 100, NUM_ELECTRONS).astype(np.float32)
thetas = np.random.uniform(0, np.pi * 2, NUM_ELECTRONS).astype(np.float32)
phis = np.random.uniform(0, np.pi, NUM_ELECTRONS).astype(np.float32)
# Rotational velocities for the electrons
d_theta = np.random.normal(0, 0.05, NUM_ELECTRONS).astype(np.float32)
d_phi = np.random.normal(0, 0.02, NUM_ELECTRONS).astype(np.float32)
d_r = np.random.normal(0, 1.5, NUM_ELECTRONS).astype(np.float32)Why this works: The 50,000 electrons are initialized using NumPy arrays. The radius (radii) is initialized with a normal (Gaussian) distribution, meaning most particles start grouped near a specific distance from the nucleus, with fewer particles further out or closer in. The angles (thetas and phis) are distributed uniformly, creating a complete sphere. The delta values (d_theta, d_phi, d_r) are given small, randomized values. Because this is entirely vectorized, updating the positions of all 50,000 electrons every frame is mathematically trivial and computationally instantaneous.
To transform this random sphere of jittering particles into a structured quantum orbital, the code applies a mathematical bias based on spherical harmonics.
# From draw()
# Add a spherical harmonic-like probability density bias
# We modulate the radius based on theta and phi to create lobed shapes (like p or d orbitals)
prob_bias = np.abs(np.cos(thetas * 2) * np.sin(phis * 3)) * 50
effective_radii = radii + prob_bias
# Keep radii constrained
radii = np.clip(radii, 50, 600)Why this works: In real quantum physics, the shape of an electron cloud is determined by spherical harmonics — complex mathematical functions that define probability on the surface of a sphere. This code uses a simplified, highly aesthetic approximation: np.abs(np.cos(thetas * 2) * np.sin(phis * 3)). This function generates peaks and valleys based strictly on the angle of the electron relative to the nucleus. By adding this prob_bias to the base radii, electrons at certain angles are pushed outward, while electrons at other angles are pulled inward. As the 50,000 particles jitter and orbit, they are continually forced into these geometric “lobes,” creating the exact visual signature of a high-energy atomic orbital.
Finally, the spherical coordinates must be converted back to Cartesian coordinates to be rendered on the screen.
# From draw()
# Convert spherical to Cartesian
x = effective_radii * np.sin(phis) * np.cos(thetas)
y = effective_radii * np.sin(phis) * np.sin(thetas)
z = effective_radii * np.cos(phis)
# Color depends on distance from nucleus
colors = (effective_radii * 0.8 + t * 50) % 360
py5.stroke_weight(2)
py5.begin_shape(py5.POINTS)
for i in range(NUM_ELECTRONS):
py5.stroke(colors[i], 80, 100, 30)
py5.vertex(x[i], y[i], z[i])
py5.end_shape()Why this works: This is the standard mathematical conversion from a spherical coordinate system to an $(X, Y, Z)$ system. By calculating the colors based on the `effective_radii`, the artwork ensures that the outermost tips of the orbital lobes are a different hue than the dense inner core near the nucleus. Because py5’s begin_shape(py5.POINTS) is optimized for drawing massive arrays of vertices, the rendering engine can comfortably handle 50,000 discrete points per frame, allowing the additive blending to accumulate the brilliant, glowing volume of the electron cloud.

Conclusion
“Quantum Orbital Electron Cloud” elegantly proves that the most counterintuitive concepts in science can be translated into stunning visual art. By simulating probability rather than deterministic paths, the artwork captures the true, chaotic beauty of the quantum realm. The combination of py5’s robust rendering engine and NumPy’s lightning-fast vector mathematics provides creative coders with the perfect laboratory. It allows us to visualize the invisible, giving form and color to the fundamental building blocks of the universe.
GitHub: https://github.com/asamiile/py5-media-art/tree/main/sketch/quantum_orbital_electron_cloud
Purchase assets: Adobe Stock