Sunday, November 1, 2009

Color Gradient

Here is a quick routine I put together which is used to calculate discrete transitions from a start color to an end color in 255 steps. You could call this function in a loop to generate all the color transitions from the start color to the end color.

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

No comments:

Post a Comment