Skip to main content

Color

Struct Color 

Source
#[repr(C)]
pub struct Color { pub r: u8, pub g: u8, pub b: u8, pub a: u8, }
Expand description

A 32-bit RGBA color value with 8 bits per channel.

Color is a #[repr(C)] struct with fields r, g, b, a each in the range 0..=255. It maps directly to raylib’s Color type in C.

A large set of named constants is available via the bundled Color::RED, Color::WHITE, Color::RAYWHITE, etc. — see the impl block below for the full list. CSS color names are also available through the CSSPalette trait and raylib palette names through RaylibPalette.

§Examples

use raylib_sys::Color;

// Construct a color and compare against a named constant
let red = Color::new(255, 0, 0, 255);
assert_eq!(red, Color::RED);

// Use alpha() to get a semi-transparent variant
let semi = Color::RED.alpha(0.5);
assert!(semi.a < 200);

Fields§

§r: u8§g: u8§b: u8§a: u8

Implementations§

Source§

impl Color

Source

pub fn from_hex(color_hex_str: &str) -> Result<Color, ParseIntError>

produces Color from a hex string(6 characters long)

Source

pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Color

Source

pub fn color_to_int(&self) -> i32

Get hexadecimal value for a Color (0xRRGGBBAA)

Source

pub fn color_normalize(&self) -> Vector4

Get Color normalized as float [0..1]

Source

pub fn color_to_hsv(&self) -> Vector3

Get HSV values for a Color, hue [0..360], saturation/value [0..1]

Source

pub fn color_from_hsv(hue: f32, saturation: f32, value: f32) -> Color

Get a Color from HSV values, hue [0..360], saturation/value [0..1]

Source

pub fn color_from_normalized(normalized: Vector4) -> Color

Get Color from normalized values [0..1]

Source

pub fn get_color(hex_value: u32) -> Color

Get Color structure from hexadecimal value

Source

pub fn tint(&self, color: Self) -> Self

Get color multiplied with another color

Source

pub fn brightness(&self, factor: f32) -> Self

Get color with brightness correction, brightness factor goes from -1.0f to 1.0f

Source

pub fn contrast(&self, factor: f32) -> Self

Get color with contrast correction, contrast values between -1.0f and 1.0f

Source

pub fn alpha(&self, alpha: f32) -> Self

Get color with alpha applied, alpha goes from 0.0f to 1.0f

Source

pub fn fade(&self, alpha: f32) -> Self

👎Deprecated:

Use Color::alpha instead

Get color with alpha applied, alpha goes from 0.0f to 1.0f

Source

pub fn color_alpha_blend(dst: &Color, src: &Color, tint: &Color) -> Color

Color fade-in or fade-out, alpha goes from 0.0f to 1.0f

Source

pub fn is_equal(&self, rhs: impl Into<Color>) -> bool

Check if two colors are equal

Source

pub fn lerp(&self, rhs: Color, factor: f32) -> Color

Get color lerp interpolation between two colors, factor [0.0f..1.0f]

Source§

impl Color

Color constants

Source

pub const INDIANRED: Color

Source

pub const LIGHTCORAL: Color

Source

pub const SALMON: Color

Source

pub const DARKSALMON: Color

Source

pub const LIGHTSALMON: Color

Source

pub const CRIMSON: Color

Source

pub const RED: Color

Source

pub const FIREBRICK: Color

Source

pub const DARKRED: Color

Source

pub const PINK: Color

Source

pub const LIGHTPINK: Color

Source

pub const HOTPINK: Color

Source

pub const DEEPPINK: Color

Source

pub const MEDIUMVIOLETRED: Color

Source

pub const PALEVIOLETRED: Color

Source

pub const CORAL: Color

Source

pub const TOMATO: Color

Source

pub const ORANGERED: Color

Source

pub const DARKORANGE: Color

Source

pub const ORANGE: Color

Source

pub const GOLD: Color

Source

pub const YELLOW: Color

Source

pub const LIGHTYELLOW: Color

Source

pub const LEMONCHIFFON: Color

Source

pub const LIGHTGOLDENRODYELLOW: Color

Source

pub const PAPAYAWHIP: Color

Source

pub const MOCCASIN: Color

Source

pub const PEACHPUFF: Color

Source

pub const PALEGOLDENROD: Color

Source

pub const KHAKI: Color

