Trait palette::Shade [−][src]
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 { ... } }
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%.
Associated Types
Loading content...Required methods
fn lighten(&self, factor: Self::Scalar) -> Self
[src]
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
[src]
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
fn darken(&self, factor: Self::Scalar) -> Self
[src]
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
[src]
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);
Implementors
impl<S, T> Shade for Luma<S, T> where
T: FloatComponent,
S: LumaStandard<TransferFn = LinearFn>,
[src]
impl<S, T> Shade for Luma<S, T> where
T: FloatComponent,
S: LumaStandard<TransferFn = LinearFn>,
[src]impl<S, T> Shade for Rgb<S, T> where
S: RgbStandard<TransferFn = LinearFn>,
T: FloatComponent,
[src]
impl<S, T> Shade for Rgb<S, T> where
S: RgbStandard<TransferFn = LinearFn>,
T: FloatComponent,
[src]impl<S, T> Shade for Hsl<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]
impl<S, T> Shade for Hsl<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]impl<S, T> Shade for Hsv<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]
impl<S, T> Shade for Hsv<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]impl<S, T> Shade for Hwb<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]
impl<S, T> Shade for Hwb<S, T> where
T: FloatComponent,
S: RgbStandard,
[src]impl<Wp, T> Shade for Hsluv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Hsluv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Lab<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Lab<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Lch<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Lch<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Lchuv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Lchuv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Luv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Luv<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Xyz<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Xyz<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]impl<Wp, T> Shade for Yxy<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]
impl<Wp, T> Shade for Yxy<Wp, T> where
T: FloatComponent,
Wp: WhitePoint,
[src]