chroma.js
chroma.js copied to clipboard
Add CMY color space
Cyan, magenta, and yellow, the pigment primaries, are complements of the light primaries, red, green, and blue, respectively. Would it be possible to add the CMY color space?
- There is no single CMY color space; any combination of ink, process, and paper creates a new one.
- Going from RGB to any particular CMY(K) color space is very much non-trivial.
That said, since there is support for a very naive version of CMYK, it only makes sense to make an equally naive version of CMY or to remove them both. For now you can use:
cmyk2cmy = function(cmyk) {
const [c, m, y, k] = cmyk
return [c + k, m + k, y + k]
}
cmy2cmyk = function(cmy) {
const [c, m, y] = cmy
const k = Math.max(...cmy)
return [c - k, m - k, y - k, k]
}
const chroma = require('chroma-js')
const Color = chroma('black').__proto__ // big hack
Color.prototype.cmy = function() { cmyk2cmy(this.cmyk()); }
chroma.cmy = (...args) => new Color(...cmy2cmyk(args), 'cmyk')