Spherical Harmonics
The real or imaginary part of any spherical harmonic up to degree 512, painted on a HEALPix sphere. Pick l and m, and view it from outside or as a Mollweide map.

Spherical harmonics are the natural waves on a sphere. The degree counts the nodal lines across the sphere (the more of them, the finer the pattern) and the order , from to , says how many of those lines are meridians. In the jet colours, blue is negative, red is positive and green-yellow is about zero. The colour range is set by the largest value of the chosen harmonic, so its pattern is always easy to read.
01 Why they matter
Any smooth function on a sphere can be written as a sum of spherical harmonics, as a function on a line is a sum of sines and cosines. The CMB temperature map is expanded this way, and the strength at each degree , its angular power spectrum, is the main thing cosmology reads from it.
The same functions give the shapes of atomic orbitals, the vibration modes of a planet, the gravity and magnetic fields of the Earth, and the lighting of a scene in computer graphics.
02 How it is built
The sphere is built
A small Nside=16 HEALPix mesh (3,072 quads, under 1 MB) is loaded, and a web worker splits every pixel into children until the sphere has Nside=256 (786,432 pixels), or 128 on phones and tablets. Each pixel keeps its RING index.
Each pixel is evaluated once, at its centre
A first pass draws the harmonic into a texture with one texel per pixel, using the centre of the pixel: and the azimuth . The sphere then looks its pixel's value up, so a pixel is one colour and turning the sphere costs nothing extra.
The harmonic is built by recursion
The graphics card starts from , multiplies in the term one factor at a time, takes the first step up in and then climbs to the chosen with a three-term recurrence. The running value carries a separate exponent, because is far below the smallest float for large . Nothing is tabulated, so changing or is instant.
Negative m comes from positive m
For the same computation is done for , and the result follows from the symmetry .
03 The recursion
Write the harmonic with its azimuthal factor and its normalisation split off, . The prime harmonic depends only on and is real. For it is built along the path in the figure, in three steps.

Start from and walk up the diagonal, multiplying in one factor for each :
One factor at a time keeps the running value in range, where a power of the sine and a product of square roots would underflow.
The first step up the column:
Then, up to the chosen :
The real part is then and the imaginary part . For the same is done for , and the symmetry gives the result:
The code is checked against the closed forms for and against orthonormality: summed over the pixels, the harmonics are orthogonal to each other and each has unit norm.
04 Things to try
Set to get the sectoral harmonics, which hug the equator, and to get the zonal ones, which are bands of latitude. Switch to the imaginary part to see the same pattern turned by a quarter of a wave around the pole. Try a negative : the pattern keeps its shape and only its sign and phase change. Turn on the grid guide in Tools to read the latitude and longitude. In the Mollweide view the whole sphere is flat and the nodal lines are easy to count. Longitude increases to the left, as on the sky.