/* This is a utility class for working with colors */ public class ColorRGB { int r; int g; int b; public ColorRGB() { r = 0; g = 0; b = 0; } public ColorRGB(int gray) { r = gray; g = gray; b = gray; } public ColorRGB(int r_, int g_, int b_) { r = r_; g = g_; b = b_; } public color getColor() { return color(r, g, b); } public void setR(int r_) { r = r_; } public void setG(int g_) { g = g_; } public void setB(int b_) { b = b_; } public int getR() { return r; } public int getG() { return g; } public int getB() { return b; } public ColorRGB blendColor(ColorRGB ca, ColorRGB cb, int minV, int maxV, int val) { int rd, gd, bd; // figure out the difference in our color values rd = cb.getR() - ca.getR(); gd = cb.getG() - ca.getG(); bd = cb.getB() - ca.getB(); // calculate the offset betwen minV and maxV double vd = maxV - minV; double offset = (double)(val - minV) / vd; // figure out the RGB values that are scaled between the colors CA and CB double nr = (double)rd * offset + (double)ca.getR(); double ng = (double)gd * offset + (double)ca.getG(); double nb = (double)bd * offset + (double)ca.getB(); // return our new color return new ColorRGB((int)nr, (int)ng, (int)nb); } }