1

i added below codes. But it generates to me 16 color. but i need 16 color between "red" and "khaki". i don't need gradient flow. My colors look like gradient flow. My colors must not closer to each other. Because i will use this codes return values in chart columns. they are too near each other.

  static class Program
    {

        [STAThread]
        static void Main()
        {
            Form form = new Form();
            Color start = Color.Red, end = Color.Khaki;
            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);
                form.Controls.Add(button);
                button.BringToFront();
            }

            Application.Run(form);
        }
        static int Interpolate(int start, int end, int steps, int count)
        {
            float s = start, e = end, final = s + (((e - s) / steps) * count);
            return (int)final;
        }
    }
Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Penguen
  • 16,836
  • 42
  • 130
  • 205
  • I think you need to rewrite the question here. The code is clear enough, but I have no idea what you actually want. – Noldorin Jun 12 '09 at 13:38
  • The code you have above will generate the 16 colors "between" Red and Khaki. Are you saying you want a different distribution of colors, not on the linear gradient? You must make the question clearer. – Mark Ransom Jun 12 '09 at 13:50
  • yes i want different distribution of colors – Penguen Jun 12 '09 at 13:57

2 Answers2

2

Here's the output of the program. I think he wants colors in the range of Red / Khaki, but aren't so close to each other. I think he wants something to choose complimentary colors similarly to http://www.colorschemer.com/online.html

Example run http://img196.imageshack.us/img196/9256/20090612094934.png

Greg
  • 16,540
  • 9
  • 51
  • 97
2

The revised text of question is pretty clear: you want 16 colors on a gradient "between" Red and Khaki where the visual difference between any two colors is visually more significant than the colors you chose are.

Perhaps a better title would be "What algorithm can I use to generate 16 visually distinctive colors between Red and Khaki?"

I don't think there is one. Red (255, 255, 0) and Khaki (255, 240, 230) just aren't that different: RGB difference = (0,15,-230)

If you divide it up in 16 equal steps like you do, the resultant colors are close enough together to look like a gradient as you said. If you were to use unequal steps, (perhaps a logarithmic scale), your results would be worse, at least at one end of your range.

I think you need to either a) choose different endpoints or b) choose discrete colors without trying to get them between your endpoints

Or you might want to look at this thread about choosing distinct colors.

Community
  • 1
  • 1
JeffH
  • 10,254
  • 2
  • 27
  • 48