Source

pub const DARKKHAKI: Color

Source

pub const LAVENDER: Color

Source

pub const THISTLE: Color

Source

pub const PLUM: Color

Source

pub const VIOLET: Color

Source

pub const ORCHID: Color

Source

pub const FUCHSIA: Color

Source

pub const MAGENTA: Color

Source

pub const MEDIUMORCHID: Color

Source

pub const MEDIUMPURPLE: Color

Source

pub const REBECCAPURPLE: Color

Source

pub const BLUEVIOLET: Color

Source

pub const DARKVIOLET: Color

Source

pub const DARKORCHID: Color

Source

pub const DARKMAGENTA: Color

Source

pub const PURPLE: Color

Source

pub const DARKPURPLE: Color

Source

pub const INDIGO: Color

Source

pub const SLATEBLUE: Color

Source

pub const DARKSLATEBLUE: Color

Source

pub const MEDIUMSLATEBLUE: Color

Source

pub const GREENYELLOW: Color

Source

pub const CHARTREUSE: Color

Source

pub const LAWNGREEN: Color

Source

pub const LIME: Color

Source

pub const LIMEGREEN: Color

Source

pub const PALEGREEN: Color

Source

pub const LIGHTGREEN: Color

Source

pub const MEDIUMSPRINGGREEN: Color

Source

pub const SPRINGGREEN: Color

Source

pub const MEDIUMSEAGREEN: Color

Source

pub const SEAGREEN: Color

Source

pub const FORESTGREEN: Color

Source

pub const GREEN: Color

Source

pub const DARKGREEN: Color

Source

pub const YELLOWGREEN: Color

Source

pub const OLIVEDRAB: Color

Source

pub const OLIVE: Color

Source

pub const DARKOLIVEGREEN: Color

Source

pub const MEDIUMAQUAMARINE: Color

Source

pub const DARKSEAGREEN: Color

Source

pub const LIGHTSEAGREEN: Color

Source

pub const DARKCYAN: Color

Source

pub const TEAL: Color

Source

pub const AQUA: Color

Source

pub const CYAN: Color

Source

pub const LIGHTCYAN: Color

Source

pub const PALETURQUOISE: Color

Source

pub const AQUAMARINE: Color

Source

pub const TURQUOISE: Color

Source

pub const MEDIUMTURQUOISE: Color

Source

pub const DARKTURQUOISE: Color

Source

pub const CADETBLUE: Color

Source

pub const STEELBLUE: Color

Source

pub const LIGHTSTEELBLUE: Color

Source

pub const POWDERBLUE: Color

Source

pub const LIGHTBLUE: Color

Source

pub const SKYBLUE: Color

Source

pub const LIGHTSKYBLUE: Color

Source

pub const DEEPSKYBLUE: Color

Source

pub const DODGERBLUE: Color

Source

pub const CORNFLOWERBLUE: Color

Source

pub const ROYALBLUE: Color

Source

pub const BLUE: Color

Source

pub const MEDIUMBLUE: Color

Source

pub const DARKBLUE: Color

Source

pub const NAVY: Color

Source

pub const MIDNIGHTBLUE: Color

Source

pub const CORNSILK: Color

Source

pub const BLANCHEDALMOND: Color

Source

pub const BISQUE: Color

Source

pub const NAVAJOWHITE: Color

Source

pub const WHEAT: Color

Source

pub const BURLYWOOD: Color

Source

pub const TAN: Color

Source

pub const ROSYBROWN: Color

Source

pub const SANDYBROWN: Color

Source

pub const GOLDENROD: Color

Source

pub const DARKGOLDENROD: Color

Source

pub const PERU: Color

Source

pub const CHOCOLATE: Color

Source

pub const SADDLEBROWN: Color

Source

pub const SIENNA: Color

Source

pub const BROWN: Color

Source

pub const DARKBROWN: Color

Source

pub const MAROON: Color

Source

pub const WHITE: Color

Source

pub const SNOW: Color

Source

pub const HONEYDEW: Color

Source

pub const MINTCREAM: Color

Source

pub const AZURE: Color

Source

pub const ALICEBLUE: Color

Source

pub const GHOSTWHITE: Color

Source

pub const WHITESMOKE: Color

Source

pub const SEASHELL: Color

Source

pub const BEIGE: Color

Source

