Add element access to Color
This commit is contained in:
parent
99749c90e4
commit
a0a94c6c01
1 changed files with 41 additions and 0 deletions
41
src/color.rs
41
src/color.rs
|
@ -18,6 +18,47 @@ pub enum Color {
|
||||||
Custom(u8, u8, u8),
|
Custom(u8, u8, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Color {
|
||||||
|
pub fn r(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
Color::White => 255,
|
||||||
|
Color::Black => 0,
|
||||||
|
Color::Red => 255,
|
||||||
|
Color::Blue => 0,
|
||||||
|
Color::Green => 0,
|
||||||
|
Color::Orange => 255,
|
||||||
|
Color::Yellow => 255,
|
||||||
|
Color::Custom(r, _g, _b) => *r,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn g(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
Color::White => 255,
|
||||||
|
Color::Black => 0,
|
||||||
|
Color::Red => 0,
|
||||||
|
Color::Blue => 0,
|
||||||
|
Color::Green => 255,
|
||||||
|
Color::Orange => 166,
|
||||||
|
Color::Yellow => 255,
|
||||||
|
Color::Custom(_r, g, _b) => *g,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn b(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
Color::White => 255,
|
||||||
|
Color::Black => 0,
|
||||||
|
Color::Red => 0,
|
||||||
|
Color::Blue => 255,
|
||||||
|
Color::Green => 0,
|
||||||
|
Color::Orange => 0,
|
||||||
|
Color::Yellow => 0,
|
||||||
|
Color::Custom(_r, _g, b) => *b,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Into<[f32; 3]> for Color {
|
impl Into<[f32; 3]> for Color {
|
||||||
fn into(self) -> [f32; 3] {
|
fn into(self) -> [f32; 3] {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue