I figured I should post this question, even if I have already found a solution, as a Java implementation was not readily available when I searched for it.
Using HSV instead of RGB allows the generation of colors with the same saturation and brightness (something I wanted).
Google App Engine does not allow use of java.awt.Color, so doing the following to convert between HSV and RGB is not an option:
Color c = Color.getHSBColor(hue, saturation, value);
String rgb = Integer.toHexString(c.getRGB());
Edit: I moved my answer as described in the comment by Nick Johnson.
Ex animo, - Alexander.
The solution was found here: http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
Martin Ankerl provides a good post on the subject, and provides Ruby script. For those too busy (or lazy) to implement it in Java, here's the one I did (I am sure it can be written more effectively, please feel free to comment):
My code for converting:
Example of use on Android:
The answer by @Peter Recore do not use rounding.
Probably somewhat more correct way to use it is to copy the content from java.awt.Color and this is how it looked in Java 6:
Rounding here seems to be correct.
Use ColorUtils which provides
And
Methods which are very easy to convert to each other!
For example:
Now get the color
Now get the hsl
Here is the sourcecode.
Using SWT you can use following code snippet:
I don't know anything about color math, but I can offer this alternative structure for the code, which tickles my aesthetic sense because it made it obvious to me how each of the 6 cases is just a different permutation of value, t and p. (Also I have an irrational fear of long if-else chains.)