Class Color
This is the engine's own color class (not Color). All color values
use integer components in the range 0-255. The class provides predefined constants
for common colors and several constructors for creating colors from different formats.
Mutability: Color fields are mutable to enable reuse during rendering (e.g., lighting calculations). This avoids allocating new Color instances per polygon.
Usage examples:
// Use predefined color constants
Color red = Color.RED;
Color semiTransparent = Color.hex("FF000080");
// Create from hex string (recommended)
Color hex6 = Color.hex("FF8800"); // RGB, fully opaque
Color hex8 = Color.hex("FF880080"); // RGBA with alpha
Color hex3 = Color.hex("F80"); // Short RGB format
// Create from integer RGBA components (0-255)
Color custom = new Color(100, 200, 50, 255);
// Create from packed RGB integer
Color packed = new Color(0xFF8800);
// Modify existing color (avoids allocation)
color.set(255, 128, 0, 255);
Important: Always use this class instead of Color when
working with the Sixth 3D engine's rendering pipeline.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionintAlpha component.intBlue component.static final ColorFully opaque black (0, 0, 0).static final ColorFully opaque blue (0, 0, 255).static final ColorFully opaque cyan (0, 255, 255).intGreen component.static final ColorFully opaque green (0, 255, 0).static final ColorFully opaque magenta/purple (255, 0, 255).static final ColorFully opaque purple/magenta (255, 0, 255).intRed component.static final ColorFully opaque red (255, 0, 0).static final ColorFully transparent (alpha = 0).static final ColorFully opaque white (255, 255, 255).static final ColorFully opaque yellow (255, 255, 0). -
Constructor Summary
ConstructorsConstructorDescriptionColor()Creates a black, fully opaque color (0, 0, 0, 255).Color(double r, double g, double b, double a) Creates a color from floating-point RGBA components in the range 0.0 to 1.0.Color(int rgb) Creates a fully opaque color from a packed RGB integer.Color(int r, int g, int b) Creates a fully opaque color from RGB integer components (0-255).Color(int r, int g, int b, int a) Creates a color from RGBA integer components (0-255).Creates a copy of the given color.Creates a color from a hexadecimal string. -
Method Summary
Modifier and TypeMethodDescriptionstatic intclamp(int value) Clamps a value to the valid color component range (0-255).booleaninthashCode()static ColorCreates a color from a hexadecimal string.booleanReturnstrueif this color is fully transparent (alpha = 0).set(int r, int g, int b, int a) Sets all color components at once.Copies values from another color.Converts this color to aColorinstance for use with Java AWT/Swing graphics APIs.inttoInt()Converts this color to a packed ARGB integer as used byColor.getRGB().
-
Field Details
-
RED
Fully opaque red (255, 0, 0). -
GREEN
Fully opaque green (0, 255, 0). -
BLUE
Fully opaque blue (0, 0, 255). -
YELLOW
Fully opaque yellow (255, 255, 0). -
CYAN
Fully opaque cyan (0, 255, 255). -
MAGENTA
Fully opaque magenta/purple (255, 0, 255). -
WHITE
Fully opaque white (255, 255, 255). -
BLACK
Fully opaque black (0, 0, 0). -
PURPLE
Fully opaque purple/magenta (255, 0, 255). -
TRANSPARENT
Fully transparent (alpha = 0). -
r
public int rRed component. 0-255. -
g
public int gGreen component. 0-255. -
b
public int bBlue component. 0-255. -
a
public int aAlpha component. 0 - transparent. 255 - opaque.
-
-
Constructor Details
-
Color
public Color()Creates a black, fully opaque color (0, 0, 0, 255). -
Color
Creates a copy of the given color.- Parameters:
parentColor- the color to copy
-
Color
public Color(double r, double g, double b, double a) Creates a color from floating-point RGBA components in the range 0.0 to 1.0. Values are internally converted to 0-255 integer range and clamped.- Parameters:
r- red component (0.0 = none, 1.0 = full)g- green component (0.0 = none, 1.0 = full)b- blue component (0.0 = none, 1.0 = full)a- alpha component (0.0 = transparent, 1.0 = opaque)
-
Color
Creates a color from a hexadecimal string.- Parameters:
colorHexCode- color code in hex format. Supported formats are:RGB RGBA RRGGBB RRGGBBAA
-
Color
public Color(int rgb) Creates a fully opaque color from a packed RGB integer.The integer is interpreted as
0xRRGGBB, where the upper 8 bits are the red channel, the middle 8 bits are green, and the lower 8 bits are blue.- Parameters:
rgb- packed RGB value (e.g.0xFF8800for orange)
-
Color
public Color(int r, int g, int b) Creates a fully opaque color from RGB integer components (0-255).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)
-
Color
public Color(int r, int g, int b, int a) Creates a color from RGBA integer components (0-255). Values outside 0-255 are clamped.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)a- alpha component (0 = transparent, 255 = opaque)
-
-
Method Details
-
hex
Creates a color from a hexadecimal string.Supported formats:
RGB- 3 hex digits, fully opaqueRGBA- 4 hex digitsRRGGBB- 6 hex digits, fully opaqueRRGGBBAA- 8 hex digits
- Parameters:
hex- hex color code- Returns:
- a new Color instance
-
clamp
public static int clamp(int value) Clamps a value to the valid color component range (0-255).- Parameters:
value- the value to clamp- Returns:
- the clamped value
-
isTransparent
public boolean isTransparent()Returnstrueif this color is fully transparent (alpha = 0).- Returns:
trueif the alpha component is zero
-
set
Sets all color components at once.Values outside 0-255 are clamped. This method invalidates any cached AWT color, so the next call to
toAwtColor()will create a new one.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)a- alpha component (0-255)- Returns:
- this Color for chaining
-
set
Copies values from another color.- Parameters:
other- the color to copy from- Returns:
- this Color for chaining
-
toAwtColor
Converts this color to aColorinstance for use with Java AWT/Swing graphics APIs.- Returns:
- the equivalent
Color
-
toInt
public int toInt()Converts this color to a packed ARGB integer as used byColor.getRGB().- Returns:
- packed ARGB integer representation
-
equals
-
hashCode
public int hashCode()
-