Structure because structure

This commit is contained in:
Mira 2023-06-16 14:20:32 +02:00
parent 01d1ea3573
commit 2b2a53466f
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36
17 changed files with 693 additions and 674 deletions

38
Tools/ColorTools.cs Normal file
View file

@ -0,0 +1,38 @@
namespace Xorog.UniversalExtensions;
public static class ColorTools
{
/// <summary>
/// Get closest Color to given Color
/// </summary>
/// <param name="colorArray"></param>
/// <param name="baseColor"></param>
/// <returns></returns>
public static Color GetClosestColor(List<Color> colorArray, Color baseColor)
{
var colors = colorArray.Select(x => new { Value = x, Diff = Internal.GetDiff(x, baseColor) }).ToList();
var min = colors.Min(x => x.Diff);
return colors.Find(x => x.Diff == min).Value;
}
/// <summary>
/// Convert Hex to Color
/// </summary>
/// <returns>The converted color</returns>
public static Color ToColor(this string str)
{
return ColorTranslator.FromHtml(str);
}
/// <summary>
/// Convert RGB Value to Hex
/// </summary>
/// <param name="R">Red</param>
/// <param name="G">Green</param>
/// <param name="B">Blue</param>
/// <returns>A string that represents the color in hex (e.g. 255, 0, 0 -> #FF0000)</returns>
public static string ToHex(int R, int G, int B)
{
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
}
}