Package de.gurkenlabs.litiengine.util
Class ColorHelper
java.lang.Object
de.gurkenlabs.litiengine.util.ColorHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic ColorDecodes the specified color string to an actualColorinstance.static ColorDecodes the specified color string to an actualColorinstance, with an option to create a darker version of the base color.static StringEncodes the specified color to a hexadecimal string representation.static intensureColorValueRange(float value) Ensures that the specified value lies within the accepted range for Color values (0-255).static intensureColorValueRange(int value) Ensures that the specified value lies within the accepted range for Color values (0-255).static ColorgetTransparentVariant(Color color, int newAlpha) Returns a transparent variant of the specified color with the given alpha value.static Colorinterpolate(Color color1, Color color2, double factor) Interpolates between two colors based on the given factor.static Colorpremultiply(Color color) Premultiplies the alpha on the given color.
-
Method Details
-
encode
Encodes the specified color to a hexadecimal string representation. The output format is:- #RRGGBB - For colors without alpha
- #AARRGGBB - For colors with alpha
Examples:
Color.RED= "#ff0000"
new Color(255, 0, 0, 200)= "#c8ff0000"- Parameters:
color- The color that is encoded.- Returns:
- An hexadecimal string representation of the specified color.
- See Also:
-
decode
Decodes the specified color string to an actualColorinstance. The accepted format is:Note: This returns null if the format of the provided color string is invalid.
- #RRGGBB - For colors without alpha
- #AARRGGBB - For colors with alpha
Examples:
"#ff0000" =Color.RED
"#c8ff0000" =new Color(255, 0, 0, 200)- Parameters:
colorHexString- The hexadecimal encodes color string representation.- Returns:
- The decoded color.
- See Also:
-
decode
Decodes the specified color string to an actualColorinstance, with an option to create a darker version of the base color. The accepted format is:- #RRGGBB - For colors without alpha
- #AARRGGBB - For colors with alpha
If the `solid` parameter is true, the color alpha will create a darker version of the base color.
Examples:
"#ff0000" =Color.RED
"#c8ff0000" =new Color(255, 0, 0, 200)- Parameters:
colorHexString- The hexadecimal encoded color string representation.solid- If true, the color alpha will create a darker version of the base color.- Returns:
- The decoded
Colorobject, ornullif the input string is invalid. - See Also:
-
ensureColorValueRange
public static int ensureColorValueRange(float value) Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.- Parameters:
value- The value to check for.- Returns:
- An integer value that fits the color value restrictions.
-
ensureColorValueRange
public static int ensureColorValueRange(int value) Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.- Parameters:
value- The value to check for.- Returns:
- An integer value that fits the color value restrictions.
-
premultiply
Premultiplies the alpha on the given color.- Parameters:
color- The color to premultiply- Returns:
- The color given, with alpha replaced with a black background.
-
interpolate
Interpolates between two colors based on the given factor. The factor determines the weight of each color in the interpolation. A factor of 0.0 will return the first color, and a factor of 1.0 will return the second color. Intermediate values will return a blend of the two colors.- Parameters:
color1- The first color.color2- The second color.factor- The interpolation factor, ranging from 0.0 to 1.0.- Returns:
- A new
Colorobject that is the result of interpolating between the two colors.
-
getTransparentVariant
Returns a transparent variant of the specified color with the given alpha value. The red, green, and blue components of the color remain unchanged.- Parameters:
color- The original color.newAlpha- The new alpha value to be applied to the color.- Returns:
- A new
Colorobject with the specified alpha value.
-