Last active
December 15, 2015 12:09
-
-
Save ryasmi/5258002 to your computer and use it in GitHub Desktop.
Reverses RGB colours.
This file contains hidden or 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
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