Package stdlib
Class RGBColor
java.lang.Object
stdlib.RGBColor
This class provides a representation for a color in RGB space.
- Author:
- Swami Iyer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
getBlue()
Returns the blue component of this color.int
getGreen()
Returns the green component of this color.int
getRed()
Returns the red component of this color.boolean
isCompatible
(RGBColor other) Returnstrue
if this color is compatible withother
, andfalse
otherwise.double
Returns the luminance of this color.static void
Unit tests this data type.toGray()
Returns the grayscale equivalent of this color.toString()
Returns a string representation of this color.
-
Constructor Details
-
RGBColor
public RGBColor(int r, int g, int b) Constructs a color given its RGB components.- Parameters:
r
- red componentg
- green componentb
- blue component
-
-
Method Details
-
getRed
public int getRed()Returns the red component of this color.- Returns:
- the red component
-
getGreen
public int getGreen()Returns the green component of this color.- Returns:
- the green component
-
getBlue
public int getBlue()Returns the blue component of this color.- Returns:
- the blue component
-
luminance
public double luminance()Returns the luminance of this color.- Returns:
- the luminance
-
toGray
Returns the grayscale equivalent of this color.- Returns:
- the grayscale equivalent
-
isCompatible
Returnstrue
if this color is compatible withother
, andfalse
otherwise.- Parameters:
other
- the other color- Returns:
true
if this color is compatible withother
, andfalse
otherwise
-
toString
Returns a string representation of this color. -
main
Unit tests this data type.- Parameters:
args
- command-line arguments
-