Skip to content

Instantly share code, notes, and snippets.

@Nachasic
Created January 24, 2020 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nachasic/10d3a3db863751c4ec4c3d6f3ec5e71e to your computer and use it in GitHub Desktop.
Save Nachasic/10d3a3db863751c4ec4c3d6f3ec5e71e to your computer and use it in GitHub Desktop.
Color macro for raylib in Rust
use raylib::prelude::*;
#[allow(unused_macros)]
macro_rules! color {
(# $color_hex:expr) => {{
let color = i32::from_str_radix(stringify!($color_hex), 16).unwrap();
let b = color % 0x100;
let g = (color - b) / 0x100 % 0x100;
let r = (color - g) / 0x10000;
Color {
r: r as u8,
g: g as u8,
b: b as u8,
a: 255
}
}};
}
#[test]
fn get_color () {
let color_white = color!(#FFFFFF);
let color_black = color!(#000000);
assert_eq!(color_black, Color::BLACK);
assert_eq!(color_white, Color::WHITE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment