Sunday, June 25, 2006 - Posts

Gradient Shades

Recently I was googling and came a routine to calculate the transision from one color to another color in 255 discreet steps.
Looking at the code it did not quite look like it was going to achieve what I understood goal of the routine to be. So I quickly
put some code together and then found that there was no way to post a comment on the blog. The original post can be found
here http://dalldorf.us/home/?m=200603

So rather than waste the code here it is.

public Color Gradient(Color from, Color to, byte step)
{
   double stepFactor = (double)step / 255;
   
return Color.FromArgb(
      (
int)(from.R + ((to.R - from.R) * stepFactor)),
      (
int)(from.G + ((to.G - from.G) * stepFactor)),
      (
int)(from.B + ((to.B - from.B) * stepFactor)));
}