-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.cs
More file actions
194 lines (164 loc) · 6.49 KB
/
Image.cs
File metadata and controls
194 lines (164 loc) · 6.49 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System.Drawing;
namespace SkinGenBot;
public class Image
{
private static readonly Bitmap
NewSkin = new(64, 64),
SolidImage = new(GetImageReference("SkinGenBot.Graphics.BaseSkin.png")),
SplitImage = new(GetImageReference("SkinGenBot.Graphics.SplitGen.png")),
GradientImage = new(GetImageReference("SkinGenBot.Graphics.Gradient.png"));
private static readonly List<int>
HatCoords1 = new() { 0, 7, 8, 31, 1, 6, 9, 30, 2, 5, 10, 29, 3, 4, 11, 28 },
HatCoords2 = new() { 15, 16, 23, 24, 14, 17, 22, 25, 13, 18, 21, 26, 12, 19, 20, 27 };
private static Stream GetImageReference(string resourcePath)
{
Stream stream = typeof(Program).Assembly.GetManifestResourceStream(resourcePath);
if (stream == null) throw new Exception($"Resource '{resourcePath}' not found.");
return stream;
}
public static void SaveImage(string input)
{
Console.WriteLine($"Hex code {input} generated. (Runtime generation #{Program.Counter})");
NewSkin.Save(Program.GetPath(input), System.Drawing.Imaging.ImageFormat.Png);
if (Program.ConsoleMode) Console.WriteLine($"Skin saved to {Program.GetPath(input)}");
Program.Counter++;
}
public static void SaveImageSplitGen(string input, string input2)
{
Console.WriteLine($"SplitGen of {Colors.HexCheck(input)} & {Colors.HexCheck(input2)} generated. (Runtime generation #{Program.Counter})");
NewSkin.Save(Program.GetPathSplitGen(input, input2), System.Drawing.Imaging.ImageFormat.Png);
if (Program.ConsoleMode) Console.WriteLine($"Skin saved to {Program.GetPathSplitGen(input, input2)}");
Program.Counter++;
}
public static void SaveImageGradient(string input, string input2)
{
Console.WriteLine($"Gradient of {Colors.HexCheck(input)} & {Colors.HexCheck(input2)} generated. (Runtime generation #{Program.Counter})");
NewSkin.Save(Program.GetPathGradient(input, input2), System.Drawing.Imaging.ImageFormat.Png);
if (Program.ConsoleMode) Console.WriteLine($"Skin saved to {Program.GetPathGradient(input, input2)}");
Program.Counter++;
}
public static void ReplaceColorValue(Color oldColor, Color newColor)
{
for (int y = 0; y < NewSkin.Height; y++)
{
for (int x = 0; x < NewSkin.Width; x++)
{
if (NewSkin.GetPixel(x, y) == oldColor)
NewSkin.SetPixel(x, y, newColor);
}
}
}
public static void ReplaceCoord(int x, int y, Color newColor)
{
NewSkin.SetPixel(x, y, newColor);
}
public static void SplitGen(string hex1, string hex2)
{
DrawNewImage(SplitImage);
Color leftColor = Colors.HexToColor(Colors.HexCheck(hex1));
Color rightColor = Colors.HexToColor(Colors.HexCheck(hex2));
if (!IsTooDark(leftColor))
ReplaceAllColors(Colors.LeftColorList, leftColor, 0.85f);
else
{
ReplaceColorValue(Colors.LeftColorList[0], leftColor);
LightenHatColors(true, false, leftColor, rightColor);
}
if (!IsTooDark(rightColor))
ReplaceAllColors(Colors.RightColorList, rightColor, 0.85f);
else
{
ReplaceColorValue(Colors.RightColorList[0], rightColor);
LightenHatColors(false, true, leftColor, rightColor);
}
}
public static void GradientGen(string hex1, string hex2)
{
float factor = 0f;
Color color1 = Colors.HexToColor(Colors.HexCheck(hex1));
Color color2 = Colors.HexToColor(Colors.HexCheck(hex2));
DrawNewImage(GradientImage);
if (!IsTooDark(color1))
ReplaceAllColors(Colors.SolidColorList, color1, 0.85f);
else
LightenHatColors(true, true, color1, color1);
foreach (Color color in Colors.GradientColorList)
{
ReplaceColorValue(color, Colors.MixColors(color1, color2, factor));
factor += 0.035f;
}
}
public static void SolidGen(string hex)
{
Color newColor = Colors.HexToColor(Colors.HexCheck(hex));
DrawNewImage(SolidImage);
if (!IsTooDark(newColor))
{
ReplaceAllColors(Colors.SolidColorList, newColor, 0.85f);
}
else
{
ReplaceColorValue(Colors.SolidColorList[0], newColor);
LightenHatColors(true, true, newColor, newColor);
}
}
private static void LightenHatColors(bool leftSide, bool rightSide, Color leftColor, Color rightColor)
{
if (leftSide)
{
ReplaceColorValue(Colors.LeftColorList[2], Colors.LightenColor(leftColor, 0.15f));
ReplaceHatCoords(HatCoords1, leftColor, 0.05f);
}
if (rightSide)
{
ReplaceColorValue(Colors.RightColorList[2], Colors.LightenColor(rightColor, 0.15f));
ReplaceHatCoords(HatCoords2, rightColor, 0.05f);
}
}
private static void ReplaceAllColors(List<Color> list, Color newColor, float factor)
{
for (int i = 0; i < 4; i++)
{
if (i < 1)
{
ReplaceColorValue(list[i], newColor);
continue;
}
ReplaceColorValue(list[i], Colors.DarkenColor(newColor, factor));
factor -= 0.10f;
}
}
private static void ReplaceHatCoords(List<int> list, Color color, float factor)
{
for (int i = 0; i < list.Count; i++)
{
if ((i + 1) % 4 == 0 && i < 16)
factor += 0.10f;
if (i < 4)
{
ReplaceCoord(list[i], 10, color);
continue;
}
ReplaceCoord(list[i], 10, Colors.LightenColor(color, factor));
}
}
private static bool IsTooDark(Color color)
{
return Equals(Colors.DarkenColor(color, 0.65f), Colors.DarkenColor(color, 0.75f));
}
public static void DrawNewImage(Bitmap baseImage)
{
using (Graphics graphics = Graphics.FromImage(NewSkin))
{
try
{
graphics.DrawImage(baseImage, new Rectangle(0, 0, 64, 64));
if (Program.DebugMode) Console.WriteLine("DEBUG: Internal graphic found.");
}
catch (Exception e)
{
Console.WriteLine($"ERROR: Internal graphic not found.\n{e}");
}
}
}
}