Their floaty rainbow colors are the result of waves of light, getting in each other’s way.
White light from the Sun contains a hidden rainbow of colors, each color a different wavelength. You can see this rainbow when light passes through a prism, and its colors spill out onto the wall. Thin layers on a surface, such as a film of oil or soap on water, can also tease the rainbow out of white light, creating an iridescent sheen.
How? When light strikes an oily puddle or soap bubble, some rays immediately bounce off the outside surface. But others penetrate into the thin film before reemerging. Since these rays travel a slightly longer path, they are slightly out of sync with the others when they emerge at the surface.
Now, imagine waves on the ocean. If two waves meet and match up, peak to peak, the resulting wave will be strongly reinforced. But if the peak of one wave meets up with the trough (low point) of another, the two cancel each other out.
Something similar happens with light waves. Scientists call this process interference. When the peaks of light waves exactly (or almost) coincide, the light brightens. But if one wave’s crest matches up with another’s trough, the two cancel each other out, making a dim or dark spot. So when light waves combine and interfere at the surface of a thin layer, colors are reinforced—or canceled. For example, a yellow wave peak matching up with a purplish-pink peak produces red.
When a crest matches to a trough and colors get canceled, we see their “complementary colors,” their color opposites. So when red waves are canceled, blue-green hues emerge. Where blues are canceled, yellows bloom. The result, in an oil slick or soap bubble, is an assortment of brilliant, swirling colors.
The exact colors you see depend on your own viewing angle, and on the depth of the thin film (say, oil). Scientists can actually determine a film’s thickness by the colors that pattern its surface, since they reveal what happened to the emerging light.
As a soap bubble evaporates, the colors change more than those on a puddle. Gravity pulls water toward the bottom, thinning the top wall and making colors shift and swirl.