[][src]Struct courgette::Color

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

Main color structure, holds RGBA but can be constructed using other color spaces.

Fields

r: f32

Red value of the color in the range [0.0, 1.0].

g: f32

Green value of the color in the range [0.0, 1.0].

b: f32

Blue value of the color in the range [0.0, 1.0].

a: f32

Alpha value of the color in the range [0.0, 1.0].

Methods

impl Color[src]

pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self[src]

Shorthand to create a new RGBA color value. Clamps values to their respective ranges.

pub fn hex(hex: u32) -> Self[src]

Construct a color from an 8-digit hexidecimal color code.

Examples

Basic usage:

use courgette::RGB;

// FF at the end represents 1.0 alpha.
let red = RGB::hex(0xFF0000FF);
let yellow = RGB::hex(0xFFFF00FF);
let green = RGB::hex(0x00FF00FF);
let cyan = RGB::hex(0x00FFFFFF);
let blue = RGB::hex(0x0000FFFF);
let magenta = RGB::hex(0xFF00FFFF);

pub fn hex_rgb(hex: u32) -> Self[src]

Construct a color from a 6-digit hexidecimal color code.

pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Self[src]

Construct a color from HSLA values. Applies modulo 360 to hue.

pub fn hsl(h: f32, s: f32, l: f32) -> Self[src]

Construct a color from HSL values. Calls Color::hsla with alpha of 1.0.

pub fn hsva(h: f32, s: f32, v: f32, a: f32) -> Self[src]

Construct a color from HSVA values. Applies modulo 360 to hue.

pub fn hsv(h: f32, s: f32, v: f32) -> Self[src]

Construct a color from HSV values. Calls Color::hsva with alpha of 1.0.

pub fn hsba(h: f32, s: f32, b: f32, a: f32) -> Self[src]

Construct a color from HSBA values. HSB is equivelant to HSV, therefore this simply calls Color::hsva.

pub fn hsb(h: f32, s: f32, b: f32) -> Self[src]

Construct a color from HSB values. Calls Color::hsba with alpha of 1.0.

pub fn brightness(self, percent: f32) -> Self[src]

Change the brightness of the current color, with a percent of 1.0 being normal brightness.

Examples

Basic usage:

use courgette::Color;

let color = Color::hex(0xff4488ff);

let brighter = color.brightness(1.1); // Lighten color by 10%.
let darker = color.brightness(0.9); // Dark color by 10%.

pub fn invert(self) -> Self[src]

Invert the current color.

pub fn grey(self) -> Self[src]

Get greyscale version of the color.

pub fn hue(self, hue: f32) -> Self[src]

Get hue shifted color of the current color. Hue value has a modulo of 360.0 applied.

pub fn hue_shift(self, dhue: f32) -> Self[src]

Hue shift the current color. Changes hue by dhue (delta hue) value.

Trait Implementations

impl Clone for Color[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for Color[src]

impl Into<[f32; 4]> for Color[src]

impl Into<[f32; 3]> for Color[src]

impl Debug for Color[src]

Auto Trait Implementations

impl Send for Color

impl Sync for Color

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

impl<T, U> TryInto 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<T> Any for T where
    T: 'static + ?Sized
[src]