生成唯一的颜色 [英] Generate unique colours

查看:138
本文介绍了生成唯一的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请一些数据到纹理:在连续多个项目。他们不是为了创建的,他们都可能是不同的大小(想到一个内存堆)。每个数据项是一个小矩形,我希望能够区分它们分开,所以我想他们每个人都有独特的色彩。

I want to draw some data into a texture: many items in a row. They aren't created in order, and they may all be different sizes (think of a memory heap). Each data item is a small rectangle and I want to be able to distinguish them apart, so I'd like each of them to have a unique colour.

现在我可以只使用兰特()来生成RGB值,并希望他们都不同,但我怀疑我不会在RGB空间分配好。难道还有比这更好的办法吗?例如。什么是通过不同颜色的循环之前,他们(几乎)重复的好方法?

Now I could just use rand() to generate RGB values and hope they are all different, but I suspect I won't get good distribution in RGB space. Is there a better way than this? E.g. what is a good way of cycling through different colours before they (nearly) repeat?

的颜色不必匹配中的项目的任何数据。我只是希望能够看多值,看看它们是不同的,因为它们是相邻的。

The colours don't have to match with any data in the items. I just want to be able to look at many values and see that they are different, as they are adjacent.

我会想办法的,但我认为这是一个有趣的问题。 :)

I could figure something out but I think this is an interesting question. :)

推荐答案

使用RGB颜色模式是不是一个好办法,以获得良好的色彩搭配。最好是用另一种颜色模型来生成你的颜色,然后从颜色模式为RGB转换。

Using the RGB color model is not a good way to get a good color mix. It's better to use another color model to generate your color, and then convert from that color model to RGB.

我建议你 HSV或HSL 颜色模式代替,特别是要改变< A HREF =htt​​p://en.wikipedia.org/wiki/Hue>色相。

I suggest you the HSV or HSL color model instead, in particular you want to vary the Hue.

如果你想要使用X不同的颜色值,它们各不相同,从0到360的360步长的X分。

If you want X different color values, vary them from 0 to 360 with a step size of 360 divided by X.

这篇关于生成唯一的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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