It's for a Mandelbrot set rendering (see: https://en.wikipedia.org/wiki/Mandelbrot_set); the color of each point should be based on the number of iterations it took for the complex number Z to escape the set.
I would like to map the colors such that if the point is an element of the Mandelbrot set, it should be purely red [RGB(255, 0, 0), 0% across spectrum from IR to UV].
If the calculation was stopped because the loop reached the iteration cap, the the color should be purely violet [RGB(249, 192, 255), 100% across spectrum].
I imagine the solution involves something like:
//where iterCount is the value for that point, maxIters is the iteration cap
double spectrumValue=iterCount/maxIters; //percent in decimal form
setColor(RGBConversion(spectrumValue));
However, the part I don't know how to do is the RGBConversion method. Ideally, it should run in constant time.
You should be looking at using either "HSL" or "HSB" (aka "HSV") colour space, where the "H" in both stands for "hue". Hue is typically measured as an angle in degrees, with 0 degrees representing red, 120 for green, 240 for blue, although some libraries use the range 0..1
Keepping "S" and "B" constant and varying "H" linearly from the bottom of the range to the top will produce the typical "rainbow" of colours.
In your case since you're using Java and AWT, you should simply be able to call:
setColor(Color.getHSBColor(spectrumValue, 1.0, 1.0));