Skip to content

Instantly share code, notes, and snippets.

@jonny64bit
Last active March 21, 2017 16:09
Show Gist options
  • Save jonny64bit/0018fe8f9e2055c492bb34f5d10f549d to your computer and use it in GitHub Desktop.
Save jonny64bit/0018fe8f9e2055c492bb34f5d10f549d to your computer and use it in GitHub Desktop.
Unquie Color Harvestor Prototype
using System.Collections.Generic;
using System.Drawing;
using ColorMine.ColorSpaces;
using ColorMine.ColorSpaces.Comparisons;
namespace ColorHarvestor
{
class Program
{
//Make sure to import ColorMine nuget.
static void Main(string[] args)
{
var colors = new List<Rgb>();
for (var r = 0; r < 255; r++)
{
for (var g = 0; g < 255; g++)
{
for (var b = 0; b < 255; b++)
{
var clash = false;
//Create a random color
var generatedRgb = new Rgb {R = r, G = g, B = b};
if (RgbtoColor(generatedRgb).GetSaturation() < 0.4)
{
clash = true;
continue;
}
//Test against the other we have created
foreach (var color in colors)
{
var deltaE = generatedRgb.Compare(color, new CieDe2000Comparison());
if (deltaE < 22)
{
clash = true;
break;
}
}
if (!clash)
colors.Add(generatedRgb);
}
}
}
var lines = new List<string>();
foreach (var color in colors)
{
lines.Add("<div style='width: 200px; height: 50px; background-color: rgb(" + color.R + "," + color.G + "," + color.B + ")'></div>");
}
System.IO.File.WriteAllLines(@"C:\ColorTest.htm", lines);
}
public static Color RgbtoColor(Rgb input)
{
return Color.FromArgb((int)input.R, (int)input.G, (int)input.B);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment