Struct buffer_graphics_lib::color::Color
source · pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Expand description
This represents an RGBA color and is used to store a pixel by Image
and PixelsWrapper
Fields§
§r: u8
§g: u8
§b: u8
§a: u8
Implementations§
source§impl Color
impl Color
sourcepub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Converts 0.0..=1.0 to 0..=255 Values outside 0.0..=1.0 are clamped
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
sourcepub const fn gray(value: u8) -> Self
pub const fn gray(value: u8) -> Self
Create a new color with red
, green
and blue
set to value
and alpha
set to 255
sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Convert an i32 into a Color
where bytes match the format [R,G,B,A]
sourcepub fn from_f32_array(array: [f32; 4]) -> Self
pub fn from_f32_array(array: [f32; 4]) -> Self
Convert f32 array in the format [R,G,B,A] to color where 0.0 = 0, and 1.0 = 255
pub fn from_hex(hex: &str) -> Result<Color, ColorError>
source§impl Color
impl Color
sourcepub fn as_f32_array(&self) -> [f32; 4]
pub fn as_f32_array(&self) -> [f32; 4]
Convert color to f32 array in the format [R,G,B,A] where 0.0 = 0, and 1.0 = 255
pub fn blend(&self, other: Color) -> Color
sourcepub fn brightness(&self) -> f32
pub fn brightness(&self) -> f32
ignores alpha
pub fn is_dark(&self) -> bool
pub fn darken(&self) -> Color
pub fn lighten(&self) -> Color
sourcepub fn with_brightness(&self, amount: f32) -> Color
pub fn with_brightness(&self, amount: f32) -> Color
Copy color with brightness
sourcepub fn with_saturate(&self, amount: f32) -> Color
pub fn with_saturate(&self, amount: f32) -> Color
De/saturate color by percentage Negative amount increases saturation
sourcepub fn desaturate(&self) -> Color
pub fn desaturate(&self) -> Color
Decrease saturation by 10%
pub fn to_hex(&self) -> String
Trait Implementations§
source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more