JSPM

color-spectrum

1.1.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 202
  • Score
    100M100P100Q82680F
  • License MIT

Convert spectrum, like FFT result, to a color

Package Exports

  • color-spectrum

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (color-spectrum) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

color-spectrum stable

Convert spectrum or wavelength to color.

color-spectrum

Usage

npm install color-spectrum

const toColor = require('color-spectrum');
const fft = require('fourier-transform');

let magnitudes = fft(myData);
document.body.style.background = toColor(magnitudes);

API

**`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.

Possible options:

// Use approximation formulas or matching table interpolation
approximate: false,

// Normalize spectrum
normalize: true,

// Reference whitepoint with x,y,z values
white: xyz.whitepoint[2].D65

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.wavelength(λ, opts?);

//get xyz values for a list of magnitudes
[x, y, z] = spectrumColor.spectrum(list, opts);

//you would like to transform to rgb
let xyz = require('color-space/xyz');
let [r, g, b] = xyz.rgb(x, y, z);

References

Credits

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.

color-space — color space conversions.
color-interpolate — interpolate color between values.