private static ConsoleBuffer createBuffer(Bitmap image)
{
ConsoleBuffer buffer = new ConsoleBuffer(image.Width, image.Height);
for (int i = 0; i < image.Width; i++)
for (int j = 0; j < image.Height; j++)
{
Color c = image.GetPixel(i, j);
if (c.A == 0) continue;
double[,] distances = new double[16, 2];
double smallestDistance = -1;
int smallestKey = 0;
for (var k = 0; k < 16; k++)
{
// euclidean distance between colors
double distance = (double)Math.Sqrt(Math.Pow(c.R - Colors[k, 0], 2) + Math.Pow(c.G - Colors[k, 1], 2) + Math.Pow(c.B - Colors[k, 2], 2));
if (smallestDistance > distance || smallestDistance == -1)
{
smallestDistance = distance;
smallestKey = k;
}
}
buffer.SetUnitBackColor(i, j, (BufferColor)Enum.GetValues(typeof(BufferColor)).GetValue(smallestKey));
}
return buffer;
}