Package greenfoot

Class Color


  • public class Color
    extends java.lang.Object
    A representation of a Color. The Color can be used to draw or fill shapes on the screen.
    Author:
    Fabio Heday
    • Constructor Summary

      Constructors 
      Constructor Description
      Color​(int r, int g, int b)
      Creates a RGB color with the specified red, green, blue values in the range (0 - 255).
      Color​(int r, int g, int b, int a)
      Creates a RGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Color brighter()
      Creates a new color that is a brighter version of this GreenfootColor.
      Color darker()
      Creates a new GreenfootColor that is a darker version of this GreenfootColor.
      boolean equals​(java.lang.Object obj)
      Determines whether another object is equal to this color.
      int getAlpha()
      Returns the alpha component in the range 0-255.
      int getBlue()
      Returns the blue component in the range 0-255 in the default RGB space.
      int getGreen()
      Returns the green component in the range 0-255 in the default RGB space.
      int getRed()
      Returns the red component in the range 0-255 in the default RGB space.
      int hashCode()
      Computes the hash code for this Color.
      java.lang.String toString()
      Return a text representation of the color.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • WHITE

        public static final Color WHITE
        The color white. In the default RGB space.
      • LIGHT_GRAY

        public static final Color LIGHT_GRAY
        The color light gray. In the default RGB space.
      • GRAY

        public static final Color GRAY
        The color gray. In the default RGB space.
      • DARK_GRAY

        public static final Color DARK_GRAY
        The color dark gray. In the default RGB space.
      • BLACK

        public static final Color BLACK
        The color black. In the default RGB space.
      • RED

        public static final Color RED
        The color red. In the default RGB space.
      • PINK

        public static final Color PINK
        The color pink. In the default RGB space.
      • ORANGE

        public static final Color ORANGE
        The color orange. In the default RGB space.
      • YELLOW

        public static final Color YELLOW
        The color yellow. In the default RGB space.
      • GREEN

        public static final Color GREEN
        The color green. In the default RGB space.
      • MAGENTA

        public static final Color MAGENTA
        The color magenta. In the default RGB space.
      • CYAN

        public static final Color CYAN
        The color cyan. In the default RGB space.
      • BLUE

        public static final Color BLUE
        The color blue. In the default RGB space.
    • Constructor Detail

      • Color

        public Color​(int r,
                     int g,
                     int b)
        Creates a RGB color with the specified red, green, blue values in the range (0 - 255).
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
      • Color

        public Color​(int r,
                     int g,
                     int b,
                     int a)
        Creates a RGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
        a - the alpha component
    • Method Detail

      • brighter

        public Color brighter()
        Creates a new color that is a brighter version of this GreenfootColor.

        This method creates a brighter version of this color. The alpha value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

        Returns:
        a new GreenfootColor object that is a brighter version of this GreenfootColor with the same alpha value.
      • darker

        public Color darker()
        Creates a new GreenfootColor that is a darker version of this GreenfootColor.

        This method creates a darker version of this color. The alpha value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

        Returns:
        a new GreenfootColor object that is a darker version of this GreenfootColor with the same alpha value.
      • equals

        public boolean equals​(java.lang.Object obj)
        Determines whether another object is equal to this color.

        The result is true if and only if the argument is not null and is a greenfoot.Color object that has the same red, green, blue, and alpha values as this object.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to test for equality with this color
        Returns:
        true if the colors are the same; false otherwise.
      • getRed

        public int getRed()
        Returns the red component in the range 0-255 in the default RGB space.
        Returns:
        the red component.
      • getGreen

        public int getGreen()
        Returns the green component in the range 0-255 in the default RGB space.
        Returns:
        the green component.
      • getAlpha

        public int getAlpha()
        Returns the alpha component in the range 0-255.
        Returns:
        the alpha component.
      • getBlue

        public int getBlue()
        Returns the blue component in the range 0-255 in the default RGB space.
        Returns:
        the blue component.
      • hashCode

        public int hashCode()
        Computes the hash code for this Color.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code value for this object.
      • toString

        public java.lang.String toString()
        Return a text representation of the color.
        Overrides:
        toString in class java.lang.Object