Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2012 JPII and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

public class Main {
    /**
     * Linear interpolation.
     * @param num0
     * @param num1
     * @param amount
     * @return
     */
    public static double Lerp(int num0, int num1, double amount) {
        return num0 + (amount * (num1 - num0));
    }

    /**
     * Linear interpolation.
     * @param color0
     * @param color1
     * @param amount
     * @return
     */
    public static Color Lerp(Color color0, Color color1, double amount) {
        int r = (int) Lerp(color0.getRed(), color1.getRed(), amount);
        int g = (int) Lerp(color0.getGreen(), color1.getGreen(), amount);
        int b = (int) Lerp(color0.getBlue(), color1.getBlue(), amount);
        int a = (int) Lerp(color0.getAlpha(), color1.getAlpha(), amount);
        if (r > 255)
            r = 255;
        if (r < 0)
            r = 0;
        if (g > 255)
            g = 255;
        if (g < 0)
            g = 0;
        if (b > 255)
            b = 255;
        if (b < 0)
            b = 0;
        if (a > 255)
            a = 255;
        if (a < 0)
            a = 0;
        return new Color(r, g, b, a);
    }
}