hsl to rgb

Hi,

I just think hsl and hsv should have standard conversions, with hsl2rgb and hsv2rgb functions. I’ve been using a variant on hsl for a while; I like it decently enough, but it’s really slow if you’re doing more than one color; so if we’ll need batches, we’ll need a C version or a numeric package.

def hsl2rgbf( h, s, l ):
    '''adapted from wikipedia.org'''
    hk= h
    if l< 0.5:
        q= l* ( 1+ s )
    else:
        q= l+ s- ( l* s )
    p= 2* l- q
    tr= hk+ 0.333333
    tg= hk
    tb= hk- 0.333333

    tc= [ tr, tg, tb ]
    for c in range( len( tc ) ):
        if tc[ c ]< 0:
            tc[ c ]+= 1
        if tc[ c ]> 1:
            tc[ c ]-= 1

    cc= [ 0, 0, 0 ]
    for c in range( len( tc ) ):
        if tc[ c ]< 0.166666:
            cc[ c ]= p+ ( ( q- p )* 6* tc[ c ] )
        elif tc[ c ]< 0.5:
            cc[ c ]= q
        elif tc[ c ]< 0.666666:
            cc[ c ]= p+ ( ( q- p )* 6* ( 0.666666- tc[ c ] ) )
        else:
            cc[ c ]= p
        cc[ c ]= float( cc[ c ] )
    r, g, b= cc

    return r, g, b

if __name__== '__main__':
    print hsl2rgbf( 0, 0, 0 )
    print hsl2rgbf( 0, 0, 1 )
    print hsl2rgbf( 0, 1, .5 )

This is not official and very ad hoc, and my testing has been on a slight variant that returns 0-255 values.