void displayResult(CImgDisplay display, CImg<unsigned char> map_image, Solution solution) { double hue = 0.0; unsigned char color [3] = {0,0,0}; hue_to_rgb(hue, color); CImg<unsigned char> allMoves = map_image; for (int i = 0; i < solution.num_routes; i++) { Point from, to; for (int city = 0; city < solution.routes[i].num_cities - 1; city++) { from = solution.routes[i].cities[city].location; to = solution.routes[i].cities[city+1].location; allMoves.draw_line(from.x,from.y,to.x,to.y,color,1.0); } hue += (1.0/(double)solution.num_routes); hue_to_rgb(hue, color); } display.display(allMoves); while(!display.is_closed())display.wait(); }
inline vec3 hsl_to_rgb(vec3 in) { float v1, v2; vec3 out; if(in.s == 0) { out.r = in.l; out.g = in.l; out.b = in.l; } else { if(in.l < 0.5f) v2 = in.l * (1 + in.s); else v2 = (in.l+in.s) - (in.s*in.l); v1 = 2 * in.l - v2; out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f)); out.g = hue_to_rgb(v1, v2, in.h); out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f)); } return out; }
Hsl::operator Rgb() const { assert(!(h < 0 || h > 1) && !(s < 0 || s > 1) && !(l < 0 || l > 1)); Rgb color{0, 0, 0, a}; if (fabs(s) < 0.000001) { color.r = l; color.g = l; color.b = l; } else { double v2; if (l < 0.5) v2 = l * (1 + s); else v2 = (l + s) - (s * l); double v1 = 2 * l - v2; color.r = hue_to_rgb(v1, v2, h + (1 / 3.0)); color.g = hue_to_rgb(v1, v2, h); color.b = hue_to_rgb(v1, v2, h - (1 / 3.0)); } return color; }
inline void hsl2rgb(double h, double s, double l, double & r, double & g, double & b) { if (!s) { r = g = b = l; } double m2 = (l <= 0.5) ? l * (s + 1.0) : l + s - l * s; double m1 = l * 2.0 - m2; r = hue_to_rgb(m1, m2, h + 1.0/3.0); g = hue_to_rgb(m1, m2, h); b = hue_to_rgb(m1, m2, h - 1.0/3.0); }
void displayResultAnimated(CImgDisplay display, CImg<unsigned char> thisRoute, Solution solution) { double hue = 0.0; unsigned char color [3] = {0,0,0}; unsigned char green [3] = {0,255,0}; unsigned char red [3] = {255,0,0}; hue_to_rgb(hue, color); CImg<unsigned char> cleanMap = thisRoute; CImg<unsigned char> allMoves = thisRoute; for (int i = 0; i < solution.num_routes; i++) { Point from, to; for (int city = 0; city < solution.routes[i].num_cities - 1; city++) { from = solution.routes[i].cities[city].location; to = solution.routes[i].cities[city+1].location; CImg<unsigned char> thisMove = thisRoute; thisRoute.draw_line(from.x,from.y,to.x,to.y,color,1.0); allMoves.draw_line(from.x,from.y,to.x,to.y,color,1.0); thisMove.draw_arrow(from.x,from.y,to.x,to.y,red,1.0); display.display(thisMove); Sleep(10); } display.display(thisRoute); thisRoute = cleanMap; Sleep(250); hue += (1.0/(double)solution.num_routes); hue_to_rgb(hue, color); } display.display(allMoves); //all.display(display); while(!display.is_closed())display.wait(); }
static int hls_to_rgb(int hue, int lum, int sat) { int R, G, B; int Magic1, Magic2; const int RGBMAX = 255; const int HLSMAX = 100; if (sat == 0) { R = G = B = (lum * RGBMAX) / HLSMAX; } else { if (lum <= (HLSMAX / 2)) { Magic2 = (lum * (HLSMAX + sat) + (HLSMAX / 2)) / HLSMAX; } else { Magic2 = lum + sat - ((lum * sat) + (HLSMAX / 2)) / HLSMAX; } Magic1 = 2 * lum - Magic2; R = (hue_to_rgb(Magic1, Magic2, hue + (HLSMAX / 3)) * RGBMAX + (HLSMAX / 2)) / HLSMAX; G = (hue_to_rgb(Magic1, Magic2, hue) * RGBMAX + (HLSMAX / 2)) / HLSMAX; B = (hue_to_rgb(Magic1, Magic2, hue - (HLSMAX / 3)) * RGBMAX + (HLSMAX/2)) / HLSMAX; } return SIXEL_RGB(R, G, B); }