I used my diffraction grating to take this picture of the low energy bulb in the table lamp on my desk. The lamp is on the right, the spectrum I got appears as coloured lines on the left. Notice that I don't get the full rainbow. The lines are said to be DISCRETE - ie not continuous, not flowing into each other like a rainbow would. The explanation is that photons of light, which are packets of light energy, are released by electrons in the atoms of the mercury vapour inside the bulb. You'll remember from GCSE Chemistry that electrons come in levels around the nucleus - 2 on the first level, 8 on the second level, 8 on the third level etc. Electrons can jump from one level to another. When they jump down levels, they release photons. The bigger the jump, the higher the energy. Photon energy = hf, where h is called Planck's constant and f is the frequency. The higher the energy the higher the frequency. Violet has the highest frequency so that line is for the biggest jump. Red has the lowest frequency and so is for the lowest jump. The lines are discrete because there are only certain discrete energy levels. Each element has its own unique pattern of coloured lines because each has its own arrangement of electron energy levels. This is mercury. See second section down on this link for more details http://hyperphysics.phy-astr.gsu.edu/hbase/quantum/atspect2.html