Created
June 14, 2011 23:56
-
-
Save arextar/1026220 to your computer and use it in GitHub Desktop.
Color parsing tool (little more optimized for speed this time)
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
parse=function(a,b,c){function d(a,b,c){return(c+=c<0?1:c>1?-1:0,c<1/6?a+(b-a)*6*c:c<.5?b:c<2/3?a+(b-a)*(2/3-c)*6:a)*255}return function(e,f,g,h,i){return a[e]=a[e]?a[e]:b.test(e)?(e=b.exec(e)[1].split(","),[~~e[0],~~e[1],~~e[2]]):e.charAt(0)=="#"?(e=b.exec(e)[1].split(","),[~~e[0],~~e[1],~~e[2]]):c.test(e)?(e=c.exec(e),g=+e[1]/360,h=+e[2]/100,i=+e[3]/100,h==0?[i,i,i]:(h=i<.5?i*(1+h):i+h-i*h,i=2*i-h,[d(i,h,g+1/3),d(i,h,g),d(i,h,g-1/3)])):[0,0,0]}}({},/rgb\((.+)\)/,/hsl\(([0-9]+),([0-9]+)%?,([0-9]+)%?\)/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment