Class Color

java.lang.Object
org.strassburger.colorlab4j.color.Color
Direct Known Subclasses:
HSLColor, HSVColor, LABColor, RGBColor, XYZColor

public abstract class Color extends Object
Abstract representation of a color. Provides methods to convert between different color spaces.
  • Constructor Details

    • Color

      public Color()
  • Method Details

    • toRGB

      public abstract RGBColor toRGB()
      Convert the color to RGB
      Returns:
      RGB representation of the color
    • toHSL

      public abstract HSLColor toHSL()
      Convert the color to HSL
      Returns:
      HSL representation of the color
    • toHSV

      public abstract HSVColor toHSV()
      Convert the color to HSV
      Returns:
      HSV representation of the color
    • toLAB

      public abstract LABColor toLAB()
      Convert the color to LAB
      Returns:
      LAB representation of the color
    • toXYZ

      public abstract XYZColor toXYZ()
      Convert the color to XYZ
      Returns:
      XYZ representation of the color
    • toHex

      public String toHex()
      Get the hex representation of the color
      Returns:
      Hex representation of the color (e.g. "#ff0000")
    • toAnsi

      public String toAnsi()
      Get the ANSI representation of the color
      Returns:
      ANSI representation of the color
    • toAnsiBackground

      public String toAnsiBackground()
      Get the ANSI representation of the color for the background
      Returns:
      ANSI representation of the color for the background
    • toCssString

      public abstract String toCssString()
      Get the CSS representation of the color
      Returns:
      CSS representation of the color
    • fromHex

      public static Color fromHex(String hex)
      Get the color from a hex string
      Parameters:
      hex - Hex representation of the color (e.g. "#ff0000")
      Returns:
      Color representation of the color
      Throws:
      IllegalArgumentException - If the HEX code is invalid
    • rgb

      public static RGBColor rgb(int r, int g, int b)
      Create an RGB color
      Parameters:
      r - Red component (0-255)
      g - Green component (0-255)
      b - Blue component (0-255)
      Returns:
      RGBColor instance
    • hsl

      public static HSLColor hsl(double h, double s, double l)
      Create an HSL color
      Parameters:
      h - Hue component (0-360)
      s - Saturation component (0-1)
      l - Lightness component (0-1)
      Returns:
      HSLColor instance
    • hsv

      public static HSVColor hsv(double h, double s, double v)
      Create an HSV color
      Parameters:
      h - Hue component (0-360)
      s - Saturation component (0-1)
      v - Value component (0-1)
      Returns:
      HSVColor instance
    • lab

      public static LABColor lab(double l, double a, double b)
      Create a LAB color
      Parameters:
      l - Lightness component
      a - A component
      b - B component
      Returns:
      LABColor instance
    • xyz

      public static XYZColor xyz(double x, double y, double z)
      Create an XYZ color
      Parameters:
      x - X component
      y - Y component
      z - Z component
      Returns:
      XYZColor instance