Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
public class ColourChecking {
    private int red;
    private int green;
    private int blue;
    private double hue;
    private double saturation;
    private double brightness;
    public ColourChecking() {
        red = 193;
        green = 255;
        blue = 183;
        calculateHSB();
    }
    private void calculateHSB() {
        double r = red / 255.0;
        double g = green / 255.0;
        double b = blue / 255.0;
        double cmax = Math.max(r, Math.max(g, b));
        double cmin = Math.min(r, Math.min(g, b));
        double delta = cmax - cmin;
        if (delta == 0) {
            hue = 0;
        } else if (cmax == r) {
            hue = ((g - b) / delta) % 6;
        } else if (cmax == g) {
            hue = ((b - r) / delta) + 2;
        } else {
            hue = ((r - g) / delta) + 4;
        }
        hue = hue * 60;
        if (hue < 0) {
            hue += 360;
        }
        if (cmax == 0) {
            saturation = 0;
        } else {
            saturation = delta / cmax;
        }
        brightness = cmax;
    }
    public double getHue() {
        return hue;
    }
    public double getSaturation() {
        return saturation;
    }
    public double getBrightness() {
        return brightness;
    }
}