Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (c) 2005-2016 Vincent Vandenschrick. All rights reserved.
 *
 *  This file is part of the Jspresso framework.
 *
 *  Jspresso is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Jspresso is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Jspresso.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

public class Main {
    /**
     * Make a color scaled using a defined factor.
     *
     * @param color
     *          the color to scale.
     * @param factor
     *          the factor to use.
     * @return the scaled color.
     */
    public static Color getScaledColor(Color color, double factor) {
        if (color == null) {
            return null;
        }
        if (factor <= 1) {
            return new Color(Math.max((int) (color.getRed() * factor), 0),
                    Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0),
                    color.getAlpha());
        }
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();

        int i = (int) (1.0 / (factor - 1));
        if (r == 0 && g == 0 && b == 0) {
            return new Color(i, i, i);
        }
        if (r > 0 && r < i) {
            r = i;
        }
        if (g > 0 && g < i) {
            g = i;
        }
        if (b > 0 && b < i) {
            b = i;
        }

        return new Color(Math.min((int) (r / (2 - factor)), 255), Math.min((int) (g / (2 - factor)), 255),
                Math.min((int) (b / (2 - factor)), 255));

    }
}