1

我添加了下面的代码。但它对我产生了 16 种颜色。但我需要“红色”和“卡其色”之间的 16 种颜色。我不需要梯度流。我的颜色看起来像渐变流。我的颜色不能彼此靠近。因为我将在图表列中使用此代码返回值。他们离得太近了。

  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;
        }
    }
4

2 回答 2

2

修改后的问题文本非常清楚:您希望在红色和卡其色之间的渐变中使用 16 种颜色,其中任何两种颜色之间的视觉差异在视觉上比您选择的颜色更显着。

也许更好的标题是“我可以使用什么算法来生成红色和卡其色之间的 16 种视觉上不同的颜色?”

我不认为有一个。红色 (255, 255, 0) 和卡其色 (255, 240, 230) 差别不大:RGB 差异 = (0,15,-230)

如果你像你一样把它分成 16 个相等的步长,得到的颜色足够接近,就像你说的那样看起来像一个渐变。如果您使用不等步(可能是对数刻度),您的结果会更糟,至少在您范围的一端。

我认为您需要a)选择不同的端点或b)选择离散颜色而不试图在端点之间获取它们

或者你可能想看看这个关于选择不同颜色的线程。

于 2009-06-12T14:40:03.113 回答
2

这是程序的输出。我认为他想要红色/卡其色范围内的颜色,但彼此之间不太接近。我认为他想要选择类似于http://www.colorschemer.com/online.html的互补色

示例运行 http://img196.imageshack.us/img196/9256/20090612094934.png

于 2009-06-12T13:53:06.427 回答