mcolor - Maxine's Mean Color Library
mcolor is a C++20 library designed to provide an efficient suite for color management. Ideal for use in games, console applications, UI, and so forth.
Color as a Class
At its heart, mcolor defines fundamental color structures for clear and concise representation:
Color3
: Represents an RGB color with 8-bit unsigned integer components (uint8_t r, g, b).Color4
: Extends Color3 to include an alpha channel (uint8_t r, g, b, a).
These core types are complemented by a full range of conversion structs, enabling seamless transitions between various color models:
HSV
,HSVA
: Hue, Saturation, Value (with Alpha)RGB
,RGBA
: Red, Green, Blue (with Alpha) using u8 components.RGBf
,RGBAf
: Red, Green, Blue (with Alpha) using float components.LCH
,LCHA
: Lightness, Chroma, Hue (with Alpha)CMYK
: Cyan, Magenta, Yellow, Key (Black)
The library also includes organized Color Palettes within dedicated namespaces:
Colors::Primary
, or justColors
,- Colors::Reds
- Colors::Oranges
- Colors::Yellows
- Colors::Greens
- Colors::Cyans
- Colors::Blues
- Colors::Purples
- Colors::Pinks
- Colors::Whites
- Colors::Grays
- Colors::Browns
offering a rich set of predefined swatches for immediate use.
Additionally, we have worked to implement Ansi Escape Codes, console-output utilities, and cross-platform abstraction so that it works the same on Windows and Linux.
Usage
Integrating mcolor into your project is straightforward. Here's a quick sample:
int main() {
#ifdef WIN32
mcolor::windowsSaneify();
#endif
mcolor::printBuiltinColorList();
mcolor::printAnsiColorTable();
mcolor::printRGBConsoleTest();
for (float i = 0; i < 360; i+=10.f)
{
HSVA hsva {i, 1.f, 1.f};
Color4 c = Color4(hsva);
std::cout << std::format("{}hue:{} rgb: {},{},{} hex: {}", c.ToEscapeCode(), i, c.r, c.g, c.b, c.ToHex()) << std::endl;
}
return 0;
}
Acknowledgements
This library was created by maxine
, and is currently maintained by Josh O'Leary.
Contributing
Pull requests and issues are always welcome! You know what to do!
License
This work is expressly dedicated to the Public Domain under the Unlicense.