private static List < Color > createLinearGradient ( final Color color1 , final Color color2 , final int gradientSteps ) { final List < Color > colors = new ArrayList <> ( gradientSteps + 1 ) ; // add beginning color to the gradient colors . add ( color1 ) ; for ( int i = 1 ; i < gradientSteps ; i ++ ) { float ratio = ( float ) i / ( float ) gradientSteps ; final float red = color2 . getRed ( ) * ratio + color1 . getRed ( ) * ( 1 - ratio ) ; final float green = color2 . getGreen ( ) * ratio + color1 . getGreen ( ) * ( 1 - ratio ) ; final float blue = color2 . getBlue ( ) * ratio + color1 . getBlue ( ) * ( 1 - ratio ) ; colors . add ( new Color ( Math . round ( red ) , Math . round ( green ) , Math . round ( blue ) ) ) ; } // add end color to the gradient colors . add ( color2 ) ; return colors ; }
Creates a linear Gradient between two colors