summaryrefslogtreecommitdiff
path: root/lolcat.c
diff options
context:
space:
mode:
authorEdgar Fouillet <vlc@edgar.fouillet.eu>2019-11-03 21:05:54 +0100
committerjaseg <githubaccount@jaseg.net>2019-11-10 16:36:39 +0100
commitd92c9b91f7b24e52262923e564cd3c32d408814e (patch)
treead4603b77e99907717def0d5cdd96b84ed4c7b81 /lolcat.c
parent92831e54d870bf4b538e3603cc45129cb355c022 (diff)
downloadlolcat-d92c9b91f7b24e52262923e564cd3c32d408814e.tar.gz
lolcat-d92c9b91f7b24e52262923e564cd3c32d408814e.tar.bz2
lolcat-d92c9b91f7b24e52262923e564cd3c32d408814e.zip
Add random option
Diffstat (limited to 'lolcat.c')
-rw-r--r--lolcat.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lolcat.c b/lolcat.c
index 5c62baf..8e209b2 100644
--- a/lolcat.c
+++ b/lolcat.c
@@ -37,6 +37,7 @@ static char helpstr[] = "\n"
" -v <d>: Vertical rainbow frequency (default: 0.1)\n"
" -f: Force color even when stdout is not a tty\n"
" -l: Use encoding from system locale instead of assuming UTF-8\n"
+ " -r: Random colors\n"
" --version: Print version and exit\n"
" --help: Show this message\n"
"\n"
@@ -94,6 +95,7 @@ int main(int argc, char** argv)
wint_t c;
int colors = isatty(STDOUT_FILENO);
int force_locale = 1;
+ int random = 0;
double freq_h = 0.23, freq_v = 0.1;
struct timeval tv;
@@ -122,6 +124,8 @@ int main(int argc, char** argv)
colors = 1;
} else if (!strcmp(argv[i], "-l")) {
force_locale = 0;
+ } else if (!strcmp(argv[i], "-r")) {
+ random = 1;
} else if (!strcmp(argv[i], "--version")) {
version();
} else {
@@ -131,6 +135,11 @@ int main(int argc, char** argv)
}
}
+ int rand_offset = 0;
+ if (random) {
+ srand(time(NULL));
+ rand_offset = rand();
+ }
char** inputs = argv + i;
char** inputs_end = argv + argc;
if (inputs == inputs_end) {
@@ -178,7 +187,7 @@ int main(int argc, char** argv)
} else {
int ncc = offx * ARRAY_SIZE(codes) + (int)((i += wcwidth(c)) * freq_h + l * freq_v);
if (cc != ncc)
- wprintf(L"\033[38;5;%hhum", codes[(cc = ncc) % ARRAY_SIZE(codes)]);
+ wprintf(L"\033[38;5;%hhum", codes[(rand_offset + (cc = ncc)) % ARRAY_SIZE(codes)]);
}
}
}
@@ -186,7 +195,7 @@ int main(int argc, char** argv)
putwchar(c);
if (escape_state == 2)
- wprintf(L"\033[38;5;%hhum", codes[cc % ARRAY_SIZE(codes)]);
+ wprintf(L"\033[38;5;%hhum", codes[(rand_offset + cc) % ARRAY_SIZE(codes)]);
}
if (colors)