HSV to RGB Color Conversion

后端 未结 9 1686
离开以前
离开以前 2020-12-14 01:16

Is there a way to convert HSV color arguments to RGB type color arguments using pygame modules in python? I tried the following code, but it returns ridiculous values.

9条回答
  •  我在风中等你
    2020-12-14 01:48

    I have prepared a vectorized version, it is cca 10x faster

    def hsv_to_rgb(h, s, v):
        shape = h.shape
        i = int_(h*6.)
        f = h*6.-i
    
        q = f
        t = 1.-f
        i = ravel(i)
        f = ravel(f)
        i%=6
    
        t = ravel(t)
        q = ravel(q)
    
        clist = (1-s*vstack([zeros_like(f),ones_like(f),q,t]))*v
    
        #0:v 1:p 2:q 3:t
        order = array([[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]])
        rgb = clist[order[i], arange(prod(shape))[:,None]]
    
        return rgb.reshape(shape+(3,))
    

提交回复
热议问题