so_createColorPath

Summary

Returns a multi-dimensional array of RGB values from color1 to color2, ie: [[0,0,0],[5,5,5]] etc.

Arguments:

String color1
Valid 6 character hexidecimal color. This is the first color in the transition.
String color2
Valid 6 character hexidecimal color. This is the first color in the transition.

Usage:

var colorArray = so_createColorPath("FFFFFF","000000");

Examples:

The function can be used to create gradients, shift background colors or get color hues, etc. See the following:

Code

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);
		}
	}
}

License

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