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