Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

public class Main {
    /**
     * Adjusts a preset color to a roughness value.
     * @param orig The original color
     * @param a The roughness value.
     * @param maxmin The maximum and minimum differential.
     * @return A color that has been adjust to match the original and roughness.
     */
    public static Color adjust(Color orig, double a, int maxmin) {
        if (a > 1)
            a = 1;
        if (a < 0)
            a = 0;

        int r = orig.getRed();
        int g = orig.getGreen();
        int b = orig.getBlue();

        r = (int) (r - (a * maxmin));
        g = (int) (g - (a * maxmin));
        b = (int) (b - (a * maxmin));

        r = colorSnap(r);
        g = colorSnap(g);
        b = colorSnap(b);
        return new Color(r, g, b, orig.getAlpha());
    }

    /**
     * Snaps a rgba value to a byte.
     * @param rgbaval The integer to snap.
     * @return Between 0 and 255.
     */
    public static int colorSnap(int rgbaval) {
        if (rgbaval > 255)
            rgbaval = 255;
        if (rgbaval < 0)
            rgbaval = 0;
        return rgbaval;
    }
}