A film thin enough to sort colors

An oil slick can act like a stack of two very close mirrors. One beam of sunlight reflects from the oil’s upper boundary; another enters the film, reflects from the water below, and returns to the air. Because the second beam travels through the oil before coming back, the two beams arrive slightly out of step.

Light behaves like a wave, with crests and troughs. When the returning waves line up, they strengthen one another; when a crest meets a trough, they weaken or cancel. This is called thin-film interference. The oil’s boundaries can also shift a reflected wave’s phase—where its crests fall in the wave cycle—so the result depends on both the film’s thickness and the materials it touches.

Why the colors change across the puddle

Different colors of visible light have different wavelengths. A film thickness that makes one wavelength reinforce itself may make another cancel. Where the oil is a little thicker or thinner, the balance changes, so a different color becomes strongest in the reflected light.

A puddle is not a perfectly even sheet: its surface ripples, spreads, and gathers into patches. Those small thickness changes create the shifting bands and swirls. The rainbow is therefore not painted onto the pavement; it is the changing mix of sunlight that survives interference at each spot. As the film moves or drains, the pattern can change with it.