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
impl RGBA
impl RGBA
pub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> RGBA
pub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> RGBA
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);
pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> RGBA
pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> RGBA
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);
pub fn to_greyscale(&self) -> RGBA
pub fn to_greyscale(&self) -> RGBA
Applies a quick grayscale conversion to the color
pub fn desaturate(&self) -> RGBA
pub fn desaturate(&self) -> RGBA
Applies a lengthier desaturate (via HSV) to the color
pub fn lerp(&self, color: RGBA, percent: f32) -> RGBA
pub fn lerp(&self, color: RGBA, percent: f32) -> RGBA
Lerps by a specified percentage (from 0 to 1) between this color and another
pub fn lerp_alpha(&self, color: RGBA, percent: f32) -> RGBA
pub fn lerp_alpha(&self, color: RGBA, percent: f32) -> RGBA
Lerps only the alpha channel, by a specified percentage (from 0 to 1) between this color and another
Trait Implementations
impl Mul<RGBA> for RGBA
impl Mul<RGBA> for RGBA
Support multiplying a color by another color. The result is clamped via the constructor.
impl Mul<f32> for RGBA
impl Mul<f32> for RGBA
Support multiplying a color by a float. The result is clamped via the constructor.
impl Sub<RGBA> for RGBA
impl Sub<RGBA> for RGBA
Support subtracting an RGB from a color. The result is clamped via the constructor.
impl Sub<f32> for RGBA
impl Sub<f32> for RGBA
Support subtracting a float from a color. The result is clamped via the constructor.