Struct bracket_color::rgba::RGBA
source · [−]Expand description
Represents an R/G/B triplet, in the range 0..1 (32-bit float)
Fields
r: f32
The red component (0..1)
g: f32
The green component (0..1)
b: f32
The blue component (0..1)
a: f32
The alpha component (0..1), 0 is transparent, 1 is solid
Implementations
sourceimpl RGBA
impl RGBA
sourcepub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> Self
Constructs a new RGB color, from 3 32-bit floats in the range 0..1
Arguments
r
- the red component (0..1)g
- the green component (0..1)b
- the blue component (0..1)a
- the alpha component (0..1). 0 is transparent, 1 is solid.
Example
use bracket_color::prelude::*;
let red = RGBA::from_f32(1.0, 0.0, 0.0, 1.0);
let green = RGBA::from_f32(0.0, 1.0, 0.0, 1.0);
let invisible = RGBA::from_f32(0.0, 0.0, 0.0, 0.0);
sourcepub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a new RGB color, from 3 bytes in the range 0..255
Arguments
r
- the red component, ranged from 0 to 255g
- the green component, ranged from 0 to 255b
- the blue component, ranged from 0 to 255
Example
use bracket_color::prelude::*;
let red = RGBA::from_u8(255, 0, 0, 255);
let green = RGBA::from_u8(0, 255, 0, 255);
let invisible = RGBA::from_u8(0, 0, 0, 0);
sourcepub fn to_greyscale(&self) -> Self
pub fn to_greyscale(&self) -> Self
Applies a quick grayscale conversion to the color
sourcepub fn desaturate(&self) -> Self
pub fn desaturate(&self) -> Self
Applies a lengthier desaturate (via HSV) to the color
sourcepub fn lerp(&self, color: Self, percent: f32) -> Self
pub fn lerp(&self, color: Self, percent: f32) -> Self
Lerps by a specified percentage (from 0 to 1) between this color and another
sourcepub fn lerp_alpha(&self, color: Self, percent: f32) -> Self
pub fn lerp_alpha(&self, color: Self, percent: f32) -> Self
Lerps only the alpha channel, by a specified percentage (from 0 to 1) between this color and another
Trait Implementations
sourceimpl Add<RGBA> for RGBA
impl Add<RGBA> for RGBA
Support adding an RGB to a color. The result is clamped via the constructor.
sourceimpl Add<f32> for RGBA
impl Add<f32> for RGBA
Support adding a float to a color. The result is clamped via the constructor.
sourceimpl Mul<RGBA> for RGBA
impl Mul<RGBA> for RGBA
Support multiplying a color by another color. The result is clamped via the constructor.
sourceimpl Mul<f32> for RGBA
impl Mul<f32> for RGBA
Support multiplying a color by a float. The result is clamped via the constructor.
sourceimpl Sub<RGBA> for RGBA
impl Sub<RGBA> for RGBA
Support subtracting an RGB from a color. The result is clamped via the constructor.
sourceimpl Sub<f32> for RGBA
impl Sub<f32> for RGBA
Support subtracting a float from a color. The result is clamped via the constructor.