-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXkcdColors.cpp
More file actions
49 lines (41 loc) · 1.3 KB
/
XkcdColors.cpp
File metadata and controls
49 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Simple program showing how to use XkcdColors.h package
* Output should be:
*
* baby puke green: #b6c406
* eggshell
* red: ff
* green: ff
* blue: d4
* midnight blue: #020035
* Could not find fuschia
*/
#include <iomanip>
#include <iostream>
#include "XkcdColors.h"
namespace xkcd = xkcdColors;
int main()
{
auto intColor = xkcd::GetColorInt("baby puke green");
if (intColor)
std::cout << "baby puke green: #" << std::hex << *intColor << "\n";
auto rgbColor = xkcd::GetColorRgb("eggshell");
if (rgbColor)
{
xkcd::RGBs& rgb = *rgbColor;
std::cout << "eggshell" << "\n";
// These need to be casted, otherwise C++ will output the characters, not the numeric values.
std::cout << " red: " << static_cast<int>(rgb.r) << "\n";
std::cout << " green: " << static_cast<int>(rgb.g) << "\n";
std::cout << " blue: " << static_cast<int>(rgb.b) << "\n";
}
auto hexColor = xkcd::GetColorHexString("midnight blue");
if (hexColor)
std::cout << "midnight blue: " << *hexColor << "\n";
auto fuschiaString = xkcd::GetColorHexString("fuschia"); // Common fuchsia misspelling
if (!fuschiaString)
std::cout << "Could not find fuschia\n";
else
std::cout << *fuschiaString << "\n";
return 0;
}