private Color interpolateColor(final Color COLOR1, final Color COLOR2, final float FRACTION) {
        assert (Float.compare(FRACTION, 0f) >= 0 && Float.compare(FRACTION, 1f) <= 0);

        final float INT_TO_FLOAT_CONST = 1f / 255f;

        final float RED1 = COLOR1.getRed() * INT_TO_FLOAT_CONST;
        final float GREEN1 = COLOR1.getGreen() * INT_TO_FLOAT_CONST;
        final float BLUE1 = COLOR1.getBlue() * INT_TO_FLOAT_CONST;
        final float ALPHA1 = COLOR1.getAlpha() * INT_TO_FLOAT_CONST;

        final float RED2 = COLOR2.getRed() * INT_TO_FLOAT_CONST;
        final float GREEN2 = COLOR2.getGreen() * INT_TO_FLOAT_CONST;
        final float BLUE2 = COLOR2.getBlue() * INT_TO_FLOAT_CONST;
        final float ALPHA2 = COLOR2.getAlpha() * INT_TO_FLOAT_CONST;

        final float DELTA_RED = RED2 - RED1;
        final float DELTA_GREEN = GREEN2 - GREEN1;
        final float DELTA_BLUE = BLUE2 - BLUE1;
        final float DELTA_ALPHA = ALPHA2 - ALPHA1;

        float red = RED1 + (DELTA_RED * FRACTION);
        float green = GREEN1 + (DELTA_GREEN * FRACTION);
        float blue = BLUE1 + (DELTA_BLUE * FRACTION);
        float alpha = ALPHA1 + (DELTA_ALPHA * FRACTION);

        red = red < 0f ? 0f : (red > 1f ? 1f : red);
        green = green < 0f ? 0f : (green > 1f ? 1f : green);
        blue = blue < 0f ? 0f : (blue > 1f ? 1f : blue);
        alpha = alpha < 0f ? 0f : (alpha > 1f ? 1f : alpha);

        return new Color(red, green, blue, alpha);
    }
private Color interpolateColor ( final Color COLOR1 , final Color COLOR2 , final float FRACTION ) { assert ( Float . compare ( FRACTION , 0f ) >= 0 && Float . compare ( FRACTION , 1f ) <= 0 ) ; final float INT_TO_FLOAT_CONST = 1f / 255f ; final float RED1 = COLOR1 . getRed ( ) * INT_TO_FLOAT_CONST ; final float GREEN1 = COLOR1 . getGreen ( ) * INT_TO_FLOAT_CONST ; final float BLUE1 = COLOR1 . getBlue ( ) * INT_TO_FLOAT_CONST ; final float ALPHA1 = COLOR1 . getAlpha ( ) * INT_TO_FLOAT_CONST ; final float RED2 = COLOR2 . getRed ( ) * INT_TO_FLOAT_CONST ; final float GREEN2 = COLOR2 . getGreen ( ) * INT_TO_FLOAT_CONST ; final float BLUE2 = COLOR2 . getBlue ( ) * INT_TO_FLOAT_CONST ; final float ALPHA2 = COLOR2 . getAlpha ( ) * INT_TO_FLOAT_CONST ; final float DELTA_RED = RED2 - RED1 ; final float DELTA_GREEN = GREEN2 - GREEN1 ; final float DELTA_BLUE = BLUE2 - BLUE1 ; final float DELTA_ALPHA = ALPHA2 - ALPHA1 ; float red = RED1 + ( DELTA_RED * FRACTION ) ; float green = GREEN1 + ( DELTA_GREEN * FRACTION ) ; float blue = BLUE1 + ( DELTA_BLUE * FRACTION ) ; float alpha = ALPHA1 + ( DELTA_ALPHA * FRACTION ) ; red = red < 0f ? 0f : ( red > 1f ? 1f : red ) ; green = green < 0f ? 0f : ( green > 1f ? 1f : green ) ; blue = blue < 0f ? 0f : ( blue > 1f ? 1f : blue ) ; alpha = alpha < 0f ? 0f : ( alpha > 1f ? 1f : alpha ) ; return new Color ( red , green , blue , alpha ) ; }
Returns the interpolated color that you get if you multiply the delta between
color2 and color1 with the given fraction (for each channel) and interpolation. The fraction should
be a value between 0 and 1.
@param COLOR1 The first color as integer in the hex format 0xALPHA RED GREEN BLUE, e.g. 0xFF00FF00 for a pure green
@param COLOR2 The second color as integer in the hex format 0xALPHA RED GREEN BLUE e.g. 0xFFFF0000 for a pure red
@param FRACTION The fraction between those two colors that we would like to get e.g. 0.5f will result in the color 0xFF808000
@return the interpolated color between color1 and color2 calculated by the given fraction and interpolation