I would like to calculate the color depending on a percentage value:
float percentage = x/total;
int color;
if (percentage >= 0.95) {
color = Color.GREE
My $0.02, I found this answer and coded up the proper solution. (Thanks to Alnitak for the HSV tip!)
For Copy+Paste:
private float interpolate(float a, float b, float proportion) {
return (a + ((b - a) * proportion));
}
/** Returns an interpoloated color, between a
and b
*/
private int interpolateColor(int a, int b, float proportion) {
float[] hsva = new float[3];
float[] hsvb = new float[3];
Color.colorToHSV(a, hsva);
Color.colorToHSV(b, hsvb);
for (int i = 0; i < 3; i++) {
hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
}
return Color.HSVToColor(hsvb);
}