随机产生独特的颜色? [英] Randomly Generate Unique Colors?

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

问题描述

我使用的是图形软件包,可以画出颜色(255,255,255)的线路。
所以基本上我在做什么是(Random.Next(0,255),Random.Next(0,255),Random.Next(0,255))生成的颜色每次添加行时间。

I'm using a graphing package that can draw lines of color (255,255,255). So basically what I'm doing is (Random.Next(0,255),Random.Next(0,255),Random.Next(0,255)) to generate a color each time a line is added.

这是一切都很好,但有时候,我得到看起来非常相似的颜色,使用户很难辨别哪些数据对应于哪条线路。

This is all well and good, but sometimes, I get colors that look very similar, making it difficult for the user to discern which data corresponds to which line.

有没有更聪明的方法在(255,255,255)格式来生成随机和独特的颜色?

Is there a more clever way to generate random and unique colors in the (255,255,255) format?

推荐答案

一个更好的选择是典型生成一个随机的色调和转换色调使用HSL或HSV颜色(与色调)的RGB颜色。通过使用随机的色相,而不是随机颜色,你会得到你的颜色更加的变化。您也可以随机其他组件(饱和度/值等),如果你需要更多的变化。

A better option is to typically generate a random hue, and the convert the hue to an RGB color using an HSL or HSV color (with that hue). By using a random "hue" instead of random color, you'll get much more variation in your colors. You can also randomize the other components (saturation/value, etc), if you need even more variation.

请参阅的维基百科关于使用HSV / HSL 在色彩的工作,包括如何转换细节HSV到RGB

See Wikipedia for details on working in colors using HSV/HSL, including how to convert HSV to RGB.

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

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