Drawing colors with colorsys

  • admin


    Python offers a couple of basic color conversion tools in the colorsys module. In this snippet the hsv_to_rgb() function converts hue (the color), saturation and brightness values (all between 0 and 1) to red, green and blue values.

    import colorsys
    s = 50
    b = 20
    step = 0
    brig = .5
    sat = 1
    for x in range(s):
        for y in range(s):
            c = colorsys.hsv_to_rgb(step/(s*s), 1, y/s)
            rect(x*b, y*b, b, b)
            step+= 1

Log in to reply