Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Color; public class Main { private static final float AMPS_LOW = 10f; private static final float AMPS_ECO = 23f; private static final float AMPS_HIGH = 30f; private static final float GOOD = 120; private static final float BAD = 0; private static final float VALUE = 0.7f; private static final float SATURATION = 0.5f; public static int GetAmpsColor(Double amps) { float hue; if (amps >= AMPS_HIGH || amps <= AMPS_LOW) { hue = BAD; } else if (amps == AMPS_ECO) { hue = GOOD; } else if (amps < AMPS_ECO) { hue = (amps.floatValue() - AMPS_LOW) / (AMPS_ECO - AMPS_LOW) * (GOOD - BAD) + BAD; } else { hue = GOOD - (amps.floatValue() - AMPS_ECO) / (AMPS_HIGH - AMPS_ECO) * (GOOD - BAD) + BAD; } return Color.HSVToColor(new float[] { hue, SATURATION, VALUE }); } }