This is due to an effect called interference
Light is an electromagnetic wave
(actually, its made up of particles at the same time, but that's not the point here - it's called wave-particle dualism
). Colors are merely waves with different wavelengths. There are also many wavelengths we cannot see (see electromagnetic spectrum
This has interesting consequences:
- When 2 waves meet, they can, just like waves on a lake, amplify one another or cancel each other out (constructive and destructive interference).
The important term is optical retardation. When the retardation is a multiple of the wavelength, the interference is constructive, and the resulting wave has the maximum amplitude.
- The speed of light is dependant on the "optical density" of the medium its traveling in, in other words,
its refractive index (it's also dependant on the wavelength, which makes for even more fun, see dispersion, Why is the sky blue?).
- If the wave hits a borderline where the refractive index changes, only part of it gets through (refraction), the other part gets reflected. Note that both parts change their direction and that under certain conditions the resulting rays will be polarized (see Brewster's angle).
Think of the surface of the lake again - while you can see the sun from under water when diving, you can also see it's reflection when standing on the edge of the water. In fact, it will likely blind you - good sunglasses can help there making use of the aforementioned polarization.
- This change in the refractive index can also be gradual, eg with Fata Morganas, where the sky is mirrored in nothing but hot air, creating the impression of water.
Now back to the oil on the puddle.
The oil spreads out into a thin film. When a ray of light falls onto this film, it splits up.
There is firstly the part reflected on the border air-oil. Then there is the part that
got refracted at the air-oil border but reflected at the oil-water border and refracted yet again at the oil-air border, and so on.
There are actually infinitely many rays, but for our purposes those two traveling from the puddle
with the oil on it towards your eyes (or the camera, whatever) will be enough.
Ray #2 had a tiny bit farther to travel than ray #1, namely twice the thickness of the oil film,
as seen at the angle of the puddle towards you. This amount is incidentally in the same order
of magnitude as the wavelength of visible light (which is between 400 (violet) and 800 (red) nm
), and each time it's a little different depending on what
point of the puddle you are looking at. Sunlight contains all colors (seen in the famous rainbow
, or with a prisma
), and for each angle there's one color which interferes constructively, while the others do less so.
Therefore each point on the puddle seems to have a certain color. And it shifts when you move your head.