I've written a class based on JPanel which displays an waterfall diagram, based on data I am getting from a FFT analysis of an audio signal.
The question is: How to determine the color to use?
My current function to do this looks like this:
/**
* Returns the color for the given FFT result value.
* @param currentValue One data entry of the FFT result
* @return The color in which the pixel should be drawn
*/
public Color calcColor(float currentValue){
float max_color_value=255+255+255;//r+g+b max value
//scale this to our MAX_VALUE
float scaled_max_color_val=(max_color_value/MAX_VALUE)*currentValue;
//split into r g b parts
int r=0;
int g=0;
int b=0;
if(scaled_max_color_val < 255) {
b=(int)Math.max(0, scaled_max_color_val);
} else if(scaled_max_color_val > 255 && scaled_max_color_val < 255*2){
g=(int)Math.max(0, scaled_max_color_val-255);
} else if(scaled_max_color_val > 255*2 ){
r=(int)Math.max(0, scaled_max_color_val-255*2);
r=Math.min(r, 255);
}
return new Color(r, g, b);
}
So my objective is to change this function in a way that the color depends on the currentValue
. currentValue
s from low->high should corespond with colors black -> green -> yellow -> red.
How to implement this in my function?