1use glam::Vec4;
2
3#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
4pub struct Color {
5 pub r: f32,
6 pub g: f32,
7 pub b: f32,
8 pub a: f32,
9}
10
11impl Color {
12 pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
13 Self { r, g, b, a }
14 }
15
16 pub const fn rgb(r: f32, g: f32, b: f32) -> Self {
17 Self::rgba(r, g, b, 1.0)
18 }
19
20 pub fn with_a(mut self, a: f32) -> Self {
21 self.a = a.clamp(0.0, 1.0);
22 self
23 }
24
25 pub fn to_rgba(&self) -> (f32, f32, f32, f32) {
26 (self.r, self.g, self.b, self.a)
27 }
28
29 pub const fn rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self {
30 Self {
31 r: r as f32 / 255.0,
32 g: g as f32 / 255.0,
33 b: b as f32 / 255.0,
34 a: a as f32 / 255.0,
35 }
36 }
37
38 pub const fn rgb_u8(r: u8, g: u8, b: u8) -> Self {
39 Self::rgba_u8(r, g, b, 0xff)
40 }
41
42 pub fn with_a_u8(mut self, a: u8) -> Self {
43 self.a = a as f32 / 255.0;
44 self
45 }
46
47 pub fn to_rgba_u8(&self) -> (u8, u8, u8, u8) {
48 (
49 (self.r * 255.0).round() as u8,
50 (self.g * 255.0).round() as u8,
51 (self.b * 255.0).round() as u8,
52 (self.a * 255.0).round() as u8,
53 )
54 }
55
56 pub fn to_vec4(&self) -> Vec4 {
57 Vec4::new(self.r, self.g, self.b, self.a)
58 }
59}
60
61pub const WHITE: Color = Color::rgb_u8(0xff, 0xff, 0xff);
62pub const BLACK: Color = Color::rgb_u8(0, 0, 0);
63pub const BLUE: Color = Color::rgb_u8(0, 0, 0xff);
64pub const GRAY: Color = Color::rgb_u8(0x80, 0x80, 0x80);
65pub const GREEN: Color = Color::rgb_u8(0, 0x80, 0);
66pub const PURPLE: Color = Color::rgb_u8(0x80, 0, 0x80);
67pub const RED: Color = Color::rgb_u8(0xff, 0, 0);
68pub const SILVER: Color = Color::rgb_u8(0xc0, 0xc0, 0xc0);
69pub const YELLOW: Color = Color::rgb_u8(0xff, 0xff, 0);
70pub const NAVY: Color = Color::rgb_u8(0x00, 0x00, 0x80);
71pub const DARK_BLUE: Color = Color::rgb_u8(0x00, 0x00, 0x8b);
72pub const MEDIUM_BLUE: Color = Color::rgb_u8(0x00, 0x00, 0xcd);
73pub const DARK_GREEN: Color = Color::rgb_u8(0x00, 0x64, 0x00);
74pub const TEAL: Color = Color::rgb_u8(0x00, 0x80, 0x80);
75pub const DARK_CYAN: Color = Color::rgb_u8(0x00, 0x8B, 0x8B);
76pub const DEEP_SKY_BLUE: Color = Color::rgb_u8(0x00, 0xBF, 0xFF);
77pub const DARK_TURQUOISE: Color = Color::rgb_u8(0x00, 0xce, 0xd1);
78pub const MEDIUM_SPRING_GREEN: Color = Color::rgb_u8(0x00, 0xfa, 0x9a);
79pub const LIME: Color = Color::rgb_u8(0x00, 0xff, 0x00);
80pub const SPRING_GREEN: Color = Color::rgb_u8(0x00, 0xff, 0x7f);
81pub const AQUA: Color = Color::rgb_u8(0x00, 0xff, 0xff);
82pub const MIDNIGHT_BLUE: Color = Color::rgb_u8(0x19, 0x19, 0x70);
83pub const DODGER_BLUE: Color = Color::rgb_u8(0x1e, 0x90, 0xff);
84pub const LIGHT_SEA_GREEN: Color = Color::rgb_u8(0x20, 0xb2, 0xaa);
85pub const FOREST_GREEN: Color = Color::rgb_u8(0x22, 0x8b, 0x22);
86pub const SEA_GREEN: Color = Color::rgb_u8(0x2e, 0x8b, 0x57);
87pub const DARK_SLATE_GRAY: Color = Color::rgb_u8(0x2f, 0x4f, 0x4f);
88pub const LIME_GREEN: Color = Color::rgb_u8(0x32, 0xcd, 0x32);
89pub const MEDIUM_SEA_GREEN: Color = Color::rgb_u8(0x3c, 0xb3, 0x71);
90pub const TURQUOISE: Color = Color::rgb_u8(0x40, 0xe0, 0xd0);
91pub const ROYAL_BLUE: Color = Color::rgb_u8(0x41, 0x69, 0xe1);
92pub const STEEL_BLUE: Color = Color::rgb_u8(0x46, 0x82, 0xb4);
93pub const DARK_SLATE_BLUE: Color = Color::rgb_u8(0x48, 0x3d, 0x8b);
94pub const MEDIUM_TORQUOISE: Color = Color::rgb_u8(0x48, 0xd1, 0xcc);
95pub const INDIGO: Color = Color::rgb_u8(0x4b, 0x00, 0x82);
96pub const DARK_OLIVE_GREEN: Color = Color::rgb_u8(0x55, 0x6b, 0x2f);
97pub const CADET_BLUE: Color = Color::rgb_u8(0x5f, 0x9e, 0xa0);
98pub const CORN_FLOWER_BLUE: Color = Color::rgb_u8(0x64, 0x95, 0xed);
99pub const REBECCA_PURPLE: Color = Color::rgb_u8(0x66, 0x33, 0x99);
100pub const MEDIUM_AQUA_MARINE: Color = Color::rgb_u8(0x66, 0xcd, 0xaa);
101pub const DIM_GRAY: Color = Color::rgb_u8(0x69, 0x69, 0x69);
102pub const SLATE_BLUE: Color = Color::rgb_u8(0x6a, 0x5a, 0xcd);
103pub const OLIVE_DRAB: Color = Color::rgb_u8(0x6b, 0x8e, 0x23);
104pub const SLATE_GRAY: Color = Color::rgb_u8(0x70, 0x80, 0x90);
105pub const LIGHT_SLATE_GRAY: Color = Color::rgb_u8(0x77, 0x88, 0x99);
106pub const MEDIUM_SLATE_BLUE: Color = Color::rgb_u8(0x7b, 0x68, 0xee);
107pub const LAWN_GREEN: Color = Color::rgb_u8(0x7c, 0xfc, 0x00);
108pub const CHARTREUSE: Color = Color::rgb_u8(0x7f, 0xff, 0x00);
109pub const AUQAMARINE: Color = Color::rgb_u8(0x7f, 0xff, 0xd4);
110pub const MAROON: Color = Color::rgb_u8(0x80, 0x00, 0x00);
111pub const OLIVE: Color = Color::rgb_u8(0x80, 0x80, 0x00);
112pub const SKY_BLUE: Color = Color::rgb_u8(0x87, 0xce, 0xeb);
113pub const LIGHT_SKY_BLUE: Color = Color::rgb_u8(0x87, 0xce, 0xfa);
114pub const BLUE_VIOLET: Color = Color::rgb_u8(0x8a, 0x2b, 0xe2);
115pub const DARK_RED: Color = Color::rgb_u8(0x8b, 0x00, 0x00);
116pub const DARK_MAGENTA: Color = Color::rgb_u8(0x8b, 0x00, 0x8b);
117pub const SADDLE_BROWN: Color = Color::rgb_u8(0x8b, 0x45, 0x13);
118pub const DARK_SEA_GREEN: Color = Color::rgb_u8(0x8f, 0xbc, 0x8f);
119pub const LIGHT_GREEN: Color = Color::rgb_u8(0x90, 0xee, 0x90);
120pub const MEDIUM_PURPLE: Color = Color::rgb_u8(0x93, 0x70, 0xdb);
121pub const DARK_VIOLET: Color = Color::rgb_u8(0x94, 0x00, 0xd3);
122pub const PALE_GREEN: Color = Color::rgb_u8(0x98, 0xfb, 0x98);
123pub const DARK_ORCHID: Color = Color::rgb_u8(0x99, 0x32, 0xcc);
124pub const YELLOW_GREEN: Color = Color::rgb_u8(0x9a, 0xcd, 0x32);
125pub const SIENNA: Color = Color::rgb_u8(0xa0, 0x52, 0x2d);
126pub const BROWN: Color = Color::rgb_u8(0xa5, 0x2a, 0x2a);
127pub const DARK_GRAY: Color = Color::rgb_u8(0xa9, 0xa9, 0xa9);
128pub const LIGHT_BLUE: Color = Color::rgb_u8(0xad, 0xd8, 0xe6);
129pub const PALE_TURQUOISE: Color = Color::rgb_u8(0xaf, 0xee, 0xee);
130pub const FIRE_BRICK: Color = Color::rgb_u8(0xb2, 0x22, 0x22);
131pub const DARK_GOLDEN_ROD: Color = Color::rgb_u8(0xb8, 0x86, 0x0b);
132pub const MEDIUM_ORCHID: Color = Color::rgb_u8(0xba, 0x55, 0xd3);
133pub const ROSY_BROWN: Color = Color::rgb_u8(0xbc, 0x8f, 0x8f);
134pub const DARK_KHAKI: Color = Color::rgb_u8(0xbd, 0xb7, 0x6b);
135pub const MEDIUM_VIOLET_RED: Color = Color::rgb_u8(0xc7, 0x15, 0x85);
136pub const INDIAN_RED: Color = Color::rgb_u8(0xcd, 0x5c, 0x5c);
137pub const PERU: Color = Color::rgb_u8(0xcd, 0x85, 0x3f);
138pub const CHOCOLATE: Color = Color::rgb_u8(0xd2, 0x69, 0x1e);
139pub const TAN: Color = Color::rgb_u8(0xd2, 0xb4, 0x8c);
140pub const LIGHT_GRAY: Color = Color::rgb_u8(0xd3, 0xd3, 0xd3);
141pub const THISTLE: Color = Color::rgb_u8(0xd8, 0xbf, 0xd8);
142pub const ORCHID: Color = Color::rgb_u8(0xda, 0x70, 0xd6);
143pub const GOLDEN_ROD: Color = Color::rgb_u8(0xda, 0xa5, 0x20);
144pub const PALE_VIOLET_RED: Color = Color::rgb_u8(0xdb, 0x70, 0x93);
145pub const CRIMSON: Color = Color::rgb_u8(0xdc, 0x14, 0x3c);
146pub const GAINSBORO: Color = Color::rgb_u8(0xdc, 0xdc, 0xdc);
147pub const PLUM: Color = Color::rgb_u8(0xdd, 0xa0, 0xdd);
148pub const BURLY_WOOD: Color = Color::rgb_u8(0xde, 0xb8, 0x87);
149pub const LIGHT_CYAN: Color = Color::rgb_u8(0xe0, 0xff, 0xff);
150pub const LAVENDER: Color = Color::rgb_u8(0xe6, 0xe6, 0xfa);
151pub const DARK_SALMON: Color = Color::rgb_u8(0xe9, 0x96, 0x7a);
152pub const VIOLET: Color = Color::rgb_u8(0xee, 0x82, 0xee);
153pub const PALE_GOLDEN_ROD: Color = Color::rgb_u8(0xee, 0xe8, 0xaa);
154pub const LIGHT_CORAL: Color = Color::rgb_u8(0xf0, 0x80, 0x80);
155pub const KHAKI: Color = Color::rgb_u8(0xf0, 0xe6, 0x8c);
156pub const ALICE_BLUE: Color = Color::rgb_u8(0xf0, 0xf8, 0xff);
157pub const HONEY_DEW: Color = Color::rgb_u8(0xf0, 0xff, 0xf0);
158pub const AZURE: Color = Color::rgb_u8(0xf0, 0xff, 0xff);
159pub const SANDY_BROWN: Color = Color::rgb_u8(0xf4, 0xa4, 0x60);
160pub const WHEAT: Color = Color::rgb_u8(0xf5, 0xde, 0xb3);
161pub const BEIGE: Color = Color::rgb_u8(0xf5, 0xf5, 0xdc);
162pub const WHITE_SMOKE: Color = Color::rgb_u8(0xf5, 0xf5, 0xf5);
163pub const MINT_CREAM: Color = Color::rgb_u8(0xf5, 0xff, 0xfa);
164pub const GHOST_WHITE: Color = Color::rgb_u8(0xf8, 0xf8, 0xff);
165pub const SALMON: Color = Color::rgb_u8(0xfa, 0x80, 0x72);
166pub const ANTIQUE_WHITE: Color = Color::rgb_u8(0xfa, 0xeb, 0xd7);
167pub const LINEN: Color = Color::rgb_u8(0xfa, 0xf0, 0xe6);
168pub const LIGHT_GOLDEN_ROD_YELLOW: Color = Color::rgb_u8(0xfa, 0xfa, 0xd2);
169pub const OLD_LACE: Color = Color::rgb_u8(0xfd, 0xf5, 0xe6);
170pub const FUCHSIA: Color = Color::rgb_u8(0xff, 0x00, 0xff);
171pub const DEEP_PINK: Color = Color::rgb_u8(0xff, 0x14, 0x93);
172pub const ORANGE_RED: Color = Color::rgb_u8(0xff, 0x45, 0x00);
173pub const TOMATO: Color = Color::rgb_u8(0xff, 0x63, 0x47);
174pub const HOT_PINK: Color = Color::rgb_u8(0xff, 0x69, 0xb4);
175pub const CORAL: Color = Color::rgb_u8(0xff, 0x7f, 0x50);
176pub const DARK_ORANGE: Color = Color::rgb_u8(0xff, 0x8c, 0x00);
177pub const LIGHT_SALMON: Color = Color::rgb_u8(0xff, 0xa0, 0x7a);
178pub const ORANGE: Color = Color::rgb_u8(0xff, 0xa5, 0x00);
179pub const LIGHT_PINK: Color = Color::rgb_u8(0xff, 0xb6, 0xc1);
180pub const PINK: Color = Color::rgb_u8(0xff, 0xc0, 0xcb);
181pub const GOLD: Color = Color::rgb_u8(0xff, 0xd7, 0x00);
182pub const PEACH_PUFF: Color = Color::rgb_u8(0xff, 0xda, 0xb9);
183pub const NAVAJO_WHITE: Color = Color::rgb_u8(0xff, 0xde, 0xad);
184pub const MOCCASIN: Color = Color::rgb_u8(0xff, 0xe4, 0xb5);
185pub const BISQUE: Color = Color::rgb_u8(0xff, 0xe4, 0xc4);
186pub const MISTY_ROSE: Color = Color::rgb_u8(0xff, 0xe4, 0xe1);
187pub const BLANCHED_ALMOND: Color = Color::rgb_u8(0xff, 0xeb, 0xcd);
188pub const PAPAYA_WHIP: Color = Color::rgb_u8(0xff, 0xef, 0xd5);
189pub const LAVENDER_BLUSH: Color = Color::rgb_u8(0xff, 0xf0, 0xf5);
190pub const SEA_SHELL: Color = Color::rgb_u8(0xff, 0xf5, 0xee);
191pub const CORNSILK: Color = Color::rgb_u8(0xff, 0xf8, 0xdc);
192pub const LEMON_CHIFFON: Color = Color::rgb_u8(0xff, 0xfa, 0xcd);
193pub const FLORAL_WHITE: Color = Color::rgb_u8(0xff, 0xfa, 0xf0);
194pub const SNOW: Color = Color::rgb_u8(0xff, 0xfa, 0xfa);
195pub const LIGHT_YELLOW: Color = Color::rgb_u8(0xff, 0xff, 0xe0);
196pub const IVORY: Color = Color::rgb_u8(0xff, 0xff, 0xf0);