Struct tint::Color

source · []
pub struct Color {
    pub red: f64,
    pub green: f64,
    pub blue: f64,
    pub alpha: f64,
}
Expand description

Color value

Fields

red: f64

Red component [0,1]

green: f64

Green component [0,1]

blue: f64

Blue component [0,1]

alpha: f64

Alpha component [0,1]

Implementations

Create new color from components

use tint::Color;
let red = Color::new(1.0, 0.0, 0.0, 1.0);
let fushcia = Color::new(1.0, 0.0, 1.0, 1.0);

Create new color from RGB components [0. .. 1.0], alpha value set to 1.0

let blue = Color::from_rgb1(0.0, 0.0, 1.0);

Create new color from RGB f64 vector [0. .. 1.0], alpha value set to 1.0

let green = Color::from_rgb1v(&[0.0, 1.0, 0.0]);

Convert Color to (f64,f64,f64)

let purple = Color::new(1.0, 0.0, 1.0, 1.0);
let rgb = purple.to_rgb1();
assert_eq!(rgb, (1.0, 0.0, 1.0));

Create new Color from RGB [0 .. 255] alpha value set to 1.0

let purple = Color::from_rgb255(255, 0, 255);

Create new Color from RGB u8 vector [0 .. 255] alpha value set to 1.0

let purple = Color::from_rgb255v(&[255, 0, 255]);
assert_eq!(purple.red,   1.0);
assert_eq!(purple.green, 0.0);
assert_eq!(purple.blue,  1.0);

Convert color to (u8,u8,u8)

let purple = Color::new(1.0, 0.0, 1.0, 1.0);
assert_eq!(purple.to_rgb255(), (255,0,255));

Create new Color from Hex String

let facade = Color::from_hex("#facade");
assert_eq!(facade.to_rgb255(), (250, 202, 222));

Convert Color into Hex String

let coffee = Color::from_rgb255(192, 255, 238);
assert_eq!(coffee.to_hex(), "#c0ffee");

Get Color from exiting named colors Colors are defined from w3c Basic and Extended colors and colors from the XKCD database if loaded

let chartreuse = Color::name("chartreuse");
assert_eq!(chartreuse, Some(Color::from_hex("7fff00")));
let olive_drab = Color::name("olivedrab").unwrap();
assert_eq!(olive_drab.to_rgb255(), (107,142,35));

tint::xkcd();
let butterscotch = Color::name("butterscotch").unwrap();
assert_eq!(butterscotch.to_hex(), "#fdb147");

let avocado = Color::name("avocado green").unwrap();
assert_eq!(avocado.to_rgb255(), (135, 169, 34));

Convert Color to HSV

Create new Color from HSV alpha value set to 1.0

Convert Color to HSL

Create new Color from HSL alpha value set to 1.0

Convert Color to YIQ

Create new Color from YIQ alpha value set to 1.0

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Convert from a f32 triple, red, green, blue

Converts to this type from the input type.

Convert from a f64 triple, red, green, blue

Converts to this type from the input type.

Convert from a u8 triple, red, green, blue

Converts to this type from the input type.

Convert from named color or a hex string

This may fail

Converts to this type from the input type.

Convert from a f32 Vec, red, green, blue, maybe alpha

This may fail

Converts to this type from the input type.

Convert from a f64 Vec, red, green, blue, maybe alpha

This may fail

Converts to this type from the input type.

Convert from named color or a hex string

This may fail

Converts to this type from the input type.

Convert from a f32 triple, red, green, blue

Converts to this type from the input type.

Convert from a f64 triple, red, green, blue

Converts to this type from the input type.

Convert from a u8 triple, red, green, blue

Converts to this type from the input type.

Convert from a f32 triple, red, green, blue

Converts to this type from the input type.

Convert from a f64 triple, red, green, blue

Converts to this type from the input type.

Convert from a u8 triple, red, green, blue

Converts to this type from the input type.

Convert from named color or a hex string

This may fail

Converts to this type from the input type.

Convert from a f32 Vec, red, green, blue, maybe alpha

This may fail

Converts to this type from the input type.

Convert from a f32 Vec, red, green, blue, maybe alpha

This may fail

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.