Luminance.java
import java.awt.Color;
public class Luminance
{
public static double lum(Color color)
{
int r = color.getRed();
int g = color.getGreen();
int b = color.getBlue();
return .299*r + .587*g + .114*b;
}
public static Color toGray(Color color)
{
int y = (int) (Math.round(lum(color)));
Color gray = new Color(y, y, y);
return gray;
}
public static boolean compatible(Color a, Color b)
{
return Math.abs(lum(a) - lum(b)) >= 128.0;
}
public static void main(String[] args)
{
int[] a = new int[6];
for (int i = 0; i < 6; i++)
{
a[i] = Integer.parseInt(args[i]);
}
Color
c1 = new Color(a[0], a[1], a[2]);
Color c2 = new Color(a[3], a[4], a[5]);
System.out.println("c1 = " + c1);
System.out.println("c2 = " + c2);
System.out.println("lum(c1) =
" + lum(c1));
System.out.println("lum(c2) =
" + lum(c2));
System.out.println(compatible(c1, c2));
}
}
No comments:
Post a Comment