Rewrite true color demo

This commit is contained in:
Bob Polis 2024-01-18 11:11:21 +01:00
parent 8328e3bbb6
commit 204585283c

View File

@ -2,6 +2,7 @@
#include <ctime>
#include <cstdlib>
#include <libscterm.hpp>
#include <libscscreensaver.hpp>
void show_rows_cols(const sc::term& t) {
std::cout << t.rows() << " rows, " << t.cols() << " cols\n";
@ -125,48 +126,20 @@ void show_truecolor(const sc::term& t) {
return;
}
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;
const double sat = 1.0;
for (double bri = 0; bri < 1; bri += 0.2) {
for (double hue = 0; hue < 360; hue += 360.0 / t.cols()) {
HSB hsbb = {hue, sat, bri};
Color bg {hsbb};
RGB rgbb = RGB(bg);
HSB hsbf = {hue, sat, bri + 0.1};
Color fg {hsbf};
RGB rgbf = RGB(fg);
std::cerr << sc::io::truecolorb(rgbb.r * 255, rgbb.g * 255, rgbb.b * 255);
std::cerr << sc::io::truecolorf(rgbf.r * 255, rgbf.g * 255, rgbf.b * 255);
std::cerr << lhb;
}
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;
std::cerr << std::endl;
}
}