1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| /* If possible, display the 256 colours. Only for Linux
*
* with bash
* foreground \33[38;5;${code}m
* background \33[48;5;${code}m
*
* with c
* fg: \e[38;5;codem
* bg: \e[45;5;codem
*
*/
#include <stdio.h>
int main()
{
/* Initialise the main variables
* colour: for the 256 colours (0-255)
* space: to insert space or newline
*/
int colour = 0;
int space = 0;
/* Print the 16 first colours, known as colours system */
printf("System colours:\n")
for( ; colour < 16; colour++) {
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* The 216 colours */
printf("Color cube: 6x6x6\n");
for ( ; colour < 232; colour++, espace++) {
if ((espace%6) == 0) {
printf("\e[0m ");
}
if ((espace%36 == 0)) {
printf("\e[0m\n");
}
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
/* And the grey colours */
printf("Greyscale ramp\n");
for ( ; colour < 256; colour++) {
printf("\e[48;5;%dm ", colour);
}
printf("\e[0m\n\n");
return 0;
} |
Partager