public static List<Color> GenerateColors_GoldenRatioGradient(int colorCount, Color[] gradient, float saturation, float luminance) { List<Color> colors = new List<Color>(); float goldenRatioConjugate = 0.618033988749895f; float currentHue = (float)random.NextDouble(); for (int i = 0; i < colorCount; i++) { HSL hslColor = new HSL(currentHue, saturation, luminance); Color newColor = SampleLinearGradient(gradient, currentHue); colors.Add(newColor); currentHue += goldenRatioConjugate; currentHue %= 1.0f; } return colors; }
public static Color RandomMixHSL(Color color1, Color color2, Color color3, float greyControl) { int randomIndex = random.NextByte() % 3; float mixRatio1 = (randomIndex == 0) ? random.NextFloat() * greyControl : random.NextFloat(); float mixRatio2 = (randomIndex == 1) ? random.NextFloat() * greyControl : random.NextFloat(); float mixRatio3 = (randomIndex == 2) ? random.NextFloat() * greyControl : random.NextFloat(); float sum = mixRatio1 + mixRatio2 + mixRatio3; mixRatio1 /= sum; mixRatio2 /= sum; mixRatio3 /= sum; HSL hsl1 = new HSL(color1); HSL hsl2 = new HSL(color2); HSL hsl3 = new HSL(color3); return new HSL( (mixRatio1 * hsl1.H + mixRatio2 * hsl2.H + mixRatio3 * hsl3.H), (mixRatio1 * hsl1.S + mixRatio2 * hsl2.S + mixRatio3 * hsl3.S), (mixRatio1 * hsl1.L + mixRatio2 * hsl2.L + mixRatio3 * hsl3.L)).Color; }
public static List<Color> GenerateColors_SaturationLuminance(int colorCount, float hue) { List<Color> colors = new List<Color>(); for (int i = 0; i < colorCount; i++) { HSL hslColor = new HSL(hue, random.NextDouble(), random.NextDouble()); colors.Add(hslColor.Color); } return colors; }
public static List<Color> GenerateColors_JitteredRainbow(int colorCount, float startHue, float endHue, float saturation, float luminance, bool jitter) { List<Color> colors = new List<Color>(); float hueRange = endHue - startHue; if (hueRange < 0) { hueRange = 1 + hueRange; } float cellRange = hueRange / colorCount; float cellOffset = (float)(random.NextDouble() * cellRange); for (int i = 0; i < colorCount; i++) { float newHue; if (jitter) { newHue = (float)(cellRange * i + random.NextDouble() * cellRange + startHue); } else { newHue = (cellRange * i + cellOffset + startHue); } if (newHue > 1) { newHue -= 1.0f; } HSL hslColor = new HSL(newHue, saturation, luminance); colors.Add(hslColor.Color); } return colors; }
public static List<Color> GenerateColors_HueRange(int colorCount, float startHue, float endHue, float saturation, float luminance) { List<Color> colors = new List<Color>(); float hueRange = endHue - startHue; if (hueRange < 0) { hueRange += 1.0f; } for (int i = 0; i < colorCount; i++) { float newHue = (float)(hueRange * random.NextDouble() + startHue); if (newHue > 1.0) { newHue -= 1.0f; } HSL hslColor = new HSL(newHue, saturation, luminance); colors.Add(hslColor.Color); } return colors; }
public static List<Color> GenerateColors_Hue(int colorCount, float saturation, float luminance) { List<Color> colors = new List<Color>(); for (int i = 0; i < colorCount; i++) { HSL hslColor = new HSL(random.NextDouble(), saturation, luminance); colors.Add(hslColor.Color); } return colors; }
public static List<Color> GenerateColors_Harmony2( int colorCount, float offsetAngle1, float offsetAngle2, float rangeAngle0, float rangeAngle1, float rangeAngle2, float saturation, float saturationRange, float luminance, float luminanceRange) { List<Color> colors = new List<Color>(); 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; } } float newSaturation = saturation + (random.NextFloat() - 0.5f) * saturationRange; float newLuminance = luminance + +(random.NextFloat() - 0.5f) * luminanceRange; HSL hslColor = new HSL(((referenceAngle + randomAngle) / 360.0f) % 1.0f, newSaturation, newLuminance); colors.Add(hslColor.Color); } return colors; }