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.