Java examples for 2D Graphics:Color
Returns a mixed color from color c1 and c2.
//package com.java2s; import java.awt.*; public class Main { /**// w ww. j a v a 2 s .co m * Returns a mixed color from color <tt>c1</tt> and <tt>c2</tt>. * @param c1 the start color * @param pct1 the first color coefficient of the mix between 0 and 1 * @param c2 the end color * @param pct2 the second color coefficient of the mix between 0 and 1 * @return the new mixed color */ private static Color getMixedColor(Color c1, float pct1, Color c2, float pct2) { float[] clr1 = c1.getComponents(null); float[] clr2 = c2.getComponents(null); for (int i = 0; i < clr1.length; i++) { clr1[i] = (clr1[i] * pct1) + (clr2[i] * pct2); } return new Color(clr1[0], clr1[1], clr1[2], clr1[3]); } }