Files
@ 4ef58379d19a
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Palette.cs - annotation
4ef58379d19a
1.3 KiB
text/x-csharp
Add a debug menu to help in tracking down problems. Save screen height/width settings entered by the user and load on next run.
b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 | using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace DesertPaintLab
{
public class Palette
{
static List<PaintColor> colors = new List<PaintColor>();
static Regex colorEntry = new Regex(@"\#(?<red>\w\w)(?<green>\w\w)(?<blue>\w\w)\s*(?<name>\w+)");
public Palette ()
{
}
public static void Load(string file)
{
string line;
Match match;
using (StreamReader reader = new StreamReader(file))
{
while ((line = reader.ReadLine()) != null)
{
match = colorEntry.Match(line);
if (match.Success)
{
colors.Add(new PaintColor(match.Groups["name"].Value,
match.Groups["red"].Value,
match.Groups["green"].Value,
match.Groups["blue"].Value));
}
}
}
}
public static string FindNearest(PaintColor color)
{
int bestDistSq = int.MaxValue;
PaintColor bestColor = null;
foreach (PaintColor paintColor in colors)
{
int distSq = paintColor.GetDistanceSquared(color);
if (distSq < bestDistSq)
{
bestDistSq = distSq;
bestColor = paintColor;
}
}
return bestColor.Name;
}
}
}
|