如何生成随机的“绿色”的颜色 [英] How to generate random 'greenish' colors

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

问题描述

任何人都有任何建议,如何使随机色的都是绿色的?现在我通过这个生成颜色:

Anyone have any suggestions on how to make randomized colors that are all greenish? Right now I'm generating the colors by this:

color = (randint(100, 200), randint(120, 255), randint(100, 200))

这大多是有效的,

推荐答案

简单解决方案:使用 HSL或HSV 颜色空间而不是rgb(如果需要,请将其转换为RGB)。区别是元组的含义:其中RGB表示红,绿和蓝的值,在HSL中,H是颜色(例如120度或0.33,意味着绿色),S是饱和度,V是亮度。所以保持H在一个固定的值(或对于更多的随机颜色,你可以通过add / sub一个小的随机数随机化)和随机化的S和V.参见 wikipedia 文章。

Simple solution: Use the HSL or HSV color space instead of rgb (convert it to RGB afterwards if you need this). The difference is the meaning of the tuple: Where RGB means values for Red, Green and Blue, in HSL the H is the color (120 degree or 0.33 meaning green for example) and the S is for saturation and the V for the brightness. So keep the H at a fixed value (or for even more random colors you could randomize it by add/sub a small random number) and randomize the S and the V. See the wikipedia article.

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

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