Here you can find the source of interpolateRGB(Color start, Color end, float p)
public static Color interpolateRGB(Color start, Color end, float p)
//package com.java2s; /*// ww w . j ava2 s. c o m * Copyright (C) 2017 Daniel H. Huson * * (Some files contain contributions from other authors, who are then mentioned separately.) * * 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.*; public class Main { public static Color interpolateRGB(Color start, Color end, float p) { if (p <= 0.5) { final float a = 2 * (0.5f - p); final float b = (int) (2f * p * 255f); return new Color((int) (a * start.getRed() + b), (int) (a * start.getGreen() + b), (int) (a * start.getBlue() + b), (start.getAlpha() + end.getAlpha()) / 2); } else { final float a = 2 * (p - 0.5f); final float b = (int) (2f * (1f - p) * 255f); return new Color((int) (a * end.getRed() + b), (int) (a * end.getGreen() + b), (int) (a * end.getBlue() + b), (start.getAlpha() + end.getAlpha()) / 2); } /* final float a=(p>=0.5?1:1-2*p); // p=0: a=1, p>=0.5: a=0 final float b=(p<=0.5?1:2*(p-0.5f)); // p<=0.5: b=0, p==1: b=1 return new Color((int)(a*start.getRed()+b*end.getRed()), (int)(a*start.getGreen()+b*end.getGreen()), (int)(a*start.getBlue()+b*end.getBlue()), (start.getAlpha()+end.getAlpha())/2); */ } }