Trait palette::LightenAssign
source · pub trait LightenAssign {
type Scalar;
// Required methods
fn lighten_assign(&mut self, factor: Self::Scalar);
fn lighten_fixed_assign(&mut self, amount: Self::Scalar);
}
Expand description
Assigning operators for lightening a color.
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative function, lighten_assign
,
scales the lightness towards the maximum lightness value. This means that
for a color with 50% lightness, if lighten_assign(0.5)
is applied to it,
the color will scale halfway to the maximum value of 100% resulting in a new
lightness value of 75%.
The fixed or absolute function,
lighten_fixed_assign
, increase the
lightness value by an amount that is independent of the current lightness of
the color. So for a color with 50% lightness, if lighten_fixed_assign(0.5)
is applied to it, the color will have 50% lightness added to its lightness
value resulting in a new value of 100%.
LightenAssign
is also implemented for [T]
:
use palette::{Hsl, LightenAssign};
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.lighten_assign(0.5);
my_array.lighten_assign(0.5);
my_slice.lighten_assign(0.5);
See also Lighten
, Darken
and DarkenAssign
.
Required Associated Types§
Required Methods§
sourcefn lighten_assign(&mut self, factor: Self::Scalar)
fn lighten_assign(&mut self, factor: Self::Scalar)
Scale the color towards the maximum lightness by factor
, a value
ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsl, LightenAssign};
let mut color = Hsl::new_srgb(0.0, 1.0, 0.5);
color.lighten_assign(0.5);
assert_relative_eq!(color.lightness, 0.75);
sourcefn lighten_fixed_assign(&mut self, amount: Self::Scalar)
fn lighten_fixed_assign(&mut self, amount: Self::Scalar)
Lighten the color by amount
, a value ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsl, LightenAssign};
let mut color = Hsl::new_srgb(0.0, 1.0, 0.4);
color.lighten_fixed_assign(0.2);
assert_relative_eq!(color.lightness, 0.6);