public class Luminance
extends Object
Luminance
is 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.
Constructor and Description |
---|
Luminance() |
Modifier and Type | Method and Description |
---|---|
static boolean |
areCompatible(java.awt.Color a,
java.awt.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 double |
intensity(java.awt.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 double |
lum(java.awt.Color color)
Deprecated.
Replaced by
intensity(Color) . |
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.
|
static java.awt.Color |
toGray(java.awt.Color color)
Returns a grayscale version of the given color as a
Color object. |
@Deprecated public static double lum(java.awt.Color color)
intensity(Color)
.color
- the color to convertpublic static double intensity(java.awt.Color color)
color
- the color to convertpublic static java.awt.Color toGray(java.awt.Color color)
Color
object.color
- the Color
object to convert to grayscalecolor
public static boolean areCompatible(java.awt.Color a, java.awt.Color b)
a
- one colorb
- the other colortrue
if colors a
and b
are compatible;
false
otherwisepublic static void main(String[] args)
args
- the six command-line arguments