
Ian M. answered 03/27/19
Web Development Specialist, Expert JavaScript Programmer
Have you tried using HSL colors? The H, or hue, component is represented by an angle, from 0 degrees (red) to 90 degrees (yellow-green) to 180 degrees (cyan) to 270 degrees (violet) and back to red.
So, for example, if N = 10, then 360 / 10 = 36 degrees. That will give you the colors at 0 degrees, 36 degrees, 72 degrees, etc. (And you don't have to start at zero, by the way. You could start with any random offset and degrees larger than 360 will just "wrap around.") No need to find separate values for red, green, and blue! And you can also easily extend your color wheel to include shades and tints of each color by changing saturation and lightness.
Ian