Class Luminance
- Object
- 
- Luminance
 
- 
 public class Luminance extends Object The classLuminanceis a library of static methods related to the monochrome luminance of a color. It supports computing the monochrome luminance of a color (r, g, b) using the NTSC formula Y = 0.299*r + 0.587*g + 0.114*b; converting the color to a grayscale color, and checking whether two colors are compatible.For additional documentation, see Section 3.1 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne. - Author:
- Robert Sedgewick, Kevin Wayne
 
- 
- 
Constructor SummaryConstructors Constructor Description Luminance()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareCompatible(Color a, Color b)Are the two given colors compatible? Two colors are compatible if the difference in their monochrome luminances is at least 128.0).static doubleintensity(Color color)Returns the monochrome luminance of the given color as an intensity between 0.0 and 255.0 using the NTSC formula Y = 0.299*r + 0.587*g + 0.114*b.static voidmain(String[] args)Takes six command-line arguments r1, g1, b1, r2, g2, and b2, prints to standard output the monochrome luminances of (r1, g1, b1) and (r2, g2, b2) and whether they are compatible.static ColortoGray(Color color)Returns a grayscale version of the given color as aColorobject.
 
- 
- 
- 
Method Detail- 
intensitypublic static double intensity(Color color) Returns the monochrome luminance of the given color as an intensity between 0.0 and 255.0 using the NTSC formula Y = 0.299*r + 0.587*g + 0.114*b. If the given color is a shade of gray (r = g = b), this method is guaranteed to return the exact grayscale value (an integer with no floating-point roundoff error).- Parameters:
- color- the color to convert
- Returns:
- the monochrome luminance (between 0.0 and 255.0)
 
 - 
toGraypublic static Color toGray(Color color) Returns a grayscale version of the given color as aColorobject.- Parameters:
- color- the- Colorobject to convert to grayscale
- Returns:
- a grayscale version of color
 
 - 
areCompatiblepublic static boolean areCompatible(Color a, Color b) Are the two given colors compatible? Two colors are compatible if the difference in their monochrome luminances is at least 128.0).- Parameters:
- a- one color
- b- the other color
- Returns:
- trueif colors- aand- bare compatible;- falseotherwise
 
 - 
mainpublic static void main(String[] args) Takes six command-line arguments r1, g1, b1, r2, g2, and b2, prints to standard output the monochrome luminances of (r1, g1, b1) and (r2, g2, b2) and whether they are compatible.- Parameters:
- args- the six command-line arguments
 
 
- 
 
-