From d6abc4512bee85b47068701c70f4fb60fbc5543a Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 17 Jan 2024 18:17:56 +0100 Subject: [PATCH] Add truecolor demo --- progress.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/progress.cpp b/progress.cpp index 8ca6824..ceceb44 100644 --- a/progress.cpp +++ b/progress.cpp @@ -1,6 +1,5 @@ #include #include -#include #include void show_rows_cols(const sc::term& t) { @@ -36,7 +35,7 @@ void show_hue_bar(int top) { } r = 0; // green -> cyan - while (b < 6) { + while (b < top) { std::cerr << sc::io::rgbb(r, g, b++) << ' '; } b = top; @@ -117,6 +116,53 @@ void show_words() { std::cout << std::endl; } +void show_truecolor(const sc::term& t) { + const char* lhb = u8"\u2584"; // lower half block + int inc = 6.0 * t.cols() / 256.0; + if (inc == 0) inc = 1; + for (int s = 16; s < 224; s += 32) { + int r = s; + int g = 0; + int b = 0; + // red -> yellow + while (g <= s) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(r, 16 + g, b) << lhb; + g += inc; + } + g = s; + // yellow -> green + while (r >= 0) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(16 + r, g, b) << lhb; + r -= inc; + } + r = 0; + // green -> cyan + while (b < s) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(r, g, 16 + b) << lhb; + b += inc; + } + b = s; + // cyan -> blue + while (g >= 0) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(r, 16 + g, b) << lhb; + g -= inc; + } + g = 0; + // blue -> magenta + while (r <= s) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(16 + r, g, b) << lhb; + r += inc; + } + r = s; + // magenta -> red + while (b >= 0) { + std::cerr << sc::io::truecolorb(r, g, b) << sc::io::truecolorf(r, g, 16 + b) << lhb; + b -= inc; + } + std::cerr << sc::io::reset << std::endl; + } +} + int main() { try { sc::term term {STDERR_FILENO}; @@ -124,6 +170,7 @@ int main() { show_grayscale_bar(); show_hue_bars(); show_words(); + show_truecolor(term); show_progress(term); } catch (const std::exception& ex) { std::cerr << sc::io::reset << ex.what() << std::endl;