pub trait Shade: Sized {
type Scalar: Float;
fn lighten(&self, factor: Self::Scalar) -> Self;
fn lighten_fixed(&self, amount: Self::Scalar) -> Self;
fn darken(&self, factor: Self::Scalar) -> Self { ... }
fn darken_fixed(&self, amount: Self::Scalar) -> Self { ... }
}
Expand description
The Shade
trait allows a color to be lightened or darkened.
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative functions, lighten
and
darken
, scale the lightness towards the maximum lightness
value and minimum lightness value, respectively. This means that for a color
with 50% lightness, if lighten(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%. darken(0.5)
applied to the original color will result in a new color
with lightness of 25% since the lightness moves halfway toward the minimum
value of 0%.
The fixed or absolute functions, lighten_fixed
and
darken_fixed
, increase or descrease 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(0.5)
is
applied to it, the color will have 50% lightness added to its lightness
value resulting in a new value of 100%. darken_fixed(0.5)
will result in a
new color with lightness of 0% since 50% lightness is subtracted from the
original value of 50%.
Required Associated Types
Required Methods
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, Shade};
let color = Hsl::new(0.0, 1.0, 0.5);
assert_relative_eq!(color.lighten(0.5).lightness, 0.75);
fn lighten_fixed(&self, amount: Self::Scalar) -> Self
fn lighten_fixed(&self, amount: Self::Scalar) -> Self
Lighten the color by amount
, a value ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsl, Shade};
let color = Hsl::new(0.0, 1.0, 0.4);
assert_relative_eq!(color.lighten_fixed(0.2).lightness, 0.6);
Provided Methods
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, Shade};
let color = Hsv::new(0.0, 1.0, 0.5);
assert_relative_eq!(color.darken(0.5).value, 0.25);
fn 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, Shade};
let color = Hsv::new(0.0, 1.0, 0.4);
assert_relative_eq!(color.darken_fixed(0.2).value, 0.2);