pub const OLDLACE: Color

Source

pub const FLORALWHITE: Color

Source

pub const IVORY: Color

Source

pub const ANTIQUEWHITE: Color

Source

pub const LINEN: Color

Source

pub const LAVENDERBLUSH: Color

Source

pub const MISTYROSE: Color

Source

pub const GAINSBORO: Color

Source

pub const LIGHTGRAY: Color

Source

pub const SILVER: Color

Source

pub const DARKGRAY: Color

Source

pub const GRAY: Color

Source

pub const DIMGRAY: Color

Source

pub const LIGHTSLATEGRAY: Color

Source

pub const SLATEGRAY: Color

Source

pub const DARKSLATEGRAY: Color

Source

pub const BLACK: Color

Source

pub const BLANK: Color

Source

pub const RAYWHITE: Color

Trait Implementations§

Source§

impl CSSPalette for Color

Source§

const ALICEBLUE: Color = _

#f0f8ffff
Source§

const ANTIQUEWHITE: Color = _

#faebd7ff
Source§

const AQUA: Color = _

#00ffffff
Source§

const AQUAMARINE: Color = _

#7fffd4ff
Source§

const AZURE: Color = _

#f0ffffff
Source§

const BEIGE: Color = _

#f5f5dcff
Source§

const BISQUE: Color = _

#ffe4c4ff
Source§

const BLACK: Color = _

#000000ff
Source§

const BLANCHEDALMOND: Color = _

#ffebcdff
Source§

const BLUE: Color = _

#0000ffff
Source§

const BLUEVIOLET: Color = _

#8a2be2ff
Source§

const BROWN: Color = _

#a52a2aff
Source§

const BURLYWOOD: Color = _

#deb887ff
Source§

const CADETBLUE: Color = _

#5f9ea0ff
Source§

const CHARTREUSE: Color = _

#7fff00ff
Source§

const CHOCOLATE: Color = _

#d2691eff
Source§

const CORAL: Color = _

#ff7f50ff
Source§

const CORNFLOWERBLUE: Color = _

#6495edff
Source§

const CORNSILK: Color = _

#fff8dcff
Source§

const CRIMSON: Color = _

#dc143cff
Source§

const CYAN: Color = Self::AQUA

#00ffffff
Source§

const DARKBLUE: Color = _

#00008bff
Source§

const DARKCYAN: Color = _

#008b8bff
Source§

const DARKGOLDENROD: Color = _

#b8860bff
Source§

const DARKGRAY: Color = _

#a9a9a9ff
Source§

const DARKGREEN: Color = _

#006400ff
Source§

const DARKGREY: Color = _

#a9a9a9ff
Source§

const DARKKHAKI: Color = _

#bdb76bff
Source§

const DARKMAGENTA: Color = _

#8b008bff
Source§

const DARKOLIVEGREEN: Color = _

#556b2fff
Source§

const DARKORANGE: Color = _

#ff8c00ff
Source§

const DARKORCHID: Color = _

#9932ccff
Source§

const DARKRED: Color = _

#8b0000ff
Source§

const DARKSALMON: Color = _

#e9967aff
Source§

const DARKSEAGREEN: Color = _

#8fbc8fff
Source§

const DARKSLATEBLUE: Color = _

#483d8bff
Source§

const DARKSLATEGRAY: Color = _

#2f4f4fff
Source§

const DARKSLATEGREY: Color = _

#2f4f4fff
Source§

const DARKTURQUOISE: Color = _

#00ced1ff
Source§

const DARKVIOLET: Color = _

#9400d3ff
Source§

const DEEPPINK: Color = _

#ff1493ff
Source§

const DEEPSKYBLUE: Color = _

#00bfffff
Source§

const DIMGRAY: Color = _

#696969ff
Source§

const DIMGREY: Color = _

#696969ff
Source§

const DODGERBLUE: Color = _

#1e90ffff
Source§

const FIREBRICK: Color = _

#b22222ff
Source§

const FLORALWHITE: Color = _

#fffaf0ff
Source§

const FORESTGREEN: Color = _

#228b22ff
Source§

const FUCHSIA: Color = _

#ff00ffff
Source§

const GAINSBORO: Color = _

#dcdcdcff
Source§

const GHOSTWHITE: Color = _

#f8f8ffff
Source§

const GOLD: Color = _

#ffd700ff
Source§

