I'd meant for some time to do something on the Physics of rainbows. What pushed me into doing it was an article published in the ( London) 'Times' science magazine, 'Eureka'. It got the whole thing wrong. Almost as bad as the photo above. ( Sun would have to be behind camera, which disagrees with the shadows. Photo would have to be panoramic since rainbow subtends 85 degrees, which is above most standard lenses....)

Rainbows are due to water drops falling through the air on the side of you which is away from the Sun. The inside, back surface of each drop acts as a mirror, internally. An incoming ray of light is refracted ( bent) as it enters; then reflected; then refracted again as it leaves.

It turns out that there is a variation of angle-of-return which concentrates the rays at around 42 degrees. The exact angle depends on the refractive index of water at the wavelength of interest. 'Mu' of water varies from about 1.330 to 1.338 across the visible spectrum. For the average density of raindrops per cubic metre, you need a path length of say 1km or more to get enough returned light for a good rainbow. It helps to have a dark background.

Note in the above it REPLACES light from the background. It actually ADDS to the back scene, so is BRIGHTER inside the rainbow. I've not yet implemented this in the programs- you can do it in PhotoShop or GIMP, adding layers... The rainbow is 42 degrees left, up and right. In a real scene your shadow would be pointing straight away from you, marking the rainbow's centre. This version is not yet finalised and so not online. I hope to add options to scale the rainbow and move the anti-solar centre below the horizon, and a line to select the horizon to use. It uses DLL method for GetPixel, so will not work on JustBASIC.

Here's one where I inspect each pixel and add RGB info rather than replacing it.

Secondary rainbows are also possible. They involve rays which entered the lower half of raindrops and reflected internally twice before returning. They are at a bigger angle, and the colours reverse.

The shape of raindrops is often DRAWN as a teardrop with a tail. In fact photographs prove they are spheres ( controlled by surface tension) with some oscillatons of shape. The Times got this wrong, too.

The programs are animations of the paths followed; draw the graph of deviation angle versus incident off-centre distance; or greate a 'rainbow'. The latter can be superposed on a photo of your choice. This means it REPLACES light in the rainbow arc directions that represents the background scenery with the rainbow colours. It ought to ADD the rainbow colours to the background. This is possible to program, but I find it easier to do in the GIMP- basically adding the image pixels. In LB you'd have to add to the existing pixel colur, which involves GetPixel or equivalents...

The programs are here for use in LB as a Rainbow.zip