Java Color Interpolate interpolate(Color c1, Color c2, float fracFromC1)

Here you can find the source of interpolate(Color c1, Color c2, float fracFromC1)

Description

Linearly interpolates between two RGB colours

License

Open Source License

Parameter

Parameter Description
c1 the first colour
c2 the second colour
fracFromC1 the fraction of the final colour that will come from c1

Return

the interpolated Color

Declaration

private static Color interpolate(Color c1, Color c2, float fracFromC1) 

Method Source Code


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

public class Main {
    /**//  w w w  .j av a 2 s  .co  m
     * Linearly interpolates between two RGB colours
     * 
     * @param c1
     *            the first colour
     * @param c2
     *            the second colour
     * @param fracFromC1
     *            the fraction of the final colour that will come from c1
     * @return the interpolated Color
     */
    private static Color interpolate(Color c1, Color c2, float fracFromC1) {
        float fracFromC2 = 1.0f - fracFromC1;
        return new Color(Math.round(fracFromC1 * c1.getRed() + fracFromC2 * c2.getRed()),
                Math.round(fracFromC1 * c1.getGreen() + fracFromC2 * c2.getGreen()),
                Math.round(fracFromC1 * c1.getBlue() + fracFromC2 * c2.getBlue()),
                Math.round(fracFromC1 * c1.getAlpha() + fracFromC2 * c2.getAlpha()));
    }
}

Related

  1. interpolate(Color a, Color b, float f)
  2. interpolate(Color b, Color a, float t)
  3. interpolate(Color colour1, Color colour2, float colour2Fraction)
  4. interpolate(Color low, Color high, double min, double max, double v)
  5. interpolate(Color start, Color end, float p)
  6. interpolate(double factor, Color bottomCol, Color topCol)