Class Color

    • Constructor Summary

      Constructors 
      Constructor Description
      Color​(int rgb)
      Creates a color based on an RGB value.
      Color​(int red, int green, int blue)
      Creates a color that has the specified red, green, and blue values within the range [0 - 255].
      Color​(int red, int green, int blue, int alpha)
      Creates a color that has the specified red, green, blue, and alpha values within the range [0 - 255].
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(Object obj)  
      int getAlpha()
      Returns the alpha value of the color.
      int getBlue()
      Returns the blue value of the color.
      String getCSS()
      Returns CSS representation of the Color, e.g. #000000.
      int getGreen()
      Returns the green value of the color.
      float[] getHSV()
      Returns converted HSV components of the color.
      int getRed()
      Returns the red value of the color.
      int getRGB()
      Returns RGB value of the color.
      int hashCode()  
      static int HSLtoRGB​(int hue, int saturation, int lightness)
      Converts HSL's hue, saturation and lightness into an RGB value.
      static int HSVtoRGB​(float hue, float saturation, float value)
      Converts HSV's hue, saturation and value into an RGB value.
      void setAlpha​(int alpha)
      Sets the alpha value of the color.
      void setBlue​(int blue)
      Sets the blue value of the color.
      void setGreen​(int green)
      Sets the green value of the color.
      void setRed​(int red)
      Sets the red value of the color.
    • Field Detail

      • WHITE

        public static final Color WHITE
      • BLACK

        public static final Color BLACK
      • RED

        public static final Color RED
      • GREEN

        public static final Color GREEN
      • BLUE

        public static final Color BLUE
      • YELLOW

        public static final Color YELLOW
      • MAGENTA

        public static final Color MAGENTA
      • CYAN

        public static final Color CYAN
    • Constructor Detail

      • Color

        public Color​(int red,
                     int green,
                     int blue,
                     int alpha)
        Creates a color that has the specified red, green, blue, and alpha values within the range [0 - 255].
        Parameters:
        red - the red value
        green - the green value
        blue - the blue value
        alpha - the alpha value
        Throws:
        IllegalArgumentException - if red, green, blue or alpha fall outside of the inclusive range from 0 to 255
      • Color

        public Color​(int red,
                     int green,
                     int blue)
        Creates a color that has the specified red, green, and blue values within the range [0 - 255]. Alpha gets the default value of 255.
        Parameters:
        red - the red value
        green - the green value
        blue - the blue value
        Throws:
        IllegalArgumentException - if red, green or blue fall outside of the inclusive range from 0 to 255
      • Color

        public Color​(int rgb)
        Creates a color based on an RGB value.
        Parameters:
        rgb - the RGB value
        Throws:
        IllegalArgumentException - if converted values of red, green, blue or alpha fall outside of the inclusive range from 0 to 255
    • Method Detail

      • getRed

        public int getRed()
        Returns the red value of the color.
      • setRed

        public void setRed​(int red)
        Sets the red value of the color. Value must be within the range [0, 255].
        Parameters:
        red - new red value
      • getGreen

        public int getGreen()
        Returns the green value of the color.
      • setGreen

        public void setGreen​(int green)
        Sets the green value of the color. Value must be within the range [0, 255].
        Parameters:
        green - new green value
      • getBlue

        public int getBlue()
        Returns the blue value of the color.
      • setBlue

        public void setBlue​(int blue)
        Sets the blue value of the color. Value must be within the range [0, 255].
        Parameters:
        blue - new blue value
      • getAlpha

        public int getAlpha()
        Returns the alpha value of the color.
      • setAlpha

        public void setAlpha​(int alpha)
        Sets the alpha value of the color. Value must be within the range [0, 255].
        Parameters:
        alpha - new alpha value
      • getCSS

        public String getCSS()
        Returns CSS representation of the Color, e.g. #000000.
      • getRGB

        public int getRGB()
        Returns RGB value of the color.
      • getHSV

        public float[] getHSV()
        Returns converted HSV components of the color.
      • hashCode

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

        public static int HSVtoRGB​(float hue,
                                   float saturation,
                                   float value)

        Converts HSV's hue, saturation and value into an RGB value.

        The saturation and value components should be floating-point values within the range [0.0-1.0].

        Parameters:
        hue - the hue of the color
        saturation - the saturation of the color
        value - the value of the color
        Returns:
        the RGB value of corresponding color
      • HSLtoRGB

        public static int HSLtoRGB​(int hue,
                                   int saturation,
                                   int lightness)

        Converts HSL's hue, saturation and lightness into an RGB value.

        Parameters:
        hue - the hue of the color. The unit of the value is degrees and should be between 0-360.
        saturation - the saturation of the color. The unit of the value is percentages and should be between 0-100;
        lightness - the lightness of the color. The unit of the value is percentages and should be between 0-100;
        Returns:
        the RGB value of corresponding color