Created
November 7, 2019 16:47
-
-
Save stefanofiorentino/aa0e76dadfd1fdb0cb0267c28363e306 to your computer and use it in GitHub Desktop.
c/c++ function to translate RGB bash terminal colot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on https://gist.github.com/mhulse/b11e568260fb8c3aa2a8 | |
void UserLedManager::print_terminal_background_color(const int &r, const int &g, const int &b) const | |
{ | |
auto r_weight = r < 75 ? 0 : (r - 35) / 40; | |
auto g_weight = g < 75 ? 0 : (g - 35) / 40; | |
auto b_weight = b < 75 ? 0 : (b - 35) / 40; | |
int status = (r_weight * 6 * 6 + g_weight * 6 + b_weight + 16); | |
fprintf(stdout, "\e[48;5;%dm %3d \e[0m", status, status); | |
fflush(stdout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment