Here you can find the source of interpolateColors(int c0, int c1, float w)
Parameter | Description |
---|---|
w | Determines the relative weight of each color, where 0.0 returns c0 and 1.0 returns c1 . |
public static int interpolateColors(int c0, int c1, float w)
//package com.java2s; //License from project: Apache License public class Main { /**/* w ww.j a va 2 s .c om*/ * Performs linear interpolation between two colors. * * @param w Determines the relative weight of each color, where 0.0 returns {@code c0} and 1.0 returns * {@code c1}. */ public static int interpolateColors(int c0, int c1, float w) { if (w <= 0) return c0; if (w >= 1) return c1; int a = interpolateColor((c0 >> 24) & 0xFF, (c1 >> 24) & 0xFF, w); int r = interpolateColor((c0 >> 16) & 0xFF, (c1 >> 16) & 0xFF, w); int g = interpolateColor((c0 >> 8) & 0xFF, (c1 >> 8) & 0xFF, w); int b = interpolateColor((c0) & 0xFF, (c1) & 0xFF, w); return (a << 24) | (r << 16) | (g << 8) | (b); } private static int interpolateColor(int a, int b, float w) { return Math.max(0, Math.min(255, Math.round(a + (b - a) * w))); } }