JSPM

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

get sweet rgb or hex colormaps

Package Exports

  • colormap
  • colormap/index.js

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 (colormap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

colormap

Output colormaps in hex or rgb. Note: these are based on Matlab's colormaps

all colormap output

Super simple just do,

options = {
  colormap: "jet"
, nshades: 72
, format: "hex"
}
cg = colormap(options)

where leaving options = {} or undefined results in the defaults given above.

Here is a more complete example which also defines all the currently available color maps.

Example

var cmap = require('colormap')

var canvas = document.getElementById('canvas')
  , c = canvas.getContext('2d')

var n = 48

// Display all the colormaps
var cms = ['jet', 'hsv' ,'hot', 'cool', 'spring', 'summer', 'autumn',
           'winter', 'gray', 'bone', 'copper']

var i, j, cg
for (i = 0; i < cms.length; i++) {
  /*
   * Call colormap with each type
   */
  cg = cmap({'colormap': cms[i], 'nshades': n })

  /*
   * Build up the color ranges and add text
   */
  for (j = 0; j < n; j++) {
    c.fillStyle = cg[j] // start ind at index 0
    c.fillRect(j*10, i*40, 10, 40)

  }
  c.fillStyle = "#262626"
  c.font = "16px Helvetica";
  c.fillText( cms[i], n*10 + 10, i * 40 + 26);
}

Then just browserify it and throw it in some html and it will output the image above!