How to generate random 'greenish' colors

后端 未结 9 2097
鱼传尺愫
鱼传尺愫 2020-12-28 13:31

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),         


        
9条回答
  •  爱一瞬间的悲伤
    2020-12-28 13:48

    The solution with HSx color space is a very good one. However, if you need something extremely simplistic and have no specific requirements about the distribution of the colors (like uniformity), a simplistic RGB-based solution would be just to make sure that G value is greater than both R and B

    rr = randint(100, 200)
    rb = randint(100, 200)
    rg = randint(max(rr, rb) + 1, 255)
    

    This will give you "greenish" colors. Some of them will be ever so slightly greenish. You can increase the guaranteed degree of greenishness by increasing (absolutely or relatively) the lower bound in the last randint call.

提交回复
热议问题