//RGB to HSV #declare HHSV=function(R,G,B) { 60* select( min(R,G,B)-max(R,G,B) ,//minB 6 ,//B>G 0 ) ) ,//min=max 0 ) } #declare SHSV=function(R,G,B) {select(-max(R,G,B),1-min(R,G,B)/max(R,G,B),0)} #declare VHSV=function(R,G,B) {max(R,G,B)} //END RGB to HSV //RGB to HSL #declare HHSL=function(R,G,B) {HHSV(R,G,B)} //same as HSV #declare SHSL=function(R,G,B) { select( min(R,G,B)-max(R,G,B) ,//max>min (max(R,G,B)-min(R,G,B))/ select( 1-(max(R,G,B)+min(R,G,B)) ,//l>1/2 2-(max(R,G,B)+min(R,G,B)) ,//1/2=>l max(R,G,B)+min(R,G,B) ) ,//max=min 0 ) } #declare LHSL=function(R,G,B){(max(R,G,B)+min(R,G,B))/2} //END RGB to HSL //HSL to RGB #declare tHSL=function(H,C){(H/360+C/3)-floor(H/360+C/3)} #declare qHSL=function(H,S,L){select(L-1/2,L*(1+S),L+S-L*S)} #declare pHSL=function(H,S,L){2*L-qHSL(H,S,L)} #declare CHSL=function(H,S,L,C) { select( -S ,//S>0 select( tHSL(H,C)-1/6 ,//tc<1/6 pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*tHSL(H,C) , select( tHSL(H,C)-1/2 ,//tc<1/2 qHSL(H,S,L) , select( tHSL(H,C)-2/3 ,//tc<2/3 pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*(2/3-tHSL(H,C)) ,//esle pHSL(H,S,L) ) ) ) ,//S=0 L ) } #declare RHSL=function (H,S,L){CHSL(H,S,L,+1)} #declare GHSL=function (H,S,L){CHSL(H,S,L, 0)} #declare BHSL=function (H,S,L){CHSL(H,S,L,-1)} //END HSL to RGB //HSV to RGB #declare hHSV=function (H){floor(mod(H/60,6))} #declare fHSV=function (H){H/60-hHSV(H)} #declare pHSV=function (H,S,V){V*(1-S)} #declare qHSV=function (H,S,V){V*(1-fHSV(H)*S)} #declare tHSV=function (H,S,V){V*(1-(1-fHSV(H))*S)} #declare RHSV=function (H,S,V) { select(hHSV(H)-0.5 ,//0 V , select(hHSV(H)-1.5 ,//1 qHSV(H,S,V) , select(hHSV(H)-2.5 ,//2 pHSV(H,S,V) , select(hHSV(H)-3.5 ,//3 pHSV(H,S,V) , select(hHSV(H)-4.5 ,//4 tHSV(H,S,V) ,//5 V ) ) ) ) ) } #declare GHSV=function (H,S,V) { select(hHSV(H)-0.5 ,//0 tHSV(H,S,V) , select(hHSV(H)-1.5 ,//1 V , select(hHSV(H)-2.5 ,//2 V , select(hHSV(H)-3.5 ,//3 qHSV(H,S,V) ,//4,5 pHSV(H,S,V) ) ) ) ) } #declare BHSV=function (H,S,V) { select(hHSV(H)-0.5 ,//0 pHSV(H,S,V) , select(hHSV(H)-1.5 ,//1 pHSV(H,S,V) , select(hHSV(H)-2.5 ,//2 tHSV(H,S,V) , select(hHSV(H)-3.5 ,//3 V , select(hHSV(H)-4.5 ,//4 V ,//5 qHSV(H,S,V) ) ) ) ) ) } //END HSV to RGB //CONVERT HSV to XYZ (polar to caresian) for interpolation and back #declare HSVX=function(H,S,V){sin(radians(H))*S} #declare HSVY=function(H,S,V){cos(radians(H))*S} #declare HSVZ=function(H,S,V){V} #declare XYZH=function(X,Y,Z){select(-sqrt(X*X+Y*Y),abs(degrees(acos(Y/sqrt(X*X+Y*Y)))-select(X,360,0)),0)} #declare XYZS=function(X,Y,Z){sqrt(X*X+Y*Y)} #declare XYZV=function(X,Y,Z){Z} #declare HSLX=function(H,S,L){sin(radians(H))*S} #declare HSLY=function(H,S,L){cos(radians(H))*S} #declare HSLZ=function(H,S,L){L} //H & S same as above #declare XYZL=function(X,Y,Z){Z} //END CONVERT HSV to XYZ #declare INTRGB=function (PTA,PTB,K){PTA+(PTB-PTA)*K}