Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Colorist.cs
Go to the documentation of this file.
1using System.Globalization;
2using UnityEngine;
3
4namespace Empyrean.Utils;
5
6public static class Colorist
7{
8 public static readonly Color steelBlue = new Color32(70, 130, 180, byte.MaxValue);
9
10 public static readonly Color lightSteelBlue = new Color32(176, 196, 222, byte.MaxValue);
11
12 public static readonly Color white32 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
13
14 public static readonly Color black = new Color32(0, 0, 0, byte.MaxValue);
15
16 public static readonly Color nearlyBlack = new Color(0.1f, 0.1f, 0.1f);
17
18 public static readonly Color red10 = new Color(1f, 0.9f, 0.9f);
19
20 public static readonly Color red25 = new Color(1f, 0.75f, 0.75f);
21
22 public static readonly Color red50 = new Color(1f, 0.5f, 0.5f);
23
24 public static readonly Color red75 = new Color(1f, 0.25f, 0.25f);
25
26 public static readonly Color green10 = new Color(0.9f, 1f, 0.9f);
27
28 public static readonly Color green25 = new Color(0.75f, 1f, 0.75f);
29
30 public static readonly Color green50 = new Color(0.5f, 1f, 0.5f);
31
32 public static readonly Color green75 = new Color(0.25f, 1f, 0.25f);
33
34 public static readonly Color blue10 = new Color(0.9f, 0.9f, 1f);
35
36 public static readonly Color blue25 = new Color(0.75f, 0.75f, 1f);
37
38 public static readonly Color blue50 = new Color(0.5f, 0.5f, 1f);
39
40 public static readonly Color blue75 = new Color(0.25f, 0.25f, 1f);
41
42 public static readonly Color cyan25 = new Color(0.75f, 1f, 1f);
43
44 public static readonly Color cyan50 = new Color(0.5f, 1f, 1f);
45
46 public static readonly Color cyan75 = new Color(0.25f, 1f, 1f);
47
48 public static readonly Color magenta25 = new Color(1f, 0.75f, 1f);
49
50 public static readonly Color magenta50 = new Color(1f, 0.5f, 1f);
51
52 public static readonly Color magenta75 = new Color(1f, 0.25f, 1f);
53
54 public static readonly Color yellow25 = new Color(1f, 1f, 0.75f);
55
56 public static readonly Color yellow50 = new Color(1f, 1f, 0.5f);
57
58 public static readonly Color yellow75 = new Color(1f, 1f, 0.25f);
59
60 public static readonly Color transparentBlack = new Color(0f, 0f, 0f, 0f);
61
62 public static readonly Color transparentWhite = new Color(1f, 1f, 1f, 0f);
63
64 public static readonly Color white = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
65
66 public static readonly Color red = new Color32(byte.MaxValue, 0, 0, byte.MaxValue);
67
68 public static readonly Color brown = new Color32(165, 42, 42, byte.MaxValue);
69
70 public static readonly Color gray = new Color32(190, 190, 190, byte.MaxValue);
71
72 public static readonly Color pink = new Color32(byte.MaxValue, 192, 203, byte.MaxValue);
73
74 public static readonly Color green = new Color32(0, byte.MaxValue, 0, byte.MaxValue);
75
76 public static readonly Color tan = new Color32(210, 180, 140, byte.MaxValue);
77
78 public static readonly Color yellow = new Color32(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue);
79
80 public static readonly Color maroon = new Color32(128, 0, 0, byte.MaxValue);
81
82 public static readonly Color navyBlue = new Color32(0, 0, 128, byte.MaxValue);
83
84 public static readonly Color magenta = new Color32(byte.MaxValue, 0, byte.MaxValue, byte.MaxValue);
85
86 public static readonly Color blue = new Color32(0, 0, byte.MaxValue, byte.MaxValue);
87
88 public static readonly Color aqua = new Color32(0, byte.MaxValue, byte.MaxValue, byte.MaxValue);
89
90 public static readonly Color orange = new Color32(byte.MaxValue, 165, 0, byte.MaxValue);
91
92 public static Color Lighten(this Color c, float value = 0.2f)
93 {
94 return new Color(c.r + value, c.g + value, c.b + value);
95 }
96
97 public static Color Darken(this Color c, float value = 0.2f)
98 {
99 return new Color(c.r - value, c.g - value, c.b - value);
100 }
101
102 public static Color Inverse(this Color color)
103 {
104 return new Color(1f - color.r, 1f - color.g, 1f - color.b, color.a);
105 }
106
107 public static Color HSVtoRGB(HSVColor hsv)
108 {
109 return HSVtoRGB(hsv.h, hsv.s, hsv.v, hsv.a);
110 }
111
112 public static Color HSVtoRGB(float hue, float saturation, float value, float alpha = 1f)
113 {
114 int num = (int)(hue / 60f) % 6;
115 float num2 = hue / 60f - (float)(int)(hue / 60f);
116 float num3 = value * (1f - saturation);
117 float num4 = value * (1f - num2 * saturation);
118 float num5 = value * (1f - (1f - num2) * saturation);
119 return num switch
120 {
121 0 => new Color(value, num5, num3, alpha),
122 1 => new Color(num4, value, num3, alpha),
123 2 => new Color(num3, value, num5, alpha),
124 3 => new Color(num3, num4, value, alpha),
125 4 => new Color(num5, num3, value, alpha),
126 _ => new Color(value, num3, num4, alpha),
127 };
128 }
129
130 public static HSVColor RGBtoHSV(Color color)
131 {
132 if (color.r == color.g && color.g == color.b)
133 {
134 color.r += 0.01f;
135 }
136 return RGBtoHSV(color.r, color.g, color.b, color.a);
137 }
138
139 public static HSVColor RGBtoHSV(float r, float g, float b, float a = 1f)
140 {
141 HSVColor result = default(HSVColor);
142 float num = Mathf.Max(r, g, b);
143 float num2 = Mathf.Min(r, g, b);
144 float num3 = num - num2;
145 result.a = a;
146 if (num == 0f || num2 == 1f || num3 == 0f)
147 {
148 result.h = 0f;
149 result.s = 0f;
150 return result;
151 }
152 if (num == r)
153 {
154 result.h = (g - b) / num3;
155 }
156 else if (num == g)
157 {
158 result.h = (b - r) / num3 + 2f;
159 }
160 else
161 {
162 result.h = (r - g) / num3 + 4f;
163 }
164 result.h *= 60f;
165 if (result.h < 0f)
166 {
167 result.h += 360f;
168 }
169 result.v = num;
170 result.s = num3 / num;
171 return result;
172 }
173
174 public static HSLColor RGBtoHSL(float r, float g, float b, float a = 1f)
175 {
176 HSLColor result = default(HSLColor);
177 float num = Mathf.Max(r, g, b);
178 float num2 = Mathf.Min(r, g, b);
179 float num3 = num - num2;
180 result.a = a;
181 if (num == 0f || num2 == 1f || num3 == 0f)
182 {
183 result.h = 0f;
184 result.s = 0f;
185 return result;
186 }
187 if (num == r)
188 {
189 result.h = (g - b) / num3;
190 }
191 else if (num == g)
192 {
193 result.h = (b - r) / num3 + 2f;
194 }
195 else
196 {
197 result.h = (r - g) / num3 + 4f;
198 }
199 result.h *= 60f;
200 if (result.h < 0f)
201 {
202 result.h += 360f;
203 }
204 result.l = (num + num2) / 2f;
205 result.s = num3 / (1f - Mathf.Abs(2f * result.l - 1f));
206 return result;
207 }
208
209 public static HSLColor RGBtoHSL(Color color)
210 {
211 return RGBtoHSL(color.r, color.g, color.b, color.a);
212 }
213
214 public static HSLColor HSVtoHSL(HSVColor hsv)
215 {
216 HSLColor result = default(HSLColor);
217 result.h = hsv.h;
218 result.l = hsv.v * (2f - hsv.s) / 2f;
219 result.s = hsv.v * hsv.s / (1f - Mathf.Abs(result.l - 1f));
220 return result;
221 }
222
223 public static HSVColor HSLtoHSV(HSLColor hsl)
224 {
225 HSVColor result = default(HSVColor);
226 result.h = hsl.h;
227 result.v = (2f * hsl.l + hsl.s * (1f - Mathf.Abs(2f * hsl.l - 1f))) / 2f;
228 result.s = 2f * (result.v - hsl.l) / result.v;
229 return result;
230 }
231
232 public static string ColorToHex(Color32 color)
233 {
234 return color.r.ToString("X2") + color.g.ToString("X2") + color.b.ToString("X2") + color.a.ToString("X2");
235 }
236
237 public static Color HexToColor(string hex)
238 {
239 byte r = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
240 byte g = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
241 byte b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
242 byte a = byte.MaxValue;
243 if (hex.Length == 8)
244 {
245 a = byte.Parse(hex.Substring(6, 2), NumberStyles.HexNumber);
246 }
247 return new Color32(r, g, b, a);
248 }
249
250 public static Color SlightlyTransparent(Color color)
251 {
252 return color.SetAlpha(0.75f);
253 }
254
255 public static Color SetAlpha(this Color color, float alpha = 0.5f)
256 {
257 color.a = alpha;
258 return color;
259 }
260}
static readonly Color black
Definition: Colorist.cs:14
static readonly Color red
Definition: Colorist.cs:66
static Color SlightlyTransparent(Color color)
Definition: Colorist.cs:250
static Color HexToColor(string hex)
Definition: Colorist.cs:237
static readonly Color magenta50
Definition: Colorist.cs:50
static readonly Color green
Definition: Colorist.cs:74
static readonly Color red75
Definition: Colorist.cs:24
static readonly Color pink
Definition: Colorist.cs:72
static readonly Color magenta
Definition: Colorist.cs:84
static readonly Color red10
Definition: Colorist.cs:18
static readonly Color brown
Definition: Colorist.cs:68
static Color HSVtoRGB(HSVColor hsv)
Definition: Colorist.cs:107
static readonly Color aqua
Definition: Colorist.cs:88
static readonly Color green25
Definition: Colorist.cs:28
static readonly Color nearlyBlack
Definition: Colorist.cs:16
static HSLColor RGBtoHSL(float r, float g, float b, float a=1f)
Definition: Colorist.cs:174
static readonly Color lightSteelBlue
Definition: Colorist.cs:10
static HSLColor RGBtoHSL(Color color)
Definition: Colorist.cs:209
static Color Lighten(this Color c, float value=0.2f)
Definition: Colorist.cs:92
static readonly Color yellow25
Definition: Colorist.cs:54
static Color Darken(this Color c, float value=0.2f)
Definition: Colorist.cs:97
static readonly Color blue50
Definition: Colorist.cs:38
static Color HSVtoRGB(float hue, float saturation, float value, float alpha=1f)
Definition: Colorist.cs:112
static readonly Color steelBlue
Definition: Colorist.cs:8
static readonly Color red50
Definition: Colorist.cs:22
static string ColorToHex(Color32 color)
Definition: Colorist.cs:232
static readonly Color white
Definition: Colorist.cs:64
static readonly Color orange
Definition: Colorist.cs:90
static readonly Color cyan25
Definition: Colorist.cs:42
static readonly Color transparentBlack
Definition: Colorist.cs:60
static readonly Color transparentWhite
Definition: Colorist.cs:62
static readonly Color green10
Definition: Colorist.cs:26
static readonly Color blue
Definition: Colorist.cs:86
static HSVColor RGBtoHSV(Color color)
Definition: Colorist.cs:130
static HSLColor HSVtoHSL(HSVColor hsv)
Definition: Colorist.cs:214
static readonly Color red25
Definition: Colorist.cs:20
static HSVColor HSLtoHSV(HSLColor hsl)
Definition: Colorist.cs:223
static readonly Color tan
Definition: Colorist.cs:76
static HSVColor RGBtoHSV(float r, float g, float b, float a=1f)
Definition: Colorist.cs:139
static readonly Color white32
Definition: Colorist.cs:12
static readonly Color magenta75
Definition: Colorist.cs:52
static readonly Color cyan75
Definition: Colorist.cs:46
static readonly Color blue25
Definition: Colorist.cs:36
static readonly Color yellow50
Definition: Colorist.cs:56
static readonly Color navyBlue
Definition: Colorist.cs:82
static readonly Color gray
Definition: Colorist.cs:70
static readonly Color green50
Definition: Colorist.cs:30
static readonly Color blue10
Definition: Colorist.cs:34
static readonly Color magenta25
Definition: Colorist.cs:48
static readonly Color green75
Definition: Colorist.cs:32
static Color Inverse(this Color color)
Definition: Colorist.cs:102
static Color SetAlpha(this Color color, float alpha=0.5f)
Definition: Colorist.cs:255
static readonly Color blue75
Definition: Colorist.cs:40
static readonly Color maroon
Definition: Colorist.cs:80
static readonly Color cyan50
Definition: Colorist.cs:44
static readonly Color yellow75
Definition: Colorist.cs:58
static readonly Color yellow
Definition: Colorist.cs:78
float l
Definition: HSLColor.cs:7
float h
Definition: HSLColor.cs:3
float a
Definition: HSVColor.cs:9
float h
Definition: HSVColor.cs:3
float s
Definition: HSVColor.cs:5
float v
Definition: HSVColor.cs:7