Showing multiplt hue bars

This commit is contained in:
Bob Polis 2021-12-12 14:24:30 +01:00
parent 1d085067a8
commit eda32848e8

View File

@ -1,18 +1,93 @@
#include <iostream> #include <iostream>
#include <libscterm.hpp>
#include <ctime> #include <ctime>
#include <cmath>
#include <libscterm.hpp>
int main() { void show_rows_cols(const sc::term& t) {
sc::term term {STDERR_FILENO}; std::cout << t.rows() << " rows, " << t.cols() << " cols\n";
std::cout << term.rows() << " rows, " << term.cols() << " cols\n"; }
sleep(1);
void show_progress(const sc::term& t) {
struct timespec tm; struct timespec tm;
tm.tv_nsec = 20000000; tm.tv_nsec = 20000000;
tm.tv_sec = 0; tm.tv_sec = 0;
sc::cursor_hider ch {STDERR_FILENO}; sc::cursor_hider ch {STDERR_FILENO};
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
term.progress(i, 1000); t.progress(i, 1000);
nanosleep(&tm, nullptr); nanosleep(&tm, nullptr);
} }
std::cerr << std::endl; std::cerr << std::endl;
} }
void show_hue_bar(const sc::term& t, int top) {
int r = top;
int g = 0;
int b = 0;
// red -> yellow
while (g <= top) {
t.rgbb(r, g++, b);
std::cerr << ' ';
}
g = top;
// yellow -> green
while (r >= 0) {
t.rgbb(r--, g, b);
std::cerr << ' ';
}
r = 0;
// green -> cyan
while (b < 6) {
t.rgbb(r, g, b++);
std::cerr << ' ';
}
b = top;
// cyan -> blue
while (g >= 0) {
t.rgbb(r, g--, b);
std::cerr << ' ';
}
g = 0;
// blue -> magenta
while (r <= top) {
t.rgbb(r++, g, b);
std::cerr << ' ';
}
r = top;
// magenta -> red
while (b >= 0) {
t.rgbb(r, g, b--);
std::cerr << ' ';
}
t.reset();
std::cerr << std::endl;
}
void show_hue_bars(const sc::term& t) {
for (int top = 1; top < 6; ++top) {
show_hue_bar(t, top);
}
}
void show_grayscale_bar(const sc::term& t) {
for (int i = 0; i < 23; ++i) {
t.grayb(i);
std::cerr << ' ';
}
t.reset();
std::cerr << std::endl;
}
int main() {
sc::term term {STDERR_FILENO};
try {
show_rows_cols(term);
show_grayscale_bar(term);
show_hue_bars(term);
show_progress(term);
} catch (const std::exception& ex) {
term.reset();
std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}