[−][src]Struct pastel::Color
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 twoColor
s 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_scaled(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_scaled(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_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_hex_string(&self, leading_hash: bool) -> String
[src]
Format the color as a RGB-representation string (#fc0070
).
pub fn to_rgba_scaled(&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_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 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]
self: &Color,
other: &Color,
fraction: Fraction
) -> Color
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 ToAnsiStyle for Color
[src]
fn ansi_style(&self) -> Style
[src]
impl From<Color> for Style
[src]
impl<'_> From<&'_ Color> for Style
[src]
impl PartialEq<Color> for Color
[src]
fn eq(&self, other: &Color) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for Color
[src]
fn clone(&self) -> Color
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Color
[src]
Auto Trait Implementations
impl Send for Color
impl Unpin for Color
impl Sync for Color
impl UnwindSafe for Color
impl RefUnwindSafe for Color
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,