const GOLDENROD: Color = _

#daa520ff
Source§

const GRAY: Color = _

#808080ff
Source§

const GREEN: Color = _

#008000ff
Source§

const GREENYELLOW: Color = _

#adff2fff
Source§

const GREY: Color = Self::GRAY

#808080ff
Source§

const HONEYDEW: Color = _

#f0fff0ff
Source§

const HOTPINK: Color = _

#ff69b4ff
Source§

const INDIANRED: Color = _

#cd5c5cff
Source§

const INDIGO: Color = _

#4b0082ff
Source§

const IVORY: Color = _

#fffff0ff
Source§

const KHAKI: Color = _

#f0e68cff
Source§

const LAVENDER: Color = _

#e6e6faff
Source§

const LAVENDERBLUSH: Color = _

#fff0f5ff
Source§

const LAWNGREEN: Color = _

#7cfc00ff
Source§

const LEMONCHIFFON: Color = _

#fffacdff
Source§

const LIGHTBLUE: Color = _

#add8e6ff
Source§

const LIGHTCORAL: Color = _

#f08080ff
Source§

const LIGHTCYAN: Color = _

#e0ffffff
Source§

const LIGHTGOLDENRODYELLOW: Color = _

#fafad2ff
Source§

const LIGHTGRAY: Color = _

#d3d3d3ff
Source§

const LIGHTGREEN: Color = _

#90ee90ff
Source§

const LIGHTGREY: Color = _

#d3d3d3ff
Source§

const LIGHTPINK: Color = _

#ffb6c1ff
Source§

const LIGHTSALMON: Color = _

#ffa07aff
Source§

const LIGHTSEAGREEN: Color = _

#20b2aaff
Source§

const LIGHTSKYBLUE: Color = _

#87cefaff
Source§

const LIGHTSLATEGRAY: Color = _

#778899ff
Source§

const LIGHTSLATEGREY: Color = _

#778899ff
Source§

const LIGHTSTEELBLUE: Color = _

#b0c4deff
Source§

const LIGHTYELLOW: Color = _

#ffffe0ff
Source§

const LIME: Color = _

#00ff00ff
Source§

const LIMEGREEN: Color = _

#32cd32ff
Source§

const LINEN: Color = _

#faf0e6ff
Source§

const MAGENTA: Color = Self::FUCHSIA

#ff00ffff
Source§

const MAROON: Color = _

#800000ff
Source§

const MEDIUMAQUAMARINE: Color = _

#66cdaaff
Source§

const MEDIUMBLUE: Color = _

#0000cdff
Source§

const MEDIUMORCHID: Color = _

#ba55d3ff
Source§

const MEDIUMPURPLE: Color = _

#9370dbff
Source§

const MEDIUMSEAGREEN: Color = _

#3cb371ff
Source§

const MEDIUMSLATEBLUE: Color = _

#7b68eeff
Source§

const MEDIUMSPRINGGREEN: Color = _

#00fa9aff
Source§

const MEDIUMTURQUOISE: Color = _

#48d1ccff
Source§

const MEDIUMVIOLETRED: Color = _

#c71585ff
Source§

const MIDNIGHTBLUE: Color = _

#191970ff
Source§

const MINTCREAM: Color = _

#f5fffaff
Source§

const MISTYROSE: Color = _

#ffe4e1ff
Source§

const MOCCASIN: Color = _

#ffe4b5ff
Source§

const NAVAJOWHITE: Color = _

#ffdeadff
Source§

const NAVY: Color = _

#000080ff
Source§

const OLDLACE: Color = _

#fdf5e6ff
Source§

const OLIVE: Color = _

#808000ff
Source§

const OLIVEDRAB: Color = _

#6b8e23ff
Source§

const ORANGE: Color = _

#ffa500ff
Source§

const ORANGERED: Color = _

#ff4500ff
Source§

const ORCHID: Color = _

#da70d6ff
Source§

const PALEGOLDENROD: Color = _

#eee8aaff
Source§

const PALEGREEN: Color = _

#98fb98ff
Source§

const PALETURQUOISE: Color = _

#afeeeeff
Source§

const PALEVIOLETRED: Color = _

#db7093ff
Source§

const PAPAYAWHIP: Color = _

#ffefd5ff
Source§

const PEACHPUFF: Color = _

