Convert spectrum or wavelength to color.
const toColor = ;const fft = ;let magnitudes = ;documentbodystylebackground = ;
**`const spectrumColor = require('color-spectrum');`**
Get spectrum to color converter.
require('color-spectrum/table') to get a table of wavelength to XYZ values.
require('color-spectrum/approx') to get approximator of wavelength to XYZ values.
**`let color = spectrumColor(list|number, options?);`**
Calculate color based off spectrum or a single wavelength value. Spectrum is a list of float values, like magnitudes or intensities, for example, a direct output from fourier-transform with real numbers. The visible range
380..780nm will be stretched to cover the passed list of intensities.
// Use approximation formulas or matching table interpolationapproximate: false// Normalize spectrumnormalize: true// Reference whitepoint with x,y,z valueswhite: xyzwhitepoint2D65
You can also use technical methods:
//get xyz values array for a given wavelength from 380..780 range. Use 1/λ to calc frequency.x y z = spectrumColor
- Rendering of Spectra
- Wavelength to color
- Color science
- Analytical Approximation of Color Matching Functions
Thanks to all the color scientists, who devoted their lives to color research and delivered their knowledge to us, for we can trust them and use their formulas and their code. Seriously, this package is just a complement to their work in js/npm format, no new scientific knowledge, just science a bit closer to practice.
In the wild
gl-waveform — color-spectrum used to paint waveform color based of spectral contents.