Class Color

java.lang.Object
com.xebisco.yield.Color
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ImmutableColor

public class Color extends Object implements Cloneable
This class represents a color with RGB or ARGB format. Storing red, green, blue and alpha values with double floating point precision.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    This enumeration is used to specify the format of the color value when creating a new `Color` object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Color(double red, double green, double blue)
    Constructor that takes red, green, and blue values.
    Color(double red, double green, double blue, double alpha)
    Constructor that takes red, green, blue, and alpha values.
    Color(int rgb, double alpha)
    Constructor that takes an RGB value and an alpha value.
    Color(long color)
    Constructor that takes a long value representing a color.
    Color(long color, Color.Format format)
    Constructor that takes a long value representing a color and a format.
    Color(Color toCopy)
    Constructor that takes another Color object and creates a copy of it.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Getter of the alpha value of this Color.
    int
    The function returns an integer value representing the ARGB color code based on the alpha, red, green, and blue values.
    double
    Getter of the blue value of this Color.
    Returns a new Color object that is a lighter version of this Color object.
    brighter(double value)
    Returns a new color with the same hue and saturation, but with a brighter value.
     
    Returns a new Color object that is a darker version of this Color object.
    darker(double value)
    If the color is already black, return black.
    boolean
     
    double
    Getter of the green value of this Color.
    int
     
    Invert the color by subtracting each component from 1.
    double
    red()
    Getter of the red value of this Color.
    int
    rgb()
    The function returns an integer representation of the RGB color values by converting the red, green, and blue values to their corresponding 8-bit values and combining them.
    int
    The function returns an integer value representing the RGBA color code based on the given red, green, blue, and alpha values.
    setAlpha(double alpha)
    Setter of the alpha value of this Color.
    setBlue(double blue)
    Setter of the blue value of this Color.
    setGreen(double green)
    Setter of the green value of this Color.
    setRed(double red)
    Setter of the red value of this Color.
     

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Color

      public Color(long color)
      Constructor that takes a long value representing a color.
      Parameters:
      color - The long value representing the color.
    • Color

      public Color(long color, Color.Format format)
      Constructor that takes a long value representing a color and a format.
      Parameters:
      color - The long value representing the color.
      format - The format of the color value.
    • Color

      public Color(Color toCopy)
      Constructor that takes another Color object and creates a copy of it.
      Parameters:
      toCopy - The Color object to copy.
    • Color

      public Color(int rgb, double alpha)
      Constructor that takes an RGB value and an alpha value.
      Parameters:
      rgb - The RGB value.
      alpha - The alpha value.
    • Color

      public Color(double red, double green, double blue)
      Constructor that takes red, green, and blue values.
      Parameters:
      red - The red value.
      green - The green value.
      blue - The blue value.
    • Color

      public Color(double red, double green, double blue, double alpha)
      Constructor that takes red, green, blue, and alpha values.
      Parameters:
      red - The red value.
      green - The green value.
      blue - The blue value.
      alpha - The alpha value.
  • Method Details

    • invert

      public Color invert()
      Invert the color by subtracting each component from 1.
      Returns:
      A new Color object with the inverted values of the original Color object.
    • brighter

      public Color brighter(double value)
      Returns a new color with the same hue and saturation, but with a brighter value.
      Parameters:
      value - The amount to brighten the color by.
      Returns:
      A new color with the same alpha value but with the red, green, and blue values increased by the value parameter.
    • darker

      public Color darker(double value)
      If the color is already black, return black.
      Parameters:
      value - The amount to brighten or darken the color.
      Returns:
      A new Color object with the same RGB values as the original, but with the brightness adjusted by the value.
    • darker

      public Color darker()
      Returns a new Color object that is a darker version of this Color object.
      Returns:
      A new Color object with the same RGB values as the original, but with the brightness reduced by 20%.
    • brighter

      public Color brighter()
      Returns a new Color object that is a lighter version of this Color object.
      Returns:
      A new Color object with the same RGB values as the original, but with the brightness increased by 20%.
    • red

      public double red()
      Getter of the red value of this Color.
      Returns:
      The 'red' variable.
    • setRed

      public Color setRed(double red)
      Setter of the red value of this Color.
    • green

      public double green()
      Getter of the green value of this Color.
      Returns:
      The 'green' variable.
    • setGreen

      public Color setGreen(double green)
      Setter of the green value of this Color.
    • blue

      public double blue()
      Getter of the blue value of this Color.
      Returns:
      The 'blue' variable.
    • setBlue

      public Color setBlue(double blue)
      Setter of the blue value of this Color.
    • alpha

      public double alpha()
      Getter of the alpha value of this Color.
      Returns:
      The 'alpha' variable.
    • setAlpha

      public Color setAlpha(double alpha)
      Setter of the alpha value of this Color.
    • rgb

      public int rgb()
      The function returns an integer representation of the RGB color values by converting the red, green, and blue values to their corresponding 8-bit values and combining them.
      Returns:
      The method is returning an integer value that represents the RGB color of the object. The RGB value is calculated by multiplying the red, green, and blue values by 255 and then shifting them to the appropriate positions in the integer value.
    • argb

      public int argb()
      The function returns an integer value representing the ARGB color code based on the alpha, red, green, and blue values.
      Returns:
      The method is returning an integer value that represents the ARGB (Alpha, Red, Green, Blue) color code of the color object.
    • rgba

      public int rgba()
      The function returns an integer value representing the RGBA color code based on the given red, green, blue, and alpha values.
      Returns:
      The method is returning an integer value that represents the RGBA color value of the object. The value is obtained by shifting the red, green, blue, and alpha values to their respective positions in the 8-bit integer and then combining them using bitwise operations.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public Color clone()
      Overrides:
      clone in class Object