This is a experiment on google gadgets, based on 2 colors calculate the transition of colors to go from the first to the second, in order to create a nice color transition.

This is the link for the gadgets page : my-google-gadgets

And this is the piece of code that make the color calculations :

/*
this dont validate the colors
*/

function calculateColor( startColor, endColor, step, iterations ) {
   var redStart = startColor.substring(1, 3);
   var greenStart = startColor.substring(3, 5);
   var blueStart = startColor.substring(5);
   var redEnd = endColor.substring(1, 3);
   var greenEnd = endColor.substring(3, 5);
   var blueEnd = endColor.substring(5);
   var redStepColor = calculateOneColor( redStart, redEnd, step, iterations );
   var greenStepColor = calculateOneColor( greenStart, greenEnd, step, iterations );
   var blueStepColor = calculateOneColor( blueStart, blueEnd, step, iterations );
   return “#” + redStepColor + greenStepColor + blueStepColor;
   }
/*
convert each color in the Hex format to integer
then calculate the difference, divide the difference
by the number of iterations and multiply by the current
step, convert back to hexa and you have the step color =)

*/
function calculateOneColor( start, end, step, iterations ) {
   var intStart = parseInt(“0X” + start );
   var intEnd = parseInt(“0X” + end );
   var difference = intEnd – intStart;
   var intOneStep = difference / iterations;
   var intResult = Math.round( intStart + ( intOneStep * step ));
   var result = intResult.toString(16).toUpperCase();
   if( result.length < 2 ) {
      result = “0″ + result;
      }
   return result;
   }