Skip to content

Instantly share code, notes, and snippets.

@tycho

tycho/colortest.pl

Created Sep 26, 2019
Embed
What would you like to do?
color test for console emulators
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $
# first the system ones:
print "System colors:\n";
for ($color = 0; $color < 8; $color++) {
print "\x1b[48;5;${color}m ";
}
print "\x1b[0m\n";
for ($color = 8; $color < 16; $color++) {
print "\x1b[48;5;${color}m ";
}
print "\x1b[0m\n\n";
# now the color cube
print "Color cube, 6x6x6:\n";
for ($green = 0; $green < 6; $green++) {
for ($red = 0; $red < 6; $red++) {
for ($blue = 0; $blue < 6; $blue++) {
$color = 16 + ($red * 36) + ($green * 6) + $blue;
print "\x1b[48;5;${color}m ";
}
print "\x1b[0m ";
}
print "\n";
}
# true color ramp
print "\nTrue color ramp:\n";
for ($colnum = 0; $colnum < 77; $colnum++) {
$r = 255 - ($colnum * 255 / 76);
$g = ($colnum * 510 / 76);
$b = ($colnum * 255 / 76);
if ($g > 255) {
$g = 510 - $g;
}
printf("\x1b[48;2;%d;%d;%dm", $r, $g, $b);
printf("\x1b[38;2;%d;%d;%dm", 255 - $r, 255 - $g, 255 - $b);
if ($colnum % 2 == 0) {
$char = "/";
} else {
$char = "\\";
}
printf("%s\x1b[0m", $char);
}
print "\n\n";
# now the grayscale ramp
print "Grayscale ramp:\n";
for ($color = 232; $color < 256; $color++) {
print "\x1b[48;5;${color}m ";
}
print "\x1b[0m\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment