java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.Color

public final class Color extends Object
RGBA color representation for the Sixth 3D engine.

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

    Fields
    Modifier and Type
    Field
    Description
    int
    Alpha component.
    int
    Blue component.
    static final Color
    Fully opaque black (0, 0, 0).
    static final Color
    Fully opaque blue (0, 0, 255).
    static final Color
    Fully opaque cyan (0, 255, 255).
    int
    Green component.
    static final Color
    Fully opaque green (0, 255, 0).
    static final Color
    Fully opaque magenta/purple (255, 0, 255).
    static final Color
    Fully opaque purple/magenta (255, 0, 255).
    int
    Red component.
    static final Color
    Fully opaque red (255, 0, 0).
    static final Color
    Fully transparent (alpha = 0).
    static final Color
    Fully opaque white (255, 255, 255).
    static final Color
    Fully opaque yellow (255, 255, 0).
  • Constructor Summary

    Constructors
    Constructor
    Description
    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).
    Color(Color parentColor)
    Creates a copy of the given color.
    Color(String colorHexCode)
    Creates a color from a hexadecimal string.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    clamp(int value)
    Clamps a value to the valid color component range (0-255).
    boolean
     
    int
     
    static Color
    hex(String hex)
    Creates a color from a hexadecimal string.
    boolean
    Returns true if this color is fully transparent (alpha = 0).
    set(int r, int g, int b, int a)
    Sets all color components at once.
    set(Color other)
    Copies values from another color.
    Converts this color to a Color instance for use with Java AWT/Swing graphics APIs.
    int
    Converts this color to a packed ARGB integer as used by Color.getRGB().

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RED

      public static final Color RED
      Fully opaque red (255, 0, 0).
    • GREEN

      public static final Color GREEN
      Fully opaque green (0, 255, 0).
    • BLUE

      public static final Color BLUE
      Fully opaque blue (0, 0, 255).
    • YELLOW

      public static final Color YELLOW
      Fully opaque yellow (255, 255, 0).
    • CYAN

      public static final Color CYAN
      Fully opaque cyan (0, 255, 255).
    • MAGENTA

      public static final Color MAGENTA
      Fully opaque magenta/purple (255, 0, 255).
    • WHITE

      public static final Color WHITE
      Fully opaque white (255, 255, 255).
    • BLACK

      public static final Color BLACK
      Fully opaque black (0, 0, 0).
    • PURPLE

      public static final Color PURPLE
      Fully opaque purple/magenta (255, 0, 255).
    • TRANSPARENT

      public static final Color TRANSPARENT
      Fully transparent (alpha = 0).
    • r

      public int r
      Red component. 0-255.
    • g

      public int g
      Green component. 0-255.
    • b

      public int b
      Blue component. 0-255.
    • a

      public int a
      Alpha component. 0 - transparent. 255 - opaque.
  • Constructor Details

    • Color

      public Color()
      Creates a black, fully opaque color (0, 0, 0, 255).
    • Color

      public Color(Color parentColor)
      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

      public Color(String colorHexCode)
      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. 0xFF8800 for 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

      public static Color hex(String hex)
      Creates a color from a hexadecimal string.

      Supported formats:

      • RGB - 3 hex digits, fully opaque
      • RGBA - 4 hex digits
      • RRGGBB - 6 hex digits, fully opaque
      • RRGGBBAA - 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()
      Returns true if this color is fully transparent (alpha = 0).
      Returns:
      true if the alpha component is zero
    • set

      public Color set(int r, int g, int b, int a)
      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

      public Color set(Color other)
      Copies values from another color.
      Parameters:
      other - the color to copy from
      Returns:
      this Color for chaining
    • toAwtColor

      public Color toAwtColor()
      Converts this color to a Color instance 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 by Color.getRGB().
      Returns:
      packed ARGB integer representation
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object