pub struct Color(pub [u8; 4]);Expand description
Represents a color in RGBA format.
This struct encapsulates color information using red, green, blue, and alpha (opacity) channels. Each channel is an 8-bit unsigned integer.
§Examples
Creating and manipulating colors:
use grafo::Color;
// Create a black color
let black = Color::BLACK;
// Create a red color with full opacity
let red = Color::rgb(255, 0, 0);
// Create a semi-transparent blue color
let semi_blue = Color::rgba(0, 0, 255, 128);
// Normalize the color values to [0.0, 1.0]
let normalized = red.normalize();
assert_eq!(normalized, [1.0, 0.0, 0.0, 1.0]);
// Convert the color to an array
let color_array = semi_blue.to_array();
assert_eq!(color_array, [0, 0, 255, 128]);Tuple Fields§
§0: [u8; 4]Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
A transparent color.
All color channels are set to zero, making the color fully transparent.
Sourcepub const BLACK: Self
pub const BLACK: Self
A black color.
Red, green, and blue channels are set to zero, and alpha is fully opaque.
Sourcepub const WHITE: Self
pub const WHITE: Self
A white color.
Red, green, and blue channels are set to zero, and alpha is fully opaque.
Sourcepub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Creates a new color with the specified RGBA values.
§Parameters
r: Red channel (0-255)g: Green channel (0-255)b: Blue channel (0-255)a: Alpha channel (0-255), where 0 is fully transparent and 255 is fully opaque
§Examples
use grafo::Color;
// Semi-transparent purple
let purple = Color::rgba(128, 0, 128, 128);
assert_eq!(purple, Color([128, 0, 128, 128]));Sourcepub fn normalize(&self) -> [f32; 4]
pub fn normalize(&self) -> [f32; 4]
Normalizes the color values to the range [0.0, 1.0].
This is useful for graphics operations that require floating-point color values.
§Examples
use grafo::Color;
let red = Color::rgb(255, 0, 0);
let normalized = red.normalize();
assert_eq!(normalized, [1.0, 0.0, 0.0, 1.0]);Trait Implementations§
impl Copy for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more