[][src]Struct pastel::Color

pub struct Color { /* fields omitted */ }

The representation of a color.

Note:

  • Colors outside the sRGB gamut (which cannot be displayed on a typical computer screen) can not be represented by Color.
  • The PartialEq instance compares two Colors by comparing their (integer) RGB values. This is different from comparing the HSL values. For example, HSL has many different representations of black (arbitrary hue and saturation values).

Methods

impl Color[src]

pub fn from_hsla(hue: f64, saturation: f64, lightness: f64, alpha: f64) -> Color[src]

pub fn from_hsl(hue: f64, saturation: f64, lightness: f64) -> Color[src]

pub fn from_rgba(r: u8, g: u8, b: u8, alpha: f64) -> Color[src]

Create a Color from integer RGB values between 0 and 255 and a floating point alpha value between 0.0 and 1.0.

pub fn from_rgb(r: u8, g: u8, b: u8) -> Color[src]

Create a Color from integer RGB values between 0 and 255.

pub fn from_rgba_float(r: f64, g: f64, b: f64, alpha: f64) -> Color[src]

Create a Color from RGB and alpha values between 0.0 and 1.0. Values outside this range will be clamped.

pub fn from_rgb_float(r: f64, g: f64, b: f64) -> Color[src]

Create a Color from RGB values between 0.0 and 1.0. Values outside this range will be clamped.

pub fn from_xyz(x: f64, y: f64, z: f64, alpha: f64) -> Color[src]

Create a Color from XYZ coordinates in the CIE 1931 color space. Note that a Color always represents a color in the sRGB gamut (colors that can be represented on a typical computer screen) while the XYZ color space is bigger. This function will tend to create fully saturated colors at the edge of the sRGB gamut if the coordinates lie outside the sRGB range.

See:

  • https://en.wikipedia.org/wiki/CIE_1931_color_space
  • https://en.wikipedia.org/wiki/SRGB

pub fn from_lms(l: f64, m: f64, s: f64, alpha: f64) -> Color[src]

Create a Color from LMS coordinates. This is the matrix inverse of the matrix that appears in to_lms.

pub fn from_lab(l: f64, a: f64, b: f64, alpha: f64) -> Color[src]

Create a Color from L, a and b coordinates coordinates in the Lab color space. Note: See documentation for from_xyz. The same restrictions apply here.

See: https://en.wikipedia.org/wiki/Lab_color_space

pub fn from_lch(l: f64, c: f64, h: f64, alpha: f64) -> Color[src]

Create a Color from lightness, chroma and hue coordinates in the CIE LCh color space. This is a cylindrical transform of the Lab color space. Note: See documentation for from_xyz. The same restrictions apply here.

See: https://en.wikipedia.org/wiki/Lab_color_space

pub fn to_hsla(&self) -> HSLA[src]

Convert a Color to its hue, saturation, lightness and alpha values. The hue is given in degrees, as a number between 0.0 and 360.0. Saturation, lightness and alpha are numbers between 0.0 and 1.0.

pub fn to_hsl_string(&self, format: Format) -> String[src]

Format the color as a HSL-representation string (hsl(123, 50.3%, 80.1%)).

pub fn to_rgba(&self) -> RGBA<u8>[src]

Convert a Color to its red, green, blue and alpha values. The RGB values are integers in the range from 0 to 255. The alpha channel is a number between 0.0 and 1.0.

pub fn to_rgb_string(&self, format: Format) -> String[src]

Format the color as a RGB-representation string (rgb(255, 127, 0)).

pub fn to_rgb_float_string(&self, format: Format) -> String[src]

Format the color as a floating point RGB-representation string (rgb(1.0, 0.5, 0)).

pub fn to_rgb_hex_string(&self, leading_hash: bool) -> String[src]

