Created
September 4, 2013 12:51
-
-
Save dduleone/6436505 to your computer and use it in GitHub Desktop.
JS Color To Number Array
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
var colorToNumArray = function(color){ | |
var colorArray = [] | |
var cleanColor = '' | |
if(color.split('')[0]='#'){ | |
cleanColor = color.slice(1); | |
} else { | |
cleanColor = color; | |
} | |
var split = cleanColor.split(''); | |
colorArray[0] = split[0] + split[1]; | |
colorArray[1] = split[2] + split[3]; | |
colorArray[2] = split[4] + split[5]; | |
colorArray[0] = parseInt(colorArray[0], 16); | |
colorArray[1] = parseInt(colorArray[1], 16); | |
colorArray[2] = parseInt(colorArray[2], 16); | |
return colorArray; | |
} | |
var colorToNumArrayDLZ = function(color){ | |
matches = color.match(/#([a-fA-F0-9][a-fA-F0-9]?)([a-fA-F0-9][a-fA-F0-9]?)([a-fA-F0-9][a-fA-F0-9]?)/); | |
if(matches != null){ | |
matches.shift(); | |
$(matches).each(function(i,e){ | |
matches[i] = parseInt(e, 16); | |
}); | |
return matches; | |
} else { | |
throw(new Exception("Invalid hex color string passed to colorToNumArrayDLZ: " + color)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment