Get colors between two colors

buttons
private void createButton()
{
Color start = Color.Green, end = Color.White;
for (int i = 0; i < 16; i++)
{
int r = Interpolate(start.R, end.R, 15, i),
g = Interpolate(start.G, end.G, 15, i),
b = Interpolate(start.B, end.B, 15, i);
Button button = new Button();
button.Dock = DockStyle.Top;
button.BackColor = Color.FromArgb(r, g, b);
this.Controls.Add(button);
button.BringToFront();
}
start = Color.White;
end = Color.Blue;
for (int i = 0; i < 16; i++)
{
int r = Interpolate(start.R, end.R, 15, i),
g = Interpolate(start.G, end.G, 15, i),
b = Interpolate(start.B, end.B, 15, i);
Button button = new Button();
button.Dock = DockStyle.Top;
button.BackColor = Color.FromArgb(r, g, b);
this.Controls.Add(button);
button.BringToFront();
}
}
private int Interpolate(int start, int end, int steps, int count)
{
float s = start, e = end, final = s + (((e – s) / steps) * count);
return (int)final;
}

Leave a Reply