I have set of categories (the number of which changes according to specific state) each of which I need to assign a unique color.
I have tried using random colors but they look bad, so I need a method of generating random colors which suit each other.
You should look in to colour theory and complementary colours; this will give you colours which work well together.
Have a look at Color Scheme Designer. Use the tetrad mode to see how you can combine 4 colours and different shades to give a number of distinct areas in the image.
Here is a colour shades chart and some examples which may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With