Generating color ranges in Python

后端 未结 4 1547
失恋的感觉
失恋的感觉 2020-12-13 01:18

I want to generate a list of color specifications in the form of (r, g, b) tuples, that span the entire color spectrum with as many entries as I want. So for 5 entries I wou

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 01:54

    Use the HSV/HSB/HSL color space (three names for more or less the same thing). Generate N tuples equally spread in hue space, then just convert them to RGB.

    Sample code:

    import colorsys
    N = 5
    HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)]
    RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples)
    

提交回复
热议问题