truecolor.sh

 1#!/usr/bin/env bash
 2# Copied from: https://unix.stackexchange.com/a/696756
 3# Based on: https://gist.github.com/XVilka/8346728 and https://unix.stackexchange.com/a/404415/395213
 4
 5awk -v term_cols="${width:-$(tput cols || echo 80)}" -v term_lines="${height:-1}" 'BEGIN{
 6    s="/\\";
 7    total_cols=term_cols*term_lines;
 8    for (colnum = 0; colnum<total_cols; colnum++) {
 9        r = 255-(colnum*255/total_cols);
10        g = (colnum*510/total_cols);
11        b = (colnum*255/total_cols);
12        if (g>255) g = 510-g;
13        printf "\033[48;2;%d;%d;%dm", r,g,b;
14        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
15        printf "%s\033[0m", substr(s,colnum%2+1,1);
16        if (colnum%term_cols==term_cols) printf "\n";
17    }
18    printf "\n";
19}'