, , HSV, RGB. HSV , - , . RGB- , .
- RGB FF0000 00FF00. - 7f7f00, -.
HSV. FF0000 00FF00 (), , - ffff00.
- RGB, , - B4B400, (B4 hex = 180 dec = 255/sqrt (2)), - . , RGB, , . , , , HSV- , 100%.
Imageshack
Java, HSB, - HSB , , RGB, , h, s, v:
static Color hsvInterpolate ( float mix, Color c0, Color c1 ) {
float[] hsv0 = new float[3];
float[] hsv1 = new float[3];
float alt = 1.0f - mix;
Color.RGBtoHSB( c0.getRed(), c0.getGreen(), c0.getBlue(), hsv0 );
Color.RGBtoHSB( c1.getRed(), c1.getGreen(), c1.getBlue(), hsv1 );
float h = mix * hsv0 [ 0 ] + alt * hsv1 [ 0 ];
float s = mix * hsv0 [ 1 ] + alt * hsv1 [ 1 ];
float v = mix * hsv0 [ 2 ] + alt * hsv1 [ 2 ];
return Color.getHSBColor ( h, s, v );
}
, # , .
static Color vectorInterpolate ( float mix, Color c0, Color c1 ) {
float alt = 1.0f - mix;
double x0 = c0.getRed();
double y0 = c0.getGreen();
double z0 = c0.getBlue();
double x1 = c1.getRed();
double y1 = c1.getGreen();
double z1 = c1.getBlue();
double mag0 = sqrt( x0*x0 + y0*y0 + z0*z0 );
double mag1 = sqrt( x1*x1 + y1*y1 + z1*z1 );
double x = mix * x0 + alt * x1;
double y = mix * y0 + alt * y1;
double z = mix * z0 + alt * z1;
double mag = mix * mag0 + alt * mag1;
double scale = mag / sqrt( x*x + y*y + z*z );
return new Color (
clamp ( x * scale ),
clamp ( y * scale ),
clamp ( z * scale ) );
}
static int clamp ( double value ) {
int x = (int) round ( value );
if ( x > 255 ) return 255;
if ( x < 0 ) return 0;
return x;
}
, RGB, , .
HSY, , Dave Green cube helix color .