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
Here is a pseudocode function that interpolates linearly between 2 colors (staying in RGB space). I'm using a class called Color here instead of ints for clarity.
bAmount is between 0 and 1 (for interpolation)
Color interpolate(Color colorA, Color colorB, float bAmount) {
Color colorOut;
float aAmount = 1.0 - bAmount;
colorOut.r = colorA.r * aAmount + colorB.r * bAmount;
colorOut.g = colorA.g * aAmount + colorB.g * bAmount;
colorOut.b = colorA.b * aAmount + colorB.b * bAmount;
return colorOut;
}