I am working on a music visualizer and I am hoping for the colors on the spectrum to gradually change from green to red based on the amplitude. Here are the instructions given:
Change the colour of each bar such that it gradually changes from green to red based on the amplitude value [2 marks]. For example
An amplitude value of 0 the colour values are R:0, G:255 and B:0. An amplitude value of 127 colour values are R:127, G:127 and B:0 An amplitude value of 255 colour values are R:255, G:0 and B: 0
Here is my code:
var spectrum = fourier.analyze();
noStroke();
for (var i = 0; i< spectrum.length; i++){
var y = map(i, 0, spectrum.length, 0, height);
var w = map(spectrum[i], 0, 255, 0, width);
if(spectrum[i] > 200)
{
fill(255,0,0);
}
if(spectrum[i] > 100 && spectrum[i] < 200)
{
fill(127,127,0);
}
if(spectrum[i] > 0 && spectrum[i] < 100)
{
fill(0,255,0);
}
rect(0,y,w,height/spectrum.length);
}
The color changed based on the amplitude however I want them to gradually change. I would be thankful for your help