//! The 16-color EGA palette MRPGI inherits from the original AGI. //! //! Everything in the engine works in palette *indices* (0..=15); we only //! convert to real RGBA at the very last moment, when we hand pixels to the GPU. use macroquad::prelude::Color; /// Standard IBM EGA / CGA 16-color palette, as (R, G, B). pub const EGA: [(u8, u8, u8); 16] = [ (0x00, 0x00, 0x00), // 0 black (0x00, 0x00, 0xAA), // 1 blue (0x00, 0xAA, 0x00), // 2 green (0x00, 0xAA, 0xAA), // 3 cyan (0xAA, 0x00, 0x00), // 4 red (0xAA, 0x00, 0xAA), // 5 magenta (0xAA, 0x55, 0x00), // 6 brown (0xAA, 0xAA, 0xAA), // 7 light gray (0x55, 0x55, 0x55), // 8 dark gray (0x55, 0x55, 0xFF), // 9 light blue (0x55, 0xFF, 0x55), // 10 light green (0x55, 0xFF, 0xFF), // 11 light cyan (0xFF, 0x55, 0x55), // 12 light red (0xFF, 0x55, 0xFF), // 13 light magenta (0xFF, 0xFF, 0x55), // 14 yellow (0xFF, 0xFF, 0xFF), // 15 white ]; /// Raw RGBA bytes for a palette index (for writing straight into an Image). #[inline] pub fn rgba(idx: u8) -> [u8; 4] { let (r, g, b) = EGA[(idx & 0x0F) as usize]; [r, g, b, 255] } /// macroquad `Color` for a palette index (for `draw_*` calls). #[inline] pub fn color(idx: u8) -> Color { let (r, g, b) = EGA[(idx & 0x0F) as usize]; Color::new(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0) }