Here you can find the source of buildColorRamp(Color startColor, Color endColor, int numColors, int alpha)
public static Color[] buildColorRamp(Color startColor, Color endColor, int numColors, int alpha)
//package com.java2s; import java.awt.Color; public class Main { public static Color[] buildColorRamp(Color startColor, Color endColor, int numColors, int alpha) { Color[] colors = new Color[numColors]; for (int j = 0; j < colors.length; j++) { float ratio = (float) j / (float) colors.length; int red = (int) (endColor.getRed() * ratio + startColor.getRed() * (1 - ratio)); int green = (int) (endColor.getGreen() * ratio + startColor.getGreen() * (1 - ratio)); int blue = (int) (endColor.getBlue() * ratio + startColor.getBlue() * (1 - ratio)); colors[j] = new Color(red, green, blue, alpha); }// w ww . j a va 2 s. c om return colors; } }