1#[repr(C)]
2#[derive(Debug, Clone, Copy, PartialEq)]
3pub struct Color {
4 r: u8,
5 g: u8,
6 b: u8,
7 a: u8,
8}
9
10impl Color {
11 pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
12 Self { r, g, b, a }
13 }
14
15 pub fn fade(color: Color, alpha: f32) -> Self {
16 *(color.clone().fade_mut(alpha))
17 }
18}
19
20impl Color {
21 pub fn fade_mut(&mut self, alpha: f32) -> &mut Self {
23 self.a = (255.0 * alpha.clamp(0., 1.)) as u8;
24 self
25 }
26
27 pub fn to_int(&self) -> i32 {
29 ((self.r as i32) << 24) | ((self.g as i32) << 16) | ((self.b as i32) << 8) | self.a as i32
30 }
31
32 pub fn tint(&mut self, color: &Color) -> &mut Self {
34 self.r = ((self.r as i32 * color.r as i32) / 255) as u8;
35 self.g = ((self.g as i32 * color.g as i32) / 255) as u8;
36 self.b = ((self.b as i32 * color.b as i32) / 255) as u8;
37 self.a = ((self.a as i32 * color.a as i32) / 255) as u8;
38
39 self
40 }
41}
42
43impl From<(u8, u8, u8, u8)> for Color {
44 fn from(value: (u8, u8, u8, u8)) -> Self {
45 Color::new(value.0, value.1, value.2, value.3)
46 }
47}
48
49impl From<(u8, u8, u8)> for Color {
50 fn from(value: (u8, u8, u8)) -> Self {
51 Color::new(value.0, value.1, value.2, 255)
52 }
53}
54
55impl Color {
56 pub const INDIANRED: Color = Color::new(205, 92, 92, 255);
57 pub const LIGHTCORAL: Color = Color::new(240, 128, 128, 255);
58 pub const SALMON: Color = Color::new(250, 128, 114, 255);
59 pub const DARKSALMON: Color = Color::new(233, 150, 122, 255);
60 pub const LIGHTSALMON: Color = Color::new(255, 160, 122, 255);
61 pub const CRIMSON: Color = Color::new(220, 20, 60, 255);
62 pub const RED: Color = Color::new(230, 41, 55, 255);
63 pub const FIREBRICK: Color = Color::new(178, 34, 34, 255);
64 pub const DARKRED: Color = Color::new(139, 0, 0, 255);
65 pub const PINK: Color = Color::new(255, 109, 194, 255);
66 pub const LIGHTPINK: Color = Color::new(255, 182, 193, 255);
67 pub const HOTPINK: Color = Color::new(255, 105, 180, 255);
68 pub const DEEPPINK: Color = Color::new(255, 20, 147, 255);
69 pub const MEDIUMVIOLETRED: Color = Color::new(199, 21, 133, 255);
70 pub const PALEVIOLETRED: Color = Color::new(219, 112, 147, 255);
71 pub const CORAL: Color = Color::new(255, 127, 80, 255);
72 pub const TOMATO: Color = Color::new(255, 99, 71, 255);
73 pub const ORANGERED: Color = Color::new(255, 69, 0, 255);
74 pub const DARKORANGE: Color = Color::new(255, 140, 0, 255);
75 pub const ORANGE: Color = Color::new(255, 161, 0, 255);
76 pub const GOLD: Color = Color::new(255, 203, 0, 255);
77 pub const YELLOW: Color = Color::new(253, 249, 0, 255);
78 pub const LIGHTYELLOW: Color = Color::new(255, 255, 224, 255);
79 pub const LEMONCHIFFON: Color = Color::new(255, 250, 205, 255);
80 pub const LIGHTGOLDENRODYELLOW: Color = Color::new(250, 250, 210, 255);
81 pub const PAPAYAWHIP: Color = Color::new(255, 239, 213, 255);
82 pub const MOCCASIN: Color = Color::new(255, 228, 181, 255);
83 pub const PEACHPUFF: Color = Color::new(255, 218, 185, 255);
84 pub const PALEGOLDENROD: Color = Color::new(238, 232, 170, 255);
85 pub const KHAKI: Color = Color::new(240, 230, 140, 255);
86 pub const DARKKHAKI: Color = Color::new(189, 183, 107, 255);
87 pub const LAVENDER: Color = Color::new(230, 230, 250, 255);
88 pub const THISTLE: Color = Color::new(216, 191, 216, 255);
89 pub const PLUM: Color = Color::new(221, 160, 221, 255);
90 pub const VIOLET: Color = Color::new(135, 60, 190, 255);
91 pub const ORCHID: Color = Color::new(218, 112, 214, 255);
92 pub const FUCHSIA: Color = Color::new(255, 0, 255, 255);
93 pub const MAGENTA: Color = Color::new(255, 0, 255, 255);
94 pub const MEDIUMORCHID: Color = Color::new(186, 85, 211, 255);
95 pub const MEDIUMPURPLE: Color = Color::new(147, 112, 219, 255);
96 pub const REBECCAPURPLE: Color = Color::new(102, 51, 153, 255);
97 pub const BLUEVIOLET: Color = Color::new(138, 43, 226, 255);
98 pub const DARKVIOLET: Color = Color::new(148, 0, 211, 255);
99 pub const DARKORCHID: Color = Color::new(153, 50, 204, 255);
100 pub const DARKMAGENTA: Color = Color::new(139, 0, 139, 255);
101 pub const PURPLE: Color = Color::new(200, 122, 255, 255);
102 pub const DARKPURPLE: Color = Color::new(112, 31, 126, 255);
103 pub const INDIGO: Color = Color::new(75, 0, 130, 255);
104 pub const SLATEBLUE: Color = Color::new(106, 90, 205, 255);
105 pub const DARKSLATEBLUE: Color = Color::new(72, 61, 139, 255);
106 pub const MEDIUMSLATEBLUE: Color = Color::new(123, 104, 238, 255);
107 pub const GREENYELLOW: Color = Color::new(173, 255, 47, 255);
108 pub const CHARTREUSE: Color = Color::new(127, 255, 0, 255);
109 pub const LAWNGREEN: Color = Color::new(124, 252, 0, 255);
110 pub const LIME: Color = Color::new(0, 158, 47, 255);
111 pub const LIMEGREEN: Color = Color::new(50, 205, 50, 255);
112 pub const PALEGREEN: Color = Color::new(152, 251, 152, 255);
113 pub const LIGHTGREEN: Color = Color::new(144, 238, 144, 255);
114 pub const MEDIUMSPRINGGREEN: Color = Color::new(0, 250, 154, 255);
115 pub const SPRINGGREEN: Color = Color::new(0, 255, 127, 255);
116 pub const MEDIUMSEAGREEN: Color = Color::new(60, 179, 113, 255);
117 pub const SEAGREEN: Color = Color::new(46, 139, 87, 255);
118 pub const FORESTGREEN: Color = Color::new(34, 139, 34, 255);
119 pub const GREEN: Color = Color::new(0, 228, 48, 255);
120 pub const DARKGREEN: Color = Color::new(0, 117, 44, 255);
121 pub const YELLOWGREEN: Color = Color::new(154, 205, 50, 255);
122 pub const OLIVEDRAB: Color = Color::new(107, 142, 35, 255);
123 pub const OLIVE: Color = Color::new(128, 128, 0, 255);
124 pub const DARKOLIVEGREEN: Color = Color::new(85, 107, 47, 255);
125 pub const MEDIUMAQUAMARINE: Color = Color::new(102, 205, 170, 255);
126 pub const DARKSEAGREEN: Color = Color::new(143, 188, 139, 255);
127 pub const LIGHTSEAGREEN: Color = Color::new(32, 178, 170, 255);
128 pub const DARKCYAN: Color = Color::new(0, 139, 139, 255);
129 pub const TEAL: Color = Color::new(0, 128, 128, 255);
130 pub const AQUA: Color = Color::new(0, 255, 255, 255);
131 pub const CYAN: Color = Color::new(0, 255, 255, 255);
132 pub const LIGHTCYAN: Color = Color::new(224, 255, 255, 255);
133 pub const PALETURQUOISE: Color = Color::new(175, 238, 238, 255);
134 pub const AQUAMARINE: Color = Color::new(127, 255, 212, 255);
135 pub const TURQUOISE: Color = Color::new(64, 224, 208, 255);
136 pub const MEDIUMTURQUOISE: Color = Color::new(72, 209, 204, 255);
137 pub const DARKTURQUOISE: Color = Color::new(0, 206, 209, 255);
138 pub const CADETBLUE: Color = Color::new(95, 158, 160, 255);
139 pub const STEELBLUE: Color = Color::new(70, 130, 180, 255);
140 pub const LIGHTSTEELBLUE: Color = Color::new(176, 196, 222, 255);
141 pub const POWDERBLUE: Color = Color::new(176, 224, 230, 255);
142 pub const LIGHTBLUE: Color = Color::new(173, 216, 230, 255);
143 pub const SKYBLUE: Color = Color::new(102, 191, 255, 255);
144 pub const LIGHTSKYBLUE: Color = Color::new(135, 206, 250, 255);
145 pub const DEEPSKYBLUE: Color = Color::new(0, 191, 255, 255);
146 pub const DODGERBLUE: Color = Color::new(30, 144, 255, 255);
147 pub const CORNFLOWERBLUE: Color = Color::new(100, 149, 237, 255);
148 pub const ROYALBLUE: Color = Color::new(65, 105, 225, 255);
149 pub const BLUE: Color = Color::new(0, 121, 241, 255);
150 pub const MEDIUMBLUE: Color = Color::new(0, 0, 205, 255);
151 pub const DARKBLUE: Color = Color::new(0, 82, 172, 255);
152 pub const NAVY: Color = Color::new(0, 0, 128, 255);
153 pub const MIDNIGHTBLUE: Color = Color::new(25, 25, 112, 255);
154 pub const CORNSILK: Color = Color::new(255, 248, 220, 255);
155 pub const BLANCHEDALMOND: Color = Color::new(255, 235, 205, 255);
156 pub const BISQUE: Color = Color::new(255, 228, 196, 255);
157 pub const NAVAJOWHITE: Color = Color::new(255, 222, 173, 255);
158 pub const WHEAT: Color = Color::new(245, 222, 179, 255);
159 pub const BURLYWOOD: Color = Color::new(222, 184, 135, 255);
160 pub const TAN: Color = Color::new(210, 180, 140, 255);
161 pub const ROSYBROWN: Color = Color::new(188, 143, 143, 255);
162 pub const SANDYBROWN: Color = Color::new(244, 164, 96, 255);
163 pub const GOLDENROD: Color = Color::new(218, 165, 32, 255);
164 pub const DARKGOLDENROD: Color = Color::new(184, 134, 11, 255);
165 pub const PERU: Color = Color::new(205, 133, 63, 255);
166 pub const CHOCOLATE: Color = Color::new(210, 105, 30, 255);
167 pub const SADDLEBROWN: Color = Color::new(139, 69, 19, 255);
168 pub const SIENNA: Color = Color::new(160, 82, 45, 255);
169 pub const BROWN: Color = Color::new(127, 106, 79, 255);
170 pub const DARKBROWN: Color = Color::new(76, 63, 47, 255);
171 pub const MAROON: Color = Color::new(190, 33, 55, 255);
172 pub const WHITE: Color = Color::new(255, 255, 255, 255);
173 pub const SNOW: Color = Color::new(255, 250, 250, 255);
174 pub const HONEYDEW: Color = Color::new(240, 255, 240, 255);
175 pub const MINTCREAM: Color = Color::new(245, 255, 250, 255);
176 pub const AZURE: Color = Color::new(240, 255, 255, 255);
177 pub const ALICEBLUE: Color = Color::new(240, 248, 255, 255);
178 pub const GHOSTWHITE: Color = Color::new(248, 248, 255, 255);
179 pub const WHITESMOKE: Color = Color::new(245, 245, 245, 255);
180 pub const SEASHELL: Color = Color::new(255, 245, 238, 255);
181 pub const BEIGE: Color = Color::new(211, 176, 131, 255);
182 pub const OLDLACE: Color = Color::new(253, 245, 230, 255);
183 pub const FLORALWHITE: Color = Color::new(255, 250, 240, 255);
184 pub const IVORY: Color = Color::new(255, 255, 240, 255);
185 pub const ANTIQUEWHITE: Color = Color::new(250, 235, 215, 255);
186 pub const LINEN: Color = Color::new(250, 240, 230, 255);
187 pub const LAVENDERBLUSH: Color = Color::new(255, 240, 245, 255);
188 pub const MISTYROSE: Color = Color::new(255, 228, 225, 255);
189 pub const GAINSBORO: Color = Color::new(220, 220, 220, 255);
190 pub const LIGHTGRAY: Color = Color::new(200, 200, 200, 255);
191 pub const SILVER: Color = Color::new(192, 192, 192, 255);
192 pub const DARKGRAY: Color = Color::new(80, 80, 80, 255);
193 pub const GRAY: Color = Color::new(130, 130, 130, 255);
194 pub const DIMGRAY: Color = Color::new(105, 105, 105, 255);
195 pub const LIGHTSLATEGRAY: Color = Color::new(119, 136, 153, 255);
196 pub const SLATEGRAY: Color = Color::new(112, 128, 144, 255);
197 pub const DARKSLATEGRAY: Color = Color::new(47, 79, 79, 255);
198 pub const BLACK: Color = Color::new(0, 0, 0, 255);
199 pub const BLANK: Color = Color::new(0, 0, 0, 0);
200 pub const RAYWHITE: Color = Color::new(245, 245, 245, 255);
201}