[java] How to automatically generate N "distinct" colors?

HSL color model may be well suited for "sorting" colors, but if you are looking for visually distinct colors you definitively need Lab color model instead.

CIELAB was designed to be perceptually uniform with respect to human color vision, meaning that the same amount of numerical change in these values corresponds to about the same amount of visually perceived change.

Once you know that, finding the optimal subset of N colors from a wide range of colors is still a (NP) hard problem, kind of similar to the Travelling salesman problem and all the solutions using k-mean algorithms or something won't really help.

That said, if N is not too big and if you start with a limited set of colors, you will easily find a very good subset of distincts colors according to a Lab distance with a simple random function.

I've coded such a tool for my own usage (you can find it here: https://mokole.com/palette.html), here is what I got for N=7: enter image description here

It's all javascript so feel free to take a look on the source of the page and adapt it for your own needs.

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to colors

is it possible to add colors to python output? How do I use hexadecimal color strings in Flutter? How do I change the font color in an html table? How do I print colored output with Python 3? Change bar plot colour in geom_bar with ggplot2 in r How can I color a UIImage in Swift? How to change text color and console color in code::blocks? Android lollipop change navigation bar color How to change status bar color to match app in Lollipop? [Android] How to change color of the back arrow in the new material theme?

Examples related to color-scheme

How to get the list of all installed color schemes in Vim? How to set default vim colorscheme Qt Creator color scheme How to automatically generate N "distinct" colors? How do I install a color theme for IntelliJ IDEA 7.0.x

Examples related to color-picker

Color picker utility (color pipette) in Ubuntu jQuery UI Color Picker How to automatically generate N "distinct" colors?