Last active
August 15, 2017 23:48
-
-
Save ktilcu/88d66220409ab403331e to your computer and use it in GitHub Desktop.
kyle-Programming Problem: Manipulating Hex colors
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
function percentToHex(x, y) { | |
var c1 = '000000', | |
hex = ['0', '1','2','3','4','5','6','7','8','9','A', 'B', 'C', 'D', 'E', 'F'], | |
second = hex[Math.round(x*(hex.length-1))], | |
first= hex[Math.round(y*(hex.length-1))], | |
group = first+""+second, | |
hexStr = group+""+group+group; | |
return hexStr; | |
} | |
function addHexColor(c1, c2) { | |
var hexStr = (parseInt(c1, 16) + parseInt(c2, 16)).toString(16); | |
while (hexStr.length < 6) { hexStr = '0' + hexStr; } // Zero pad. | |
return hexStr; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment