Created
February 25, 2024 23:58
-
-
Save metalefty/99b688ec67e5debb4d662fb6a12fc069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compile with | |
* gcc -Wall -o paint paint.c | |
* | |
* Run with | |
* ./paint $(tput lines) $(tput cols) | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
char rand_char() { | |
return ' ' + rand() % 27; | |
} | |
int rand_fg_color() { | |
return 30 + rand() % 8; | |
} | |
int rand_bg_color() { | |
return 40 + rand() % 8; | |
} | |
int main(int argc, char **argv) { | |
if (argc != 3) { | |
printf("Usage: %s rows cols\n", argv[0]); | |
return 1; | |
} | |
int rows = atoi(argv[1]); | |
int cols = atoi(argv[2]); | |
srand(time(NULL)); | |
for (int i = 0; i < rows; i++) { | |
for (int j = 0; j < cols; j++) { | |
printf("\033[%d;%dm%c\033[0m", rand_fg_color(), rand_bg_color(), rand_char()); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment