|
|
|
@ -7,9 +7,10 @@
@@ -7,9 +7,10 @@
|
|
|
|
|
/*
|
|
|
|
|
* Basic Settings |
|
|
|
|
*/ |
|
|
|
|
int rainbow_len = 80; // how many characters long is one full rainbow (360deg)
|
|
|
|
|
int rainbow_len = 90; // how many characters long is one full rainbow (360deg)
|
|
|
|
|
int col_change; // how many degrees between colours in the rainbow
|
|
|
|
|
int col_dist; // how many characters per colour in output
|
|
|
|
|
int frequency = 1; // how many degrees to rotate start point on new line
|
|
|
|
|
|
|
|
|
|
struct colour* colours; // the rainbow
|
|
|
|
|
int num_colours; // the length of the rainbow
|
|
|
|
@ -26,17 +27,30 @@ void print_next_colour(int current) {
@@ -26,17 +27,30 @@ void print_next_colour(int current) {
|
|
|
|
|
int display(FILE *file) { |
|
|
|
|
char c = fgetc(file); |
|
|
|
|
|
|
|
|
|
int start = 0; |
|
|
|
|
int counter = 0; |
|
|
|
|
bool in_escape = false; |
|
|
|
|
while (c != EOF) { |
|
|
|
|
if (c == '\n') { |
|
|
|
|
counter = 0; |
|
|
|
|
counter = (start += frequency); |
|
|
|
|
} |
|
|
|
|
print_next_colour(counter); |
|
|
|
|
printf("%c", c); |
|
|
|
|
if (c == '\033') { |
|
|
|
|
in_escape = true; |
|
|
|
|
} else if (c == 'm' && in_escape) { |
|
|
|
|
in_escape = false; |
|
|
|
|
c = fgetc(file); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!in_escape) { |
|
|
|
|
print_next_colour(counter); |
|
|
|
|
} |
|
|
|
|
putc(c, stdout); |
|
|
|
|
|
|
|
|
|
counter++; |
|
|
|
|
c = fgetc(file); |
|
|
|
|
} |
|
|
|
|
counter++; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,7 +76,7 @@ int generate_rainbow() {
@@ -62,7 +76,7 @@ int generate_rainbow() {
|
|
|
|
|
col_change = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
col_dist = rainbow_len / num_colours; |
|
|
|
|
col_dist = (rainbow_len) / (num_colours); |
|
|
|
|
colours = calloc(num_colours, sizeof(struct colour)); |
|
|
|
|
struct colour c; |
|
|
|
|
c.h = 0; |
|
|
|
@ -80,13 +94,16 @@ int generate_rainbow() {
@@ -80,13 +94,16 @@ int generate_rainbow() {
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
int opt; |
|
|
|
|
int optcount = 0; |
|
|
|
|
while ((opt = getopt(argc, argv, "l:")) != -1) { |
|
|
|
|
while ((opt = getopt(argc, argv, "l:f:")) != -1) { |
|
|
|
|
optcount++; |
|
|
|
|
if (opt == 'l') { |
|
|
|
|
optcount++; |
|
|
|
|
rainbow_len = atoi(optarg); |
|
|
|
|
} else if (opt == 'f') { |
|
|
|
|
optcount++; |
|
|
|
|
frequency = atoi(optarg); |
|
|
|
|
} else { |
|
|
|
|
printf("Usage: colcat -l [rainbow length]"); |
|
|
|
|
printf("Usage: colcat -l [rainbow length] -f [frequency]"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|