Created
February 27, 2015 14:38
-
-
Save tutuca/5608efc5e8b620c3db47 to your computer and use it in GitHub Desktop.
Color harmony algorithm
This file contains 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 static List GenerateColors_Harmony( | |
int colorCount, | |
float offsetAngle1, | |
float offsetAngle2, | |
float rangeAngle0, | |
float rangeAngle1, | |
float rangeAngle2, | |
float saturation, float luminance) | |
{ | |
List colors = new List(); | |
float referenceAngle = random.NextFloat() * 360; | |
for (int i = 0; i < colorCount; i++) | |
{ | |
float randomAngle = | |
random.NextFloat() * (rangeAngle0 + rangeAngle1 + rangeAngle2); | |
if (randomAngle > rangeAngle0) | |
{ | |
if (randomAngle < rangeAngle0 + rangeAngle1) | |
{ | |
randomAngle += offsetAngle1; | |
} | |
else | |
{ | |
randomAngle += offsetAngle2; | |
} | |
} | |
HSL hslColor = new HSL( | |
((referenceAngle + randomAngle) / 360.0f) % 1.0f, | |
saturation, | |
luminance); | |
colors.Add(hslColor.Color); | |
} | |
return colors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one takes three colors and create a pallete out of them.
public static Color RandomMix(Color color1, Color color2, Color color3,
float greyControl)
{
int randomIndex = random.NextByte() % 3;
}