-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathU.cs
More file actions
68 lines (56 loc) · 1.91 KB
/
U.cs
File metadata and controls
68 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FancadeImageGenerator
{
internal static class U
{
/// <summary>
/// Shows press any key to exit, then waits for key press
/// </summary>
/// <param name="message"></param>
public static void PAKE(string message = "")
{
Console.CursorVisible = true;
if (string.IsNullOrWhiteSpace(message))
Console.WriteLine("Press any key to exit...");
else
Console.WriteLine(message + ", press any key to exit...");
Console.ReadKey(true);
}
public static bool TakeBool(string message, bool defaultOption)
{
Console.Write($"{message} ({(defaultOption ? 'Y' : 'y')}/{(defaultOption ? 'n' : 'N')}): ");
string? typed = Console.ReadLine();
if (defaultOption)
return !(typed == "n" || typed == "N");
else
return (typed == "y" || typed == "Y");
}
public static int ClosestColor(Rgba32[] colors, Rgba32 color)
{
int minDiff = int.MaxValue;
int index = -1;
if (color.A < 127)
return 0;
for (int i = 1; i < colors.Length; i++)
{
int diff = ColorDiff(color, colors[i]);
if (diff < minDiff)
{
minDiff = diff;
index = i;
}
}
return index;
}
public static int ColorDiff(Rgba32 c1, Rgba32 c2)
=> (int)Math.Sqrt((c1.R - c2.R) * (c1.R - c2.R)
+ (c1.G - c2.G) * (c1.G - c2.G)
+ (c1.B - c2.B) * (c1.B - c2.B));
}
}