In the electromagnetic spectrum illustration and light color, frequency and wavelength post, I needed to calculate color from wavelength value. I tried a few different approaches but finally settled on a modified version of some widely cited FORTRAN code for determining RGB values.
The following illustration shows an updated version of the code in action. The sliders and buttons allow the illustration's appearance to be modified. Save the illustration as a .png file by right clicking.
The color values are an approximation. The colors fade on either end of as the wavelengths move beyond the visible range.
The code below shows a function that takes wavelength in nm as a parameter and returns an array containing the rgba value.