Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Color; public class Main { private static final float VOLTAGE_UPPER = 26f; private static final float VOLTAGE_LOWER = 15f; 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 GetVoltsColor(Double volts) { float hue; if (volts >= VOLTAGE_UPPER) { hue = GOOD; } else if (volts <= VOLTAGE_LOWER) { hue = BAD; } else { hue = (volts.floatValue() - VOLTAGE_LOWER) / (VOLTAGE_UPPER - VOLTAGE_LOWER) * (GOOD - BAD) + BAD; } return Color.HSVToColor(new float[] { hue, SATURATION, VALUE }); } }