When element heated chemical bonds break and new ones form and make new molecules and releasing energy.The light is emitted when an excited electron drops from a higher energy state to a lower energy state.Every element has its own specific energy configuration for the electrons in the atom. so every element has its own specific light spectrum that it emits when electrons change orbitals.
and also, Wavelength (color) is directly related to energy (E=h/wavelength).
Arsenic(As) - blue
sodium(Na) - bright yellow
zinc(Zn) - blue-green to pale green
lead(Pb) - blue
potassium(K) - light purple to red