Format the color as a RGB-representation string (#fc0070).

pub fn to_rgba_float(&self) -> RGBA<f64>[src]

Convert a Color to its red, green, blue and alpha values. All numbers are from the range between 0.0 and 1.0.

pub fn to_u32(&self) -> u32[src]

Return the color as an integer in RGB representation (0xRRGGBB)

pub fn to_xyz(&self) -> XYZ[src]

Get XYZ coordinates according to the CIE 1931 color space.

See:

  • https://en.wikipedia.org/wiki/CIE_1931_color_space
  • https://en.wikipedia.org/wiki/SRGB

pub fn to_lms(&self) -> LMS[src]

Get coordinates according to the LSM color space

See https://en.wikipedia.org/wiki/LMS_color_space for info on the color space as well as an algorithm for converting from CIE XYZ

pub fn to_lab(&self) -> Lab[src]

Get L, a and b coordinates according to the Lab color space.

See: https://en.wikipedia.org/wiki/Lab_color_space

pub fn to_lab_string(&self, format: Format) -> String[src]

Format the color as a Lab-representation string (Lab(41, 83, -93)).

pub fn to_lch(&self) -> LCh[src]

Get L, C and h coordinates according to the CIE LCh color space.

See: https://en.wikipedia.org/wiki/Lab_color_space

pub fn to_lch_string(&self, format: Format) -> String[src]

Format the color as a LCh-representation string (LCh(0.3, 0.2, 0.1)).

pub fn black() -> Color[src]

Pure black.

pub fn white() -> Color[src]

Pure white.

pub fn red() -> Color[src]

Red (#ff0000)

pub fn green() -> Color[src]

Green (#008000)

pub fn blue() -> Color[src]

Blue (#0000ff)

pub fn yellow() -> Color[src]

Yellow (#ffff00)

pub fn fuchsia() -> Color[src]

Fuchsia (#ff00ff)

pub fn aqua() -> Color[src]

Aqua (#00ffff)

pub fn lime() -> Color[src]

Lime (#00ff00)

pub fn maroon() -> Color[src]

Maroon (#800000)

pub fn olive() -> Color[src]

Olive (#808000)

pub fn navy() -> Color[src]

Navy (#000080)

pub fn purple() -> Color[src]

Purple (#800080)

pub fn teal() -> Color[src]

Teal (#008080)

pub fn silver() -> Color[src]

Silver (#c0c0c0)

pub fn gray() -> Color[src]

Gray (#808080)

pub fn graytone(lightness: f64) -> Color[src]

Create a gray tone from a lightness value (0.0 is black, 1.0 is white).

pub fn rotate_hue(&self, delta: f64) -> Color[src]

Rotate along the "hue" axis.

pub fn complementary(&self) -> Color[src]

Get the complementary color (hue rotated by 180°).

pub fn lighten(&self, f: f64) -> Color[src]

Lighten a color by adding a certain amount (number between -1.0 and 1.0) to the lightness channel. If the number is negative, the color is darkened.

pub fn darken(&self, f: f64) -> Color[src]

Darken a color by subtracting a certain amount (number between -1.0 and 1.0) from the lightness channel. If the number is negative, the color is lightened.

pub fn saturate(&self, f: f64) -> Color[src]

Increase the saturation of a color by adding a certain amount (number between -1.0 and 1.0) to the saturation channel. If the number is negative, the color is desaturated.

pub fn desaturate(&self, f: f64) -> Color[src]

Decrease the saturation of a color by subtracting a certain amount (number between -1.0 and 1.0) from the saturation channel. If the number is negative, the color is saturated.

pub fn simulate_colorblindness(&self, cb_ty: ColorblindnessType) -> Color[src]

Adjust the long-, medium-, and short-wavelength cone perception of a color to simulate what a colorblind person sees. Since there are multiple kinds of colorblindness, the desired kind must be specified in cb_ty.

pub fn to_gray(&self) -> Color[src]

Convert a color to a gray tone with the same perceived luminance (see luminance).

pub fn brightness(&self) -> f64[src]

The percieved brightness of the color (A number between 0.0 and 1.0).

See: https://www.w3.org/TR/AERT#color-contrast

pub fn is_light(&self) -> bool[src]

Determine whether a color is perceived as a light color (perceived brightness is larger than 0.5).

pub fn luminance(&self) -> f64[src]

The relative brightness of a color (normalized to 0.0 for darkest black and 1.0 for lightest white), according to the WCAG definition.

See: https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef

pub fn contrast_ratio(&self, other: &Color) -> f64[src]

Contrast ratio between two colors as defined by the WCAG. The ratio can range from 1.0 to 21.0. Two colors with a contrast ratio of 4.5 or higher can be used as text color and background color and should be well readable.

https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef

pub fn text_color(&self) -> Color[src]

Return a readable foreground text color (either black or white) for a given background color.

pub fn distance_delta_e_cie76(&self, other: &Color) -> f64[src]

Compute the perceived 'distance' between two colors according to the CIE76 delta-E standard. A distance below ~2.3 is not noticable.

See: https://en.wikipedia.org/wiki/Color_difference

pub fn distance_delta_e_ciede2000(&self, other: &Color) -> f64[src]

Compute the perceived 'distance' between two colors according to the CIEDE2000 delta-E standard.

See: https://en.wikipedia.org/wiki/Color_difference

pub fn mix<C: ColorSpace>(
    self: &Color,
    other: &Color,
    fraction: Fraction
) -> Color
[src]

Mix two colors by linearly interpolating between them in the specified color space. For the angle-like components (hue), the shortest path along the unit circle is chosen.

Trait Implementations

impl AnsiColor for Color[src]

fn from_ansi_8bit(code: u8) -> Color[src]

Create a color from an 8-bit ANSI escape code

See: https://en.wikipedia.org/wiki/ANSI_escape_code

fn to_ansi_8bit(&self) -> u8[src]

Approximate a color by its closest 8-bit ANSI color (as measured by the perceived color distance).

See: https://en.wikipedia.org/wiki/ANSI_escape_code

fn to_ansi_sequence(&self, mode: Mode) -> String[src]

Return an ANSI escape sequence in 8-bit or 24-bit representation:

  • 8-bit: ESC[38;5;CODEm, where CODE represents the color.
  • 24-bit: ESC[38;2;R;G;Bm, where R, G, B represent 8-bit RGB values

impl Clone for Color[src]

impl Debug for Color[src]

impl<'_> From<&'_ Color> for Style[src]

impl From<Color> for Style[src]

impl PartialEq<Color> for Color[src]

impl ToAnsiStyle for Color[src]

Auto Trait Implementations

impl RefUnwindSafe for Color

impl Send for Color

impl Sync for Color

impl Unpin for Color

impl UnwindSafe for Color

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,