Files
@ 45b588f61ac8
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Palette.cs - annotation
45b588f61ac8
1.3 KiB
text/x-csharp
Add a button to flush all reagents from the simulator.
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;
}
}
}
|