Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Last active August 15, 2017 23:48
Show Gist options
  • Save ktilcu/88d66220409ab403331e to your computer and use it in GitHub Desktop.
Save ktilcu/88d66220409ab403331e to your computer and use it in GitHub Desktop.
kyle-Programming Problem: Manipulating Hex colors
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