public final class Colors extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
blend(int first,
int second)
Same as
blend(int, int, float) with 0.5 blending ratio. |
static int |
blend(int first,
int second,
float blendingRatio)
Blends the given colors together in the specified blending.
|
static int |
brighter(int color,
float fraction)
Transforms the given color by changing its components (except alpha) to the brightest
ones by multiplying theirs current value with (
1.0 + fraction). |
static int |
darker(int color,
float fraction)
Transforms the given color by changing its components (except alpha) to the darkest
ones by multiplying theirs current value with (
1.0 - fraction). |
static String |
hexName(int color)
Same as
hexName(int, boolean) with withAlpha flag set to true. |
static String |
hexName(int color,
boolean withAlpha)
Returns the name of the specified color represented by hexadecimal values of its current components.
|
static int |
random(boolean randomAlpha)
Returns a new color with random components.
|
static int |
withAlpha(int color,
float alphaRatio)
Same as
withAlpha(int, int) with alpha ratio support. |
static int |
withAlpha(int color,
int alpha)
Transforms the given color in a way that changes its alpha value to the given one.
|
public static int withAlpha(int color,
float alphaRatio)
withAlpha(int, int) with alpha ratio support.
Alpha ratio must be in the [0.0, 1.0] range, otherwise an exception is thrown.
color - Color to transform.alphaRatio - Ratio used to calculate value of alpha component (0.0 = fully transparent, 1.0 = fully opaque).IllegalArgumentException - If the specified alpha ratio is not from the required range.public static int withAlpha(int color,
int alpha)
Alpha value must be in the [0, 255] range, otherwise an exception is thrown.
color - Color to transform.alpha - New value of alpha component (0 = fully transparent, 255 = fully opaque).IllegalArgumentException - If the specified alpha is not from the required range.public static int blend(int first,
int second)
blend(int, int, float) with 0.5 blending ratio.public static int blend(int first,
int second,
float blendingRatio)
Blending ratio must be in the [0.0, 1.0] range, otherwise an exception is thrown.
first - First color to be blended with the second one.second - Second color to be blended with the first one.blendingRatio - Ratio used to blend the given two colors. Use ratio from range [0.0, 1.0].
1.0 ratio will return first, 0.0 ratio
will return second color.IllegalArgumentException - If the specified blending ratio is not from the required range.public static int brighter(int color,
float fraction)
1.0 + fraction).
Transforming fraction must be in the [0.0, 1.0] range, otherwise an exception is thrown.
fraction - Fraction used to transform color components. Use for example 0.75 if
the resulting color should be brighter by 75%.color.IllegalArgumentException - If the specified fraction is not from the required range.darker(int, float),
blend(int, int, float)public static int darker(int color,
float fraction)
1.0 - fraction).
Transforming fraction must be in the [0.0, 1.0] range, otherwise an exception is thrown.
fraction - Fraction used to transform color components. Use for example 0.25 if
the resulting color should be darker by 25%.color.IllegalArgumentException - If the specified fraction is not from the required range.brighter(int, float),
blend(int, int, float)public static int random(boolean randomAlpha)
randomAlpha - If true, the random selection will be also applied to the alpha
component, otherwise alpha component will be set to 255.@NonNull public static String hexName(int color)
hexName(int, boolean) with withAlpha flag set to true.@NonNull public static String hexName(int color, boolean withAlpha)
color - The color of which hexadecimal name to obtain.withAlpha - If true, the hexadecimal name will be returned also with the alpha
component, otherwise without it.black color => #000000, white color => #ffffff or with
alpha #33000000, #00ffffff.