Skip to content

Instantly share code, notes, and snippets.

@a-a
Created August 1, 2018 10:24
Show Gist options
  • Save a-a/6fc6b382ff8d4682d1ff23e275719ada to your computer and use it in GitHub Desktop.
Save a-a/6fc6b382ff8d4682d1ff23e275719ada to your computer and use it in GitHub Desktop.
:(
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
const char* RESET = "\x1B[0m";
const char *COLORS[] = { "\x1B[31m", "\x1B[32m", "\x1B[33m", "\x1B[34m", "\x1B[35m", "\x1B[36m" };
DWORD dwOldMode, dwMode;
HANDLE hStdout;
int main() {
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if(!GetConsoleMode(hStdout, &dwOldMode)) {
return 1;
}
dwMode = dwOldMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if(!SetConsoleMode(hStdout, dwMode)){
return 2;
}
srand(time(NULL));
for(;;) {
int colorIdx = rand() % 6;
printf("%s:(%s", COLORS[colorIdx], RESET);
int spacing = rand() % 10;
for(int i = 0; i < spacing; i++) {
printf(" ");
}
fflush(stdout);
usleep(5000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment