pub struct Color { /* private fields */ }Expand description
An RGBA color value, holding four floating point components.
§Guarantees
- All values are in 0..=1 range.
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
A transparent color.
Sourcepub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Option<Color>
pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Option<Color>
Creates a new color from 4 components.
All values must be in 0..=1 range.
Sourcepub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color
Creates a new color from 4 components.
u8 will be divided by 255 to get the float component.
Sourcepub fn red(&self) -> f32
pub fn red(&self) -> f32
Returns color’s red component.
The value is guarantee to be in a 0..=1 range.
Sourcepub fn green(&self) -> f32
pub fn green(&self) -> f32
Returns color’s green component.
The value is guarantee to be in a 0..=1 range.
Sourcepub fn blue(&self) -> f32
pub fn blue(&self) -> f32
Returns color’s blue component.
The value is guarantee to be in a 0..=1 range.
Sourcepub fn alpha(&self) -> f32
pub fn alpha(&self) -> f32
Returns color’s alpha component.
The value is guarantee to be in a 0..=1 range.
Sourcepub fn set_red(&mut self, c: f32)
pub fn set_red(&mut self, c: f32)
Sets the red component value.
The new value will be clipped to the 0..=1 range.
Sourcepub fn set_green(&mut self, c: f32)
pub fn set_green(&mut self, c: f32)
Sets the green component value.
The new value will be clipped to the 0..=1 range.
Sourcepub fn set_blue(&mut self, c: f32)
pub fn set_blue(&mut self, c: f32)
Sets the blue component value.
The new value will be clipped to the 0..=1 range.
Sourcepub fn set_alpha(&mut self, c: f32)
pub fn set_alpha(&mut self, c: f32)
Sets the alpha component value.
The new value will be clipped to the 0..=1 range.
Sourcepub fn apply_opacity(&mut self, opacity: f32)
pub fn apply_opacity(&mut self, opacity: f32)
Shifts color’s opacity.
Essentially, multiplies color’s alpha by opacity.
opacity will be clamped to the 0..=1 range first.
The final alpha will also be clamped.
Sourcepub fn premultiply(&self) -> PremultipliedColor
pub fn premultiply(&self) -> PremultipliedColor
Converts into a premultiplied color.
Sourcepub fn to_color_u8(&self) -> ColorU8
pub fn to_color_u8(&self) -> ColorU8
Converts into ColorU8.
Trait Implementations§
Source§impl Colorful for Color
impl Colorful for Color
Source§fn jiggle_xy(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
fn jiggle_xy(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
Perturb a color based on its position on the canvas. The perturbation is done by adding a random number from a normal distribution with the given mean and standard deviation to each of the color’s components.
Source§fn jiggle_xy_lightness(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
fn jiggle_xy_lightness(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
Perturb a color’s lightness based on its position on the canvas. The perturbation is done by adding a random number from a normal distribution with the given mean and standard deviation to the color’s lightness.
Source§fn jiggle_xy_saturation(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
fn jiggle_xy_saturation(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
Perturb a color’s saturation based on its position on the canvas. The perturbation is done by adding a random number from a normal distribution with the given mean and standard deviation to the color’s saturation.
Source§fn jiggle_xy_hue(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
fn jiggle_xy_hue(&self, x: u32, y: u32, mean: f32, std: f32) -> Color
Perturb a color’s hue based on its position on the canvas. The perturbation is done by adding a random number from a normal distribution with the given mean and standard deviation to the color’s hue.
Source§fn rotate_hue(&self, degrees: f32) -> Color
fn rotate_hue(&self, degrees: f32) -> Color
Rotate the hue of a color by the given number of degrees.
Source§fn tighten(&self) -> Color
fn tighten(&self) -> Color
Change the lighness of a color to it’s square, i.e. tightening it away from lighter or darker which ever is closer.
Source§fn spread(&self) -> Color
fn spread(&self) -> Color
Change the lighness of a color to it’s square root, i.e. spreading it towards lighter or darker which ever is closer.
Source§fn tint(&self, t: f32) -> Color
fn tint(&self, t: f32) -> Color
Tint a color by mixing it with white. 0 is no white, 1 is all white.
Source§fn tone(&self, t: f32) -> Color
fn tone(&self, t: f32) -> Color
Tone a color by mixing it with gray. 0 is no gray, 1 is all gray.
Source§fn shade(&self, t: f32) -> Color
fn shade(&self, t: f32) -> Color
Shade a color by mixing it with black. 0 is no black, 1 is all black.
Source§fn saturate_fixed(&self, amount: f32) -> Color
fn saturate_fixed(&self, amount: f32) -> Color
Saturate a color a fixed abount.
Source§fn lighten_fixed(&self, amount: f32) -> Color
fn lighten_fixed(&self, amount: f32) -> Color
Lighten a color a fixed abount.
Source§fn lerp(&self, color2: &Color, t: f32) -> Color
fn lerp(&self, color2: &Color, t: f32) -> Color
Linearly interpolate between two colors in a linear color space and convert back to sRGBA.
Source§fn darken_fixed(&self, amount: f32) -> Selfwhere
Self: Sized,
fn darken_fixed(&self, amount: f32) -> Selfwhere
Self: Sized,
Source§fn desaturate(&self, factor: f32) -> Selfwhere
Self: Sized,
fn desaturate(&self, factor: f32) -> Selfwhere
Self: Sized,
Source§fn desaturate_fixed(&self, amount: f32) -> Selfwhere
Self: Sized,
fn desaturate_fixed(&self, amount: f32) -> Selfwhere
Self: Sized,
Source§impl ConvertColor for Color
impl ConvertColor for Color
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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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>
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>
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 moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more