pub trait DarkenAssign {
type Scalar;
// Required methods
fn darken_assign(&mut self, factor: Self::Scalar);
fn darken_fixed_assign(&mut self, amount: Self::Scalar);
}
Expand description
Assigning operators for darkening a color;
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative function, darken_assign
,
scales the lightness towards the minimum lightness value. This means that
for a color with 50% lightness, if darken_assign(0.5)
is applied to it,
the color will scale halfway to the minimum value of 0% resulting in a new
lightness value of 25%.
The fixed or absolute function,
darken_fixed_assign
, decreases the
lightness value by an amount that is independent of the current lightness of
the color. So for a color with 50% lightness, if darken_fixed_assign(0.5)
is applied to it, the color will have 50% lightness removed from its
lightness value resulting in a new value of 0%.
DarkenAssign
is also implemented for [T]
:
use palette::{Hsl, DarkenAssign};
let mut my_vec = vec![Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(113.0, 0.5, 0.8)];
let mut my_array = [Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(113.0, 0.5, 0.8)];
let mut my_slice = &mut [Hsl::new_srgb(104.0, 0.3, 0.8), Hsl::new_srgb(112.0, 0.5, 0.8)];
my_vec.darken_assign(0.5);
my_array.darken_assign(0.5);
my_slice.darken_assign(0.5);
See also Darken
, Lighten
and LightenAssign
.
Required Associated Types§
Required Methods§
sourcefn darken_assign(&mut self, factor: Self::Scalar)
fn darken_assign(&mut self, factor: Self::Scalar)
Scale the color towards the minimum lightness by factor
, a value
ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, DarkenAssign};
let mut color = Hsv::new_srgb(0.0, 1.0, 0.5);
color.darken_assign(0.5);
assert_relative_eq!(color.value, 0.25);
sourcefn darken_fixed_assign(&mut self, amount: Self::Scalar)
fn darken_fixed_assign(&mut self, amount: Self::Scalar)
Darken the color by amount
, a value ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, DarkenAssign};
let mut color = Hsv::new_srgb(0.0, 1.0, 0.4);
color.darken_fixed_assign(0.2);
assert_relative_eq!(color.value, 0.2);