#[repr(C)]pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
A color represented by 4 floats: red, green, blue and alpha.
Fields§
§r: f32Red channel value from 0.0 to 1.0.
g: f32Green channel value from 0.0 to 1.0.
b: f32Blue channel value from 0.0 to 1.0.
a: f32Alpha channel value from 0.0 to 1.0.
Implementations§
Source§impl Color
impl Color
Sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Color
Creates a new Color with the given red, green, blue, and alpha components.
Values are expected to be between 0.0 and 1.0.
§Example
use macroquad::prelude::*;
let pink = Color::new(1.00, 0.43, 0.76, 1.00);
assert_eq!(pink.r, 1.00);
assert_eq!(pink.g, 0.43);
assert_eq!(pink.b, 0.76);
assert_eq!(pink.a, 1.00);Note that values outside of this range are effectively clamped, and do not generate an error or warning.
Sourcepub const fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Color
pub const fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Color
Build a color from 4 components between 0 and 255.
Sourcepub const fn from_hex(hex: u32) -> Color
pub const fn from_hex(hex: u32) -> Color
Build a color from a hexadecimal u32.
§Example
use macroquad::prelude::*;
let light_blue = Color::from_hex(0x3CA7D5);
assert_eq!(light_blue.r, 0.23529412);
assert_eq!(light_blue.g, 0.654902);
assert_eq!(light_blue.b, 0.8352941);
assert_eq!(light_blue.a, 1.00);Sourcepub const fn from_vec(vec: Vec4) -> Color
pub const fn from_vec(vec: Vec4) -> Color
Create a color from a vec4 of red, green, blue, and alpha components.
Sourcepub const fn with_alpha(&self, alpha: f32) -> Color
pub const fn with_alpha(&self, alpha: f32) -> Color
Create a copy of the current color, but with a different alpha value.
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 UnsafeUnpin 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