Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active December 15, 2015 12:09
Show Gist options
  • Save ryasmi/5258002 to your computer and use it in GitHub Desktop.
Save ryasmi/5258002 to your computer and use it in GitHub Desktop.
Reverses RGB colours.
var reverseNumber = function (maxValue, value) {
return (maxValue - 1) - value;
};
var hex2Dec = function (hexStr) {
return parseInt(hexStr, 16);
};
var dec2Hex = function (decStr, digits) {
var hexStr = decStr.toString(16);
var chars = digits - hexStr.length;
var count;
for (count = 0; count < chars; count += 1) {
hexStr = "0" + hexStr;
}
return hexStr;
};
var reverseColour = function(colour) {
var digits = colour.length;
return dec2Hex(reverseNumber(Math.pow(16, digits), hex2Dec(colour)), digits);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment