Returns a multi-dimensional array of RGB values from color1
to color2
, ie: [[0,0,0],[5,5,5]] etc.
color1
color2
var colorArray = so_createColorPath("FFFFFF","000000");
The function can be used to create gradients, shift background colors or get color hues, etc. See the following:
function so_createColorPath(color1,color2) {
color1 = color1.replace(/#/g,""); color2 = color2.replace(/#/g,"");
colorPath = new Array();
colorPercent = 1.0;
do {
colorPath[colorPath.length]=setColorHue(longHexToDec(color1),colorPercent,longHexToDec(color2));
colorPercent-=.01;
} while(colorPercent>0);
return colorPath;
function setColorHue(originColor,opacityPercent,maskRGB) {
returnColor=new Array();
for(w=0;w<originColor.length;w++) returnColor[w] = Math.round(originColor[w]*opacityPercent) + Math.round(maskRGB[w]*(1.0-opacityPercent));
return returnColor;
}
function longHexToDec(longHex) {
r=toDec(longHex.substring(0,2));
g=toDec(longHex.substring(2,4));
b=toDec(longHex.substring(4,6));
return new Array(r,g,b);
function toDec(hex) {
return parseInt(hex,16);
}
}
}
This code is issued under a Creative Commons license. You do not need my permission to use it, though I'm always interested in seeing where my code has ended up if you want to drop me a line.
slayeroffice main