Package gov.nasa.worldwind.render
Class Color
- java.lang.Object
-
- gov.nasa.worldwind.render.Color
-
public class Color extends java.lang.Object
Color with red, green, blue and alpha components. Each RGB component is a number between 0.0 and 1.0 indicating the component's intensity. The alpha component is a number between 0.0 (fully transparent) and 1.0 (fully opaque) indicating the color's opacity.
-
-
Constructor Summary
Constructors Constructor Description Color()
Constructs a color with red, green, blue and alpha all 1.0.Color(float red, float green, float blue, float alpha)
Constructs a color with specified red, green, blue and alpha components.Color(int colorInt)
Constructs a color with components stored in a color int.Color(Color color)
Constructs a color with the components of a specified color.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
int
hashCode()
Color
premultiply()
Premultiplies this color in place.Color
premultiplyColor(Color color)
Premultiplies the specified color and stores the result in this color.float[]
premultiplyToArray(float[] result, int offset)
Copies this color's premultiplied components to the specified array.Color
set(float red, float green, float blue, float alpha)
Sets this color to the specified components.Color
set(int colorInt)
Sets this color to the components stored in a color int.Color
set(Color color)
Sets this color to the components of a specified color.float[]
toArray(float[] result, int offset)
Copies this color's components to the specified array.int
toColorInt()
Returns this color's components as a color int.java.lang.String
toString()
-
-
-
Constructor Detail
-
Color
public Color()
Constructs a color with red, green, blue and alpha all 1.0.
-
Color
public Color(float red, float green, float blue, float alpha)
Constructs a color with specified red, green, blue and alpha components.- Parameters:
red
- the red componentgreen
- the green componentblue
- the blue componentalpha
- the alpha component
-
Color
public Color(int colorInt)
Constructs a color with components stored in a color int. Color ints are stored as packed ints as follows:(alpha << 24) | (red << 16) | (green << 8) | (blue)
. Each component is an 8 bit number between 0 and 255 with 0 indicating the component's intensity.- Parameters:
colorInt
- the color int specifying the components
-
Color
public Color(Color color)
Constructs a color with the components of a specified color.- Parameters:
color
- the color specifying the components- Throws:
java.lang.IllegalArgumentException
- If the color is null
-
-
Method Detail
-
set
public Color set(float red, float green, float blue, float alpha)
Sets this color to the specified components.- Parameters:
red
- the new red componentgreen
- the new green componentblue
- the new blue componentalpha
- the new alpha component- Returns:
- this color with its components set to the specified values
-
set
public Color set(int colorInt)
Sets this color to the components stored in a color int. Color ints are stored as packed ints as follows:(alpha << 24) | (red << 16) | (green << 8) | (blue)
. Each component is an 8 bit number between 0 and 255 with 0 indicating the component's intensity.- Parameters:
colorInt
- the color int specifying the new components- Returns:
- this color with its components set to those of the specified color int
-
set
public Color set(Color color)
Sets this color to the components of a specified color.- Parameters:
color
- the color specifying the new components- Returns:
- this color with its components set to that of the specified color
- Throws:
java.lang.IllegalArgumentException
- If the color is null
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toArray
public float[] toArray(float[] result, int offset)
Copies this color's components to the specified array. The result is compatible with GLSL uniform vectors, and can be passed to the function glUniform4fv.- Parameters:
result
- a pre-allocated array of length 4 in which to return the componentsoffset
- a starting index in the result array- Returns:
- the result argument set to this color's components
-
toColorInt
public int toColorInt()
Returns this color's components as a color int. Color ints are stored as packed ints as follows:(alpha << 24) | (red << 16) | (green << 8) | (blue)
. Each component is an 8 bit number between 0 and 255 with 0 indicating the component's intensity.- Returns:
- this color converted to a color int
-
premultiply
public Color premultiply()
Premultiplies this color in place. The RGB components are multiplied by the alpha component.- Returns:
- this color with its RGB components multiplied by its alpha component
-
premultiplyColor
public Color premultiplyColor(Color color)
Premultiplies the specified color and stores the result in this color. This color's RGB components are set to the product of the specified color's RGB components and its alpha component. This color's alpha component is set to the specified color's alpha.- Parameters:
color
- the color with components to premultiply and store in this color- Returns:
- this color set to the premultiplied components of the specified color
- Throws:
java.lang.IllegalArgumentException
- If the color is null
-
premultiplyToArray
public float[] premultiplyToArray(float[] result, int offset)
Copies this color's premultiplied components to the specified array. The result is compatible with GLSL uniform vectors, and can be passed to the function glUniform4fv.- Parameters:
result
- a pre-allocated array of length 4 in which to return the componentsoffset
- a starting index in the result array- Returns:
- the result argument set to this color's premultiplied components
-
-