的算法,创建每次对比的颜色相同的阵列? [英] An algorithm to create the same array of contrasting colors each time?

查看:95
本文介绍了的算法,创建每次对比的颜色相同的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的节目,我想创建,将产生一个颜色数组的函数,每个颜色是其他颜色太大的不同(每次所以没有随机性应该是相同的)。

For my program I am trying to create a function that will generate an array of colors (should be the same each time so no randomness) where each colors is much different from the other colors.

为什么会这么问?好,因为用户可以添加自定义项目给用户的控制和在添加的项目应与特定颜色相关联的每个项目的

Why might you ask? Well, because the user can add custom items to a user control and with the addition of each item the item should be associated with a specific color.

显然,这将是糟糕的:

Red
Dark Red
Light Red
Pink

由于视觉所有这些都是在色调和彩色相当类似,用户将不能够区分它们。理想情况下,功能会产生这样的事情:

Because visually all of these are quite similar in tint and color and the user would not be able to differentiate them. Ideally the function would yield something like this:

Red
Dark Green
Light Cyan
Orange

在此情况下,每个颜色与其他颜色太大的不同,用户可以很容易地分辨它们在视觉上

In this case each color is much different from the other colors and the user can easily tell them apart visually.

不过,我有一点麻烦来了一个算法,做到这一点。我知道我要使用Color.FromArgb,但我不完全知道如何构建,其中每个项目是与其他很多不同的循环还没有该函数运行每次它是相同的。取模运算符可能会有所帮助。我一直在瞎搞用不同的方法,但每种总有一个颜色太相似到阵列中的另一种颜色。我想用一个循环做到这一点,但似乎有种暗示所有的颜色之间的图案,并在任何色彩,色调相似,或亮度。

However, I'm having a bit of trouble coming up with an algorithm that does this. I know I want to use Color.FromArgb but I'm not exactly sure how to construct the loops where each item is much different from the others yet it is the same each time the function is ran. The modulus operator might be helpful.. I have been messing around with different approaches but each there is always a color too similar to another color in the array. I want to do it with a loop but that seems to kind of imply a pattern and a similarity in either tint, hue, or brightness between all the colors.

我想我可以硬codeA吨价值,但我真的不想.. = X

I suppose I could hardcode a ton of values but I'd really rather not.. =X

好了,如果你们有一个想法,请让我知道!谢谢!

Well, if any of you have an idea please let me know! Thanks!!

推荐答案

有可能是这是一个很酷的方法,但如果没有人变成一起来,你也许可以蛮力也很轻松了。有些东西你可以尝试是刚刚空间的RGB值出尽可能多地。一个缺点是,你可能会得到一些花哨的颜色。我认为你可以得到解决,通过抵消了一下,但你需要一个位的测试。

There may be a really cool method for this, but if nobody turns one up, you can probably brute force it easily enough. Something you can try is to just space the RGB values out as much as possible. The one downside is that you will probably get some garish colors. I think you can get around that by offsetting a bit but you'll need a bit of testing.

例如......

8广泛分布的颜色看起来是这样的。需要注意的是D0和50是80分开或​​宽,你可以在一个8位的空间,但还是给出了不同的选择比00和80,而IMO是可怕的颜色。

8 widely spaced colors could look like this. Note that D0 and 50 are 80 apart or as wide as you can get in an 8-bit space but give different options than 00 and 80, which IMO are horrible colors.

D0D0D0
50D0D0
D050D0
D0D050
5050D0
50D050
D05050
505050

D0D0D0
50D0D0
D050D0
D0D050
5050D0
50D050
D05050
505050

如果您需要更多的颜色,可以使间隔。所有排列用3 8位值代替2-每个字将使您27变化(3 ^ 3)应该是足够在大多数情况下。在这种情况下,空间的数字约55(十六进制)彼此分开。 4 8位值变为64色(4 ^ 3),这肯定会做的。

If you need more colors, you can make the interval smaller. All permutations with 3 8-bit values instead of 2 for each word would give you 27 variations (3^3) which should be enough in most cases. In that case, space your numbers about 55 (hex) apart from each other. 4 8-bit values goes to 64 colors (4^3) which certainly will do.

我看到的唯一的问题是,一些较暗的颜色将是很难区分,所以你可能想欺骗你​​的价值走向更轻的终端。但我觉得不是,如果你直接跳过了最黑暗的颜色(这将是深灰色​​)其他应各项工作,并区分彼此相对。

The only other problem I see is that some of the darker colors will be hard to distinguish so you may want to cheat your values towards the lighter end. But I think instead if you simply skip the darkest color (which will be dark gray) the others should all work and be distinguishable relative to each other.

该算法生成的颜色,一旦你决定哪些值,这三个词之间轮换应该是相当简单的。

The algorithm to generate the colors should be fairly simple once you decide which values to rotate among the three words.

最后请注意:我重申,这是快速和肮脏的,我推迟到有人能够指向任何现有的方法。只是想给OP这可能是足够的一个选项。

Final Note: I reiterate that this is quick and dirty and I defer to any existing method that someone can point to. Just trying to give the OP an option that might be sufficient.

这篇关于的算法,创建每次对比的颜色相同的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