Add truecolor demo

This commit is contained in:
Bob Polis 2024-01-17 18:17:56 +01:00
parent ee0ee06108
commit d6abc4512b

View File

@ -1,6 +1,5 @@
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <cmath>
#include <libscterm.hpp> #include <libscterm.hpp>
void show_rows_cols(const sc::term& t) { void show_rows_cols(const sc::term& t) {
@ -36,7 +35,7 @@ void show_hue_bar(int top) {
} }
r = 0; r = 0;
// green -> cyan // green -> cyan
while (b < 6) { while (b < top) {
std::cerr << sc::io::rgbb(r, g, b++) << ' '; std::cerr << sc::io::rgbb(r, g, b++) << ' ';
} }
b = top; b = top;
@ -117,6 +116,53 @@ void show_words() {
std::cout << std::endl; 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() { int main() {
try { try {
sc::term term {STDERR_FILENO}; sc::term term {STDERR_FILENO};
@ -124,6 +170,7 @@ int main() {
show_grayscale_bar(); show_grayscale_bar();
show_hue_bars(); show_hue_bars();
show_words(); show_words();
show_truecolor(term);
show_progress(term); show_progress(term);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
std::cerr << sc::io::reset << ex.what() << std::endl; std::cerr << sc::io::reset << ex.what() << std::endl;