Suppose I have a class RainbowColorsMapper with the constructor RainbowColorsMapper(int n)
, where n>=2. Now I want to have continuous mapping of rainbow colors from red to violet which I get using the method mapper.getColor(int number)
where low values correspond to red end, and high near n to violet end. If n = 2, mapper.getColor(0)
returns most left color of the spectrum (near red), and mapper.getColor(1)
returns the most right color. Same with bigger n with automatic scaling.
My question: can this be done relatively easy, and if yes what are suggestions on the algorithm?