private static Color hsv ( float h , float s , float v , float alpha ) { float r = 0 ; float g = 0 ; float b = 0 ; if ( s == 0 ) { // this color in on the black white center line <=> h = UNDEFINED // Achromatic color, there is no hue r = v ; g = v ; b = v ; } else { if ( h == 1.0f ) { h = 0.0f ; } // h is now in [0,6) h *= 6 ; int i = ( int ) Math . floor ( h ) ; float f = h - i ; //f is fractional part of h float p = v * ( 1 - s ) ; float q = v * ( 1 - ( s * f ) ) ; float t = v * ( 1 - ( s * ( 1 - f ) ) ) ; switch ( i ) { case 0 : r = v ; g = t ; b = p ; break ; case 1 : r = q ; g = v ; b = p ; break ; case 2 : r = p ; g = v ; b = t ; break ; case 3 : r = p ; g = q ; b = v ; break ; case 4 : r = t ; g = p ; b = v ; break ; case 5 : r = v ; g = p ; b = q ; break ; } } return new Color ( r , g , b , alpha ) ; }
Generate a color based on HSV model .