Skip to content

struct

Color

pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}

A color with components in 0.0..=1.0.

Fields

r

pub r: f32

Red.

g

pub g: f32

Green.

b

pub b: f32

Blue.

a

pub a: f32

Alpha: 0 transparent, 1 opaque.

Methods

BLACK

pub const BLACK: Color;

Opaque black.

WHITE

pub const WHITE: Color;

Opaque white.

TRANSPARENT

pub const TRANSPARENT: Color;

Fully transparent.

rgba

pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color

A colour from red, green, blue and alpha, each 0 to 1.

parse

pub fn parse(s: &str) -> Option<Color>

Parse #rgb, #rrggbb, #rrggbbaa, rgb(…), hsl(…) (and their a forms) or a basic CSS color name.

lerp

pub fn lerp(&self, o: Color, t: f32) -> Color

Linear interpolation towards o.

to_css

pub fn to_css(&self) -> String

CSS rgba(…) string for Canvas 2D.

to_hex

pub fn to_hex(&self) -> String

#rrggbb, ignoring alpha.

to_array

pub fn to_array(&self) -> [f32; 4]

[r, g, b, a] for WebGL uniforms.

Trait implementations