|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.ColorRGBA
public class ColorRGBA
Helper class for exchanging RGBA colors of four float components.
ColorRGBA is a basic helper class for exchanging colors of four
float components between different software components. It does
not contain any means for color arithmetics, only methods for
setting and getting the color components. It is not meant to be used
directly by software components for color representation. Instead,
software components should use their own, appropriate classes for
handling colors. Only when sending colors to an OutSlot
, or
when receiving colors from an InSlot
, the internal
representation of colors should be converted to ColorRGBA's. This
ensures the interoperability between different software components
that use different internal representations for colors.
The first component of the color is the red component, the second component the green component, the third component the blue component, and the fourth component the alpha component. All components must be between 0 and 1, inclusively. For color components, 0 means no intensity, and 1 means maximum intensity. For the alpha component, 0 means fully transparent, and 1 means fully opaque.
The following example creates a ColorRGBA object that represents the color "red", and prints its components to the console:
ColorRGBA red = new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f); System.out.println("red component = " + red.getRed()); System.out.println("green component = " + red.getGreen()); System.out.println("blue component = " + red.getBlue()); System.out.println("alpha component = " + red.getAlpha());
Constructor Summary | |
---|---|
ColorRGBA(ColorRGBA color)
Constructor that initializes the components of the ColorRGBA object with the components taken from another ColorRGBA object. |
|
ColorRGBA(float[] color)
Constructor that initializes the components of the ColorRGBA object with the values of a given float array. |
|
ColorRGBA(float red,
float green,
float blue,
float alpha)
Constructor that initializes the components of the ColorRGBA object with the given float values. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Compares the color to another object. |
void |
get(float[] color)
Returns the values of the red, green, blue and alpha components. |
float |
getAlpha()
Returns the value of the alpha component. |
float |
getBlue()
Returns the value of the blue component. |
float |
getGreen()
Returns the value of the green component. |
float |
getRed()
Returns the value of the red component. |
java.lang.String |
toString()
Converts the color to a string. |
static ColorRGBA |
valueOf(java.lang.String str)
Converts a string to a ColorRGBA object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ColorRGBA(float red, float green, float blue, float alpha)
The following example demonstrates how to create a ColorRGBA object that represents the color "red":
float red_component = 1.0f; float green_component = 0.0f; float blue_component = 0.0f; float alpha_component = 1.0f; ColorRGBA color = new ColorRGBA(red_component, green_component, blue_component, alpha_component);
red
- Value of the red component of the new color.green
- Value of the green component of the new color.blue
- Value of the blue component of the new color.alpha
- Value of the alpha component of the new color.public ColorRGBA(float[] color)
The following example demonstrates how to create a ColorRGBA object that represents the color "red":
float red_component = 1.0f; float green_component = 0.0f; float blue_component = 0.0f; float alpha_component = 1.0f; float[] color_components = new float[] { red_component, green_component, blue_component, alpha_component }; ColorRGBA color = new ColorRGBA(color_components);
color
- An array of at least four float values. The red component
of the color is set to the value of the first element of the array,
the green component is set to the value of the second element of the
array, the blue component is set to the value of the third element of the
array and the alpha component is set to the value of the fourth element of the
array.public ColorRGBA(ColorRGBA color)
The following example demonstrates how to create a ColorRGBA object that is an exact copy of another ColorRGBA object:
ColorRGBA given_color = ...; ColorRGBA color = new ColorRGBA(given_color);
color
- The other color used to initialize the new color.Method Detail |
---|
public final float getRed()
The following example demonstrates how to print the red color component of a ColorRGBA object to the console:
ColorRGBA color = ...; System.out.println("red component = " + color.getRed());
public final float getGreen()
The following example demonstrates how to print the green color component of a ColorRGBA object to the console:
ColorRGBA color = ...; System.out.println("green component = " + color.getGreen());
public final float getBlue()
The following example demonstrates how to print the blue color component of a ColorRGBA object to the console:
ColorRGBA color = ...; System.out.println("blue component = " + color.getBlue());
public final float getAlpha()
The following example demonstrates how to print the alpha color component of a ColorRGBA object to the console:
ColorRGBA color = ...; System.out.println("alpha component = " + color.getAlpha());
public final void get(float[] color)
The following example prints the color components of a ColorRGBA object to the console:
ColorRGBA color = ...; float[] color_components = new float[4]; color.get(color_components); System.out.println("red component = " + color_components[0]); System.out.println("green component = " + color_components[1]); System.out.println("blue component = " + color_components[2]); System.out.println("alpha component = " + color_components[3]);
color
- A float array that gets filled with the components of the
color. This array must have at least four elements. The first
element of the array is set to the red component of the color, the
second element of the array is set to the green component of the color,
the third element of the array is set to the blue component of the
color, and the fourth element of the array is set to the alpha component
of the color.public final boolean equals(java.lang.Object obj)
The following example compares two colors and prints the result to the console:
ColorRGBA color1 = ...; ColorRGBA color2 = ...; System.out.println("Colors are the same: " + color1.equals(color2));
equals
in class java.lang.Object
obj
- the object to compare the color to
public final java.lang.String toString()
The following example prints the string representation of a ColorRGBA object to the console:
ColorRGBA color = ...; System.out.println("Color = " + color.toString());
toString
in class java.lang.Object
public static final ColorRGBA valueOf(java.lang.String str)
The following example creates a new ColorRGBA object that represents the color "red":
Color color = Color.valueOf("1.0 0.0 0.0 1.0");
str
- The string representation of the color.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |