Here you can find the source of blend(Color color1, Color color2, float ratio)
Parameter | Description |
---|---|
color1 | First color to blend. |
color2 | Second color to blend. |
ratio | Blend ratio. 0.5 will give even blend, 1.0 will return color1, 0.0 will return color2 and so on. |
public static Color blend(Color color1, Color color2, float ratio)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { /**//from w w w . j a v a2 s . com * Blend two colors. * * @param color1 First color to blend. * @param color2 Second color to blend. * @param ratio Blend ratio. 0.5 will give even blend, 1.0 will return * color1, 0.0 will return color2 and so on. * @return Blended color. */ public static Color blend(Color color1, Color color2, float ratio) { float ir = (float) 1.0 - ratio; float rgb1[] = new float[3]; float rgb2[] = new float[3]; color1.getColorComponents(rgb1); color2.getColorComponents(rgb2); return new Color(rgb1[0] * ratio + rgb2[0] * ir, rgb1[1] * ratio + rgb2[1] * ir, rgb1[2] * ratio + rgb2[2] * ir); } /** * Make an even blend between two colors. * * @param color1 First color to blend. * @param color2 Second color to blend. * @return Blended color. */ public static Color blend(Color color1, Color color2) { return blend(color1, color2, 0.5f); } }