Here you can find the source of interpolate(final Color from, final Color to, final double t)
Parameter | Description |
---|---|
from | The color to interpolate from. |
to | The color to interpolate to. |
t | The interpolation value from <code>0</code> to <code>1</code>. |
public static Color interpolate(final Color from, final Color to, final double t)
//package com.java2s; //License from project: Open Source License import java.awt.Color; public class Main { /**// w w w . j ava 2s. c om * Interpolates between two colors. * * @param from The color to interpolate from. * @param to The color to interpolate to. * @param t The interpolation value from <code>0</code> to <code>1</code>. * @return The interpolated color. */ public static Color interpolate(final Color from, final Color to, final double t) { if (Double.isNaN(t)) throw new IllegalArgumentException("NaN"); if (t > 1 || t < 0) throw new IllegalArgumentException("" + t); final float[] fromRGBA = new float[4]; final float[] toRGBA = new float[4]; from.getRGBComponents(fromRGBA); to.getRGBComponents(toRGBA); final double r = fromRGBA[0] * (1 - t) + toRGBA[0] * t; final double g = fromRGBA[1] * (1 - t) + toRGBA[1] * t; final double b = fromRGBA[2] * (1 - t) + toRGBA[2] * t; final double a = fromRGBA[3] * (1 - t) + toRGBA[3] * t; return new Color((float) r, (float) g, (float) b, (float) a); } }