Program to Change RGB color model to HSV color model | Python3 program change RGB Color Model to HSV Color Model ; R , G , B values are divided by 255 to change the range from 0. .255 to 0. .1 : ; if cmax and cmax are equal then h = 0 ; if cmax equal r then compute h ; if cmax equal g then compute h ; if cmax equal b then compute h ; if cmax equal zero ; compute v ; print ( rgb_to_hsv ( 45 , 215 , 0 ) ) print ( rgb_to_hsv ( 31 , 52 , 29 ) )
def rgb_to_hsv ( r , g , b ) : NEW_LINE INDENT r , g , b = r / 255.0 , g / 255.0 , b / 255.0 NEW_LINE if cmax == cmin : NEW_LINE INDENT h = 0 NEW_LINE DEDENT elif cmax == r : NEW_LINE INDENT h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 NEW_LINE DEDENT elif cmax == g : NEW_LINE INDENT h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 NEW_LINE DEDENT elif cmax == b : NEW_LINE INDENT h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 NEW_LINE DEDENT if cmax == 0 : NEW_LINE INDENT s = 0 NEW_LINE DEDENT else : NEW_LINE INDENT s = ( diff / cmax ) * 100 NEW_LINE DEDENT v = cmax * 100 NEW_LINE return h , s , v NEW_LINE DEDENT print ( rgb_to_hsv ( 129 , 88 , 47 ) ) NEW_LINE