How to generate a palette of X colors

Hello,

For my game I need to generate an array with X colours, these colours must all be different from each other and “contrasting”, I mean, that a player can distinguish one colour from each other.

To give you a better understanding look the attached photo.

So, I need an algorithm to do this.

I am no expert in colour systems, so I ask for help, thank you in advance

If you are trying to color-code things on the fly, then you might as just find a nice-looking palette of 32 colors somewhere on the internet and use those for X<=32 you can just sample X evenly spaced-colors. If X is ever greater than 32 then it’s not going to be easy to distinguish by color anyway, but you could try a 64 color palette and see if that works.

I don’t really see much point in actually generating colors on the fly, but if you really want to it would probably be easiest to work in HSL color space and convert to RGB. The formula to convert is HSL to RGB is all over the internet, so you can just google it.