Struct glm_color::rgb::Rgb [] [src]

#[repr(C)]
pub struct Rgb { /* fields omitted */ }

The linear RGB color space.

Methods

impl Rgb
[src]

Constructs a Rgb color from given red, green and blue values.

Parameter values are clamped into the interval [0, 1].

Example

use glm_color::*;

let blue = Rgb::new(-10., 0., 1000.);
assert_eq!(blue, BLUE);

Returns the value of red channel of self.

Example

use glm_color::*;

assert_eq!(RED.red(), 1.);

Returns the value of green channel of self.

Returns the value of blue channel of self.

Returns a new Rgb value that has given red valud r and same green and blue values as self.

Example

use glm_color::*;

let clr = RED.with_red(0.75);
assert_eq!(clr.red(), 0.75);
assert_eq!(clr.green(), 0.);
assert_eq!(clr.blue(), 0.)

Changes the red value of self to r.

Example

use glm_color::*;

let mut clr = BLUE;
clr.set_red(100.);
assert_eq!(clr.red(), 1.);

Returns a new Rgb value that has given green valud g and same red and blue values as self.

Changes the green value of self to g.

Returns a new Rgb value that has given blue valud b and same red and green values as self.

Changes the blue value of self to b.

Creates a Rgb value by specifying red, green and blue values in u8 type.

Example

use glm_color::*;

let red = Rgb::from_u8(255, 0, 0);
assert_eq!(red.red(), 1f32);

Constructs a Rgb value from a 32-bit unsigned integer clr.

The lower 24 bits of clr are intepreted as 3 8-bit values, from low to high, for B, G and R respectively.

Example

use glm_color::{ Rgb, CYAN };
let cyan = Rgb::from_u32(0x00FFFF);
assert_eq!(cyan, CYAN);
assert_eq!(cyan.red(), 0.);

Returns the hue of self. It is a value in the interval [0, 2π).

Example

use glm::*;
use glm_color::*;

assert_eq!(RED.hue(), 0.);
assert_eq!(GREEN.hue(), radians(120.));
assert_eq!(BLUE.hue(), radians(240.));

Returns the saturation of self. It is a value in the interval [0, 1].

Example

use glm_color::*;

// gray colors have 0 saturation.
assert_eq!(GRAY.saturation(), 0.);
// pure color has full saturation.
assert_eq!(RED.saturation(), 1.);

Returns the lightness of self.

Note

The returned value is maximum of red, green, and blue channels.

Returns self's lunimance.

Luminance is calculated with the same parameters as YCbCr color space's from_rgb() function.

Example

use glm_color::*;

assert_eq!(WHITE.lunimance(), 1.);
assert_eq!(BLACK.lunimance(), 0.);

Re-interprets the reference of a Rgb to a reference of Vec3.

Example

use glm_color as color;

let red = color::RED;
assert_eq!(red.as_vec3().x, red.red());

Constructs an Rgb value by randomly choosing values for each of the three RGB channels using the thread local RNG.

Note

This function is used to generates a single seed color. Use other member methods to generates colors that have certain relationships with the seed.

Example

use glm_color::*;

let seed = Rgb::rand();
// generating 10 colors based on `seed`.
let clrs: Vec<Rgb> = (0..10).map(|_| -> Rgb {
    seed.rand_offset(0.3)
}).collect();

Constructs an Rgb value by adding a random offset to all RGB channels.

offset is clamped to the interval [0, 1].

Trait Implementations

impl Copy for Rgb
[src]

impl Clone for Rgb
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Rgb
[src]

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

This method tests for !=.

impl Debug for Rgb
[src]

Formats the value using the given formatter.

impl ColorSpace for Rgb
[src]

Constructs from color value rgb in RGB color space.

Converts self to a color value in RGB color space.

impl Eq for Rgb
[src]

impl Rand for Rgb
[src]

Generates a random instance of this type using the specified source of randomness. Read more

impl ApproxEq for Rgb
[src]

Returns true if the difference between x and y is less than max_diff. Read more

Returns true if the difference between x and y is less than machine epsilon. Read more

impl Add<Rgb> for Rgb
[src]

The resulting type after applying the + operator

The method for the + operator

impl Sub<Rgb> for Rgb
[src]

The resulting type after applying the - operator

The method for the - operator

impl Mul<f32> for Rgb
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<Rgb> for Rgb
[src]

The resulting type after applying the * operator

The method for the * operator