Java Color Interpolate interpolate(Color a, Color b, float f)

Here you can find the source of interpolate(Color a, Color b, float f)

Description

interpolate

License

Open Source License

Declaration

public static Color interpolate(Color a, Color b, float f) 

Method Source Code


//package com.java2s;
/*/*from ww  w  .java 2 s .  co m*/
Copyright 2012 James Edwards
    
This file is part of Jhrome.
    
Jhrome 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.
    
Jhrome 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 Jhrome.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

public class Main {
    public static Color interpolate(Color a, Color b, float f) {
        float rf = 1 - f;
        int red = (int) (a.getRed() * rf + b.getRed() * f);
        int green = (int) (a.getGreen() * rf + b.getGreen() * f);
        int blue = (int) (a.getBlue() * rf + b.getBlue() * f);
        int alpha = (int) (a.getAlpha() * rf + b.getAlpha() * f);

        return new Color(red, green, blue, alpha);
    }
}

Related

  1. interpolate(Color b, Color a, float t)
  2. interpolate(Color c1, Color c2, float fracFromC1)
  3. interpolate(Color colour1, Color colour2, float colour2Fraction)
  4. interpolate(Color low, Color high, double min, double max, double v)