-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboilerplate.c
72 lines (63 loc) · 1.42 KB
/
boilerplate.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "boilerplate.h"
// progress bar stuff //
#define NUM_PROGRESS_BARS 40
#define PRINT_PERIOD 1
#define FULL '='
#define ARROW '>'
#define EMPTY '-'
#define GO_TO_LINE_START "[0`"
#define OUT_SIZE 64
int pathi = -1, palettei = -1;
void printProgress(int curr, int total){
double precentage = (double)curr/total;
int numFull = precentage * NUM_PROGRESS_BARS;
printf("%s", GO_TO_LINE_START);
for(int i = 0; i < NUM_PROGRESS_BARS; i++){
putc(i <= numFull ? (i == numFull ? ARROW : FULL) : EMPTY, stdout);
}
printf("|%3d%%", (int)(precentage * 100));
fflush(stdout);
}
int outputImage(gdImage *img, const char *path, int i, int total){
if(!img || !path)
return 0;
char out[OUT_SIZE] = {0};
if(total == 1){
printProgress(total, total);
sprintf(out, "%s.png", path);
gdImageFile(img, out);
return total;
}
if(i % PRINT_PERIOD == 0)
printProgress(i, total);
sprintf(out, "%s%d.png", path, i);
gdImageFile(img, out);
return i;
}
void parseArgs(int argc, const char *argv[]){
for(int i = 0; i < argc; i++){
if(argv[i][0] != '-')
continue;
switch(argv[i][1]){
case 'p':
case 'P':
palettei = i + 1;
break;
case 'o':
case 'O':
pathi = i + 1;
break;
case 'h':
case 'H':
printHelp();
exit(0);
break;
}
}
}
void printHelp(){
puts("sapphire: a smooth life visualizer");
for(int i = 0; i < NUM_ARGS; i++){
printf("%s : %s\n", help[i][0], help[i][1]);
}
}