pub trait Darken {
type Scalar;
// Required methods
fn darken(self, factor: Self::Scalar) -> Self;
fn darken_fixed(self, amount: Self::Scalar) -> Self;
}
Expand description
Operators for darkening a color;
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative function, darken
, scales the lightness
towards the minimum lightness value. This means that for a color with 50%
lightness, if darken(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
,
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(0.5)
is applied to it, the color will have 50% lightness
removed from its lightness value resulting in a new value of 0%.
See also DarkenAssign
, Lighten
and LightenAssign
.
Required Associated Types§
Required Methods§
sourcefn darken(self, factor: Self::Scalar) -> Self
fn darken(self, factor: Self::Scalar) -> Self
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, Darken};
let color = Hsv::new_srgb(0.0, 1.0, 0.5);
assert_relative_eq!(color.darken(0.5).value, 0.25);
sourcefn darken_fixed(self, amount: Self::Scalar) -> Self
fn darken_fixed(self, amount: Self::Scalar) -> Self
Darken the color by amount
, a value ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, Darken};
let color = Hsv::new_srgb(0.0, 1.0, 0.4);
assert_relative_eq!(color.darken_fixed(0.2).value, 0.2);