Created
October 1, 2013 21:03
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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