#ffdab9ff
Source§

const PERU: Color = _

#cd853fff
Source§

const PINK: Color = _

#ffc0cbff
Source§

const PLUM: Color = _

#dda0ddff
Source§

const POWDERBLUE: Color = _

#b0e0e6ff
Source§

const PURPLE: Color = _

#800080ff
Source§

const REBECCAPURPLE: Color = _

#663399ff
Source§

const RED: Color = _

#ff0000ff
Source§

const ROSYBROWN: Color = _

#bc8f8fff
Source§

const ROYALBLUE: Color = _

#4169e1ff
Source§

const SADDLEBROWN: Color = _

#8b4513ff
Source§

const SALMON: Color = _

#fa8072ff
Source§

const SANDYBROWN: Color = _

#f4a460ff
Source§

const SEAGREEN: Color = _

#2e8b57ff
Source§

const SEASHELL: Color = _

#fff5eeff
Source§

const SIENNA: Color = _

#a0522dff
Source§

const SILVER: Color = _

#c0c0c0ff
Source§

const SKYBLUE: Color = _

#87ceebff
Source§

const SLATEBLUE: Color = _

#6a5acdff
Source§

const SLATEGRAY: Color = _

#708090ff
Source§

const SLATEGREY: Color = _

#708090ff
Source§

const SNOW: Color = _

#fffafaff
Source§

const SPRINGGREEN: Color = _

#00ff7fff
Source§

const STEELBLUE: Color = _

#4682b4ff
Source§

const TAN: Color = _

#d2b48cff
Source§

const TEAL: Color = _

#008080ff
Source§

const THISTLE: Color = _

#d8bfd8ff
Source§

const TRANSPARENT: Color = _

#00000000
Source§

const TOMATO: Color = _

#ff6347ff
Source§

const TURQUOISE: Color = _

#40e0d0ff
Source§

const VIOLET: Color = _

#ee82eeff
Source§

const WHEAT: Color = _

#f5deb3ff
Source§

const WHITE: Color = _

#ffffffff
Source§

const WHITESMOKE: Color = _

#f5f5f5ff
Source§

const YELLOW: Color = _

#ffff00ff
Source§

const YELLOWGREEN: Color = _

#9acd32ff
Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Color

Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Color

Returns the “default value” for a type. Read more
Source§

impl Eq for Color

Source§

impl From<&Color> for Color

Source§

fn from(v: &Color) -> Self

Converts to this type from the input type.
Source§

impl From<(u8, u8, u8, u8)> for Color

Source§

fn from(col: (u8, u8, u8, u8)) -> Color

Converts to this type from the input type.
Source§

impl From<Color> for Vector4

Source§

fn from(v: Color) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Color

NOTE(IOI_XD): We manually implement PartialEq as of 5.5 to use Raylib’s function. It’s very unlikely it will ever change or do anything different, but in the ultra rare case that it does, we want to mimic Raylib’s behavior.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RaylibPalette for Color

Source§

const LIGHTGRAY: Color = _

Light Gray
Source§

const GRAY: Color = _

Gray
Source§

const DARKGRAY: Color = _

Dark Gray
Source§

const YELLOW: Color = _

Yellow
Source§

const GOLD: Color = _

Gold
Source§

const ORANGE: Color = _

Orange
Source§

const PINK: Color = _

Pink
Source§

const RED: Color = _

Red
Source§

const MAROON: Color = _

Maroon
Source§

const GREEN: Color = _

Green
Source§

const LIME: Color = _

Lime
Source§

const DARKGREEN: Color = _

Dark Green
Source§

const SKYBLUE: Color = _

Sky Blue
Source§

const BLUE: Color = _

Blue
Source§

const DARKBLUE: Color = _

Dark Blue
Source§

const PURPLE: Color = _

Purple
Source§

const VIOLET: Color = _

Violet
Source§

const DARKPURPLE: Color = _

Dark Purple
Source§

const BEIGE: Color = _

Beige
Source§

const BROWN: Color = _

Brown
Source§

const DARKBROWN: Color = _

Dark Brown
Source§

const WHITE: Color = _

White
Source§

const BLACK: Color = _

Black
Source§

const BLANK: Color = _

Blank (Transparent)
Source§

const MAGENTA: Color = _

Magenta
Source§

const RAYWHITE: Color = _

My own White (raylib logo)

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.