dotfiles/scripts/colortest.awk

99 lines
2.1 KiB
Awk
Raw Normal View History

2019-08-25 14:15:59 +00:00
#!/usr/bin/awk -f
BEGIN {
print "";
test_standard_colors();
print "";
test_base16_colorscheme();
print "";
test_6x6x6_cube();
print "";
test_grayscale();
print "";
test_true_color();
print "";
}
function print_color(color) {
printf "\033[48;5;%sm \033[0m", color
}
function test_standard_colors() {
print "16 standard colors:";
for (color = 0; color < 16; color += 1) print_color(color);
print "";
}
function test_base16_colorscheme() {
print "base16 colorscheme:";
split("0 18 19 8 20 7 21 15 1 16 3 2 6 4 5 17", colors, " ");
for (i = 1; i <= length(colors); i++) print_color(colors[i]);
print "";
}
function test_6x6x6_cube() {
print "6x6x6 cube (216 colors):";
block_grid_w = 3;
block_grid_h = 2;
for (block_y = 0; block_y < block_grid_h; block_y++) {
for (row = 0; row < 6; row++) {
for (block_x = 0; block_x < block_grid_w; block_x++) {
for (col = 0; col < 6; col++) {
print_color(16 + col + 6*row + 6*6*block_x + block_grid_w*6*6*block_y);
}
}
print "";
}
}
}
function test_grayscale() {
print "grayscale from black to white in 24 steps:";
for (color = 0; color < 24; color += 1) {
print_color(16 + 6*6*6 + color)
}
print "";
}
function test_true_color() {
print "24-bit true color test:"
colors_count = 360;
for (h = 0; h < colors_count; h++) {
2019-08-26 12:29:52 +00:00
hsv2rgb(h / colors_count, 1, 1, rgb);
2019-08-25 14:15:59 +00:00
for (i = 0; i < 3; i++) rgb[i] = int(rgb[i] * 255);
r = rgb[0];
g = rgb[1];
b = rgb[2];
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf " \033[0m";
}
print "";
}
2019-08-26 12:29:52 +00:00
function hsv2rgb(h, s, v, rgb) {
2019-08-25 14:15:59 +00:00
if (s == 0) {
2019-08-26 12:29:52 +00:00
r = g = b = v;
2019-08-25 14:15:59 +00:00
} else {
h *= 6;
i = int(h);
f = h - i;
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
if (i == 0) {
2019-08-26 12:29:52 +00:00
r = v; g = t; b = p;
2019-08-25 14:15:59 +00:00
} else if (i == 1) {
2019-08-26 12:29:52 +00:00
r = q; g = v; b = p;
2019-08-25 14:15:59 +00:00
} else if (i == 2) {
2019-08-26 12:29:52 +00:00
r = p; g = v; b = t;
2019-08-25 14:15:59 +00:00
} else if (i == 3) {
2019-08-26 12:29:52 +00:00
r = p; g = q; b = v;
2019-08-25 14:15:59 +00:00
} else if (i == 4) {
2019-08-26 12:29:52 +00:00
r = t; g = p; b = v;
2019-08-25 14:15:59 +00:00
} else if (i == 5) {
2019-08-26 12:29:52 +00:00
r = v; g = p; b = q;
2019-08-25 14:15:59 +00:00
}
}
2019-08-26 12:29:52 +00:00
rgb[0] = r; rgb[1] = g; rgb[2] = b;
2019-08-25 14:15:59 +00:00
}