Get the RGB color of monochromatic light
This functionality does not run in MATLAB.
RGB::fromWaveLength( λ ) returns an approximative RGB specification for light of wavelength λ nm.
Light consists of photons, each of which has a distinct wavelength. These different wavelengths cause color perception. RGB::fromWaveLength calculates an RGB triple corresponding to a given wave length.
Different displays show the same RGB color in slightly different ways. For this reason, the so-called "gamma correction" has been invented. RGB::fromWaveLength accepts a second argument, for fine-tuning the assumed gamma correction that enters the calculation.
Color perception depends on a number of factors, including individual differences. Therefore, such a calculation can only return an approximation. RGB::fromWaveLength uses the model published by Dan Bruton for the conversion.
For wavelengths outside the visible spectrum (which ranges from 380 nm to 780 nm), RGB::fromWaveLength returns black.
White light, when sent through a prism, is split into the commonly known spectrum, because the prism refracts different wavelengths differently. This spectrum can easily be reproduced by RGB::fromWaveLength:
plot(plot::Raster([[RGB::fromWaveLength(i) $ i=380..780]]), Scaling = Unconstrained, Height = 20)
Bruton's conversion model looks like this:
plotfunc2d( plot::Raster([[RGB::fromWaveLength(i) $ i = 380..780]], x = 380..780, y = -0.2..0), (x -> RGB::fromWaveLength(x)[i]) $ i = 1..3, x = 380..780, Colors = [RGB::Red, RGB::Green, RGB::Blue], LegendVisible = FALSE, XTicksNumber = Low, Scaling = Unconstrained, Axes = Automatic)
The wavelength: a real-valued constant (interpreted as nanometers) or a length expression
The "gamma correcture" for the display, defaults to 0.8