Skip to content

Instantly share code, notes, and snippets.

@AlexLamson
Created October 1, 2013 21:03
Show Gist options
  • Save AlexLamson/6785065 to your computer and use it in GitHub Desktop.
Save AlexLamson/6785065 to your computer and use it in GitHub Desktop.
Random pleasant color generator, translated to java. Theory taken from http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
public class NiceColors
{
public static int colorPos = 0;
//use golden ratio to create pleasant colors
//http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
public static Color betterNiceColor()
{
double goldenRatioConj = (1.0 + Math.sqrt(5.0)) / 2.0;
float hue = new Random().nextFloat();
hue += goldenRatioConj * (colorPos / (5 * Math.random()));
hue = hue % 1;
return Color.getHSBColor(hue, 0.5f, 0.95f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment