且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

随机产生独特的颜色?

更新时间:2023-02-26 18:52:30

一个更好的选择是典型生成一个随机的色调和转换色调使用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.