10 #ifndef EMP_COLOR_MAP_H 11 #define EMP_COLOR_MAP_H 18 #include "../base/vector.h" 19 #include "../tools/string_utils.h" 24 using dHueMapKey = std::tuple<int, double, double, int, int>;
25 using dHueMap = std::map<dHueMapKey, emp::vector<std::string> >;
31 std::string
ColorHSL(
double h,
double s,
double l) {
36 ss <<
"hsl(" << h <<
',' << s <<
"%," << l <<
"%)";
46 ss <<
'#' << std::setw(2) << std::setfill(
'0') << std::hex << r
47 << std::setw(2) << std::setfill(
'0') << std::hex << g
48 << std::setw(2) << std::setfill(
'0') << std::hex << b;
53 std::string
ColorRGB(
int r,
int g,
int b,
double a) {
58 ss <<
"rgba(" << r <<
',' << g <<
',' << b <<
',' << a <<
')';
65 GetHueMap(
size_t map_size,
double min_h=0.0,
double max_h=360.0,
int s=100,
int l=50) {
66 dHueMapKey map_key = std::make_tuple(map_size, min_h, max_h, s, l);
72 if (cur_map.
size() != (std::size_t) map_size) {
76 double step_size = (max_h - min_h) / (
double) map_size;
77 for (
size_t i = 0; i < map_size; ++i) {
78 double h = min_h + step_size * i;
88 GetHSLMap(
size_t map_size,
double min_h=0.0,
double max_h=360.0,
89 int min_s=100,
int max_s=100,
90 int min_l=50,
int max_l=50) {
94 double h_step = (max_h - min_h) / (
double) map_size;
95 double s_step = (max_s - min_s) / (
double) map_size;
96 double l_step = (max_l - min_l) / (
double) map_size;
97 for (
size_t i = 0; i < map_size; ++i) {
98 double h = min_h + h_step * i;
99 double s = min_s + s_step * i;
100 double l = min_l + l_step * i;
101 if (h > 360) h -= 360;
102 if (s > 100) s -= 100;
103 if (l > 100) l -= 100;
const emp::vector< std::string > & GetHueMap(size_t map_size, double min_h=0.0, double max_h=360.0, int s=100, int l=50)
Definition: color_map.h:65
size_t size() const
Definition: vector.h:151
void resize(size_t new_size)
Definition: vector.h:161
std::string ColorRGB(int r, int g, int b)
Generate a string to describe a JS color out of RGB values.
Definition: color_map.h:41
If we are in emscripten, make sure to include the header.
Definition: array.h:37
#define emp_assert(...)
Definition: assert.h:199
std::string ColorHSL(double h, double s, double l)
Generate a string to describe a JS color out of HSL values.
Definition: color_map.h:31
emp::vector< std::string > GetHSLMap(size_t map_size, double min_h=0.0, double max_h=360.0, int min_s=100, int max_s=100, int min_l=50, int max_l=50)
Generate a vector of color strings providing ranges of all of hue, satuation and luminosity.
Definition: color_map.h:88