pub struct RGBA {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
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§
Source§impl RGBA
impl RGBA
Sourcepub 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);
Sourcepub 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);
Sourcepub fn from_hex<S>(code: S) -> Result<RGBA, HtmlColorConversionError>
pub fn from_hex<S>(code: S) -> Result<RGBA, HtmlColorConversionError>
Sourcepub fn to_greyscale(&self) -> RGBA
pub fn to_greyscale(&self) -> RGBA
Applies a quick grayscale conversion to the color
Sourcepub fn desaturate(&self) -> RGBA
pub fn desaturate(&self) -> RGBA
Applies a lengthier desaturate (via HSV) to the color
Sourcepub 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
Sourcepub 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§
Source§impl Add<f32> for RGBA
Support adding a float to a color. The result is clamped via the constructor.
impl Add<f32> for RGBA
Support adding a float to a color. The result is clamped via the constructor.
Source§impl Add for RGBA
Support adding an RGB to a color. The result is clamped via the constructor.
impl Add for RGBA
Support adding an RGB to a color. The result is clamped via the constructor.
Source§impl Mul<f32> for RGBA
Support multiplying a color by a float. The result is clamped via the constructor.
impl Mul<f32> for RGBA
Support multiplying a color by a float. The result is clamped via the constructor.
Source§impl Mul for RGBA
Support multiplying a color by another color. The result is clamped via the constructor.
impl Mul for RGBA
Support multiplying a color by another color. The result is clamped via the constructor.
Source§impl Sub<f32> for RGBA
Support subtracting a float from a color. The result is clamped via the constructor.
impl Sub<f32> for RGBA
Support subtracting a float from a color. The result is clamped via the constructor.
Source§impl Sub for RGBA
Support subtracting an RGB from a color. The result is clamped via the constructor.
impl Sub for RGBA
Support subtracting an RGB from a color. The result is clamped via the constructor.