Created
November 19, 2016 06:12
-
-
Save weedgrease/d41ec28617410dbeb37d6e6d8df6262d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chroma = require('chroma-js'); | |
var Q = 255; | |
var color = chroma("#FF0000").rgb(); | |
var max = Math.max.apply(null, color); | |
var min = Math.min.apply(null, color); | |
var K; | |
var Wo = (min/max < 0.5) ? ((min*max) / (max-min)) : (max); | |
if(color[0] == color[1] && color[0] == color[2] && color[0] != null) { | |
K = 1; | |
} else { | |
K = (Wo + max) / min; | |
} | |
if (K > Q) { | |
K = Q; | |
} else if (K < 0) { | |
K = 0; | |
} | |
var Ro, Go, Bo; | |
Ro = Math.floor(((K * color[0]) - Wo) / Q); | |
Go = Math.floor(((K * color[1]) - Wo) / Q); | |
Bo = Math.floor(((K * color[2]) - Wo) / Q); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment