Rename some options

step is now distance, and speed is now wait. This more accurately
describes what they do.
pull/4/head
Martin Tournoij 7 years ago
parent 673fb3377f
commit 7ad971098f
No known key found for this signature in database
GPG Key ID: A6258419189EE585

@ -20,13 +20,13 @@
void usage(char *name); void usage(char *name);
int parse_num(int ch, char *opt, char *name); int parse_num(int ch, char *opt, char *name);
void draw(char *name, int size, int step, int speed, int line_width, char *color_name); void draw(char *name, int size, int distance, int wait, int line_width, char *color_name);
static struct option longopts[] = { static struct option longopts[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"size", required_argument, NULL, 's'}, {"size", required_argument, NULL, 's'},
{"step", required_argument, NULL, 't'}, {"distance", required_argument, NULL, 'd'},
{"speed", required_argument, NULL, 'p'}, {"wait", required_argument, NULL, 'w'},
{"line-width", required_argument, NULL, 'l'}, {"line-width", required_argument, NULL, 'l'},
{"color", required_argument, NULL, 'c'}, {"color", required_argument, NULL, 'c'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
@ -35,16 +35,16 @@ static struct option longopts[] = {
void usage(char *name) { void usage(char *name) {
printf("Usage: %s [-stplc]\n\n", name); printf("Usage: %s [-stplc]\n\n", name);
printf(" -h, --help Show this help.\n"); printf(" -h, --help Show this help.\n");
printf(" -s, --size Size in pixels.\n"); printf(" -s, --size Maximum size the circle will grow to in pixels.\n");
printf(" -t, --step ???.\n"); printf(" -d, --distance Distance between the circles in pixels.\n");
printf(" -p, --speed Animation speed.\n");
printf(" -l, --line-width Width of the lines in pixels.\n"); printf(" -l, --line-width Width of the lines in pixels.\n");
printf(" -w, --wait Time to wait before drawing the next circle in microseconds.\n");
printf(" -c, --color Color; can either be an X11 color name or RGB as hex (i.e. #ff0055).\n"); printf(" -c, --color Color; can either be an X11 color name or RGB as hex (i.e. #ff0055).\n");
printf("\n"); printf("\n");
printf("The defaults:\n"); printf("The defaults:\n");
printf(" %s --size 220 --step 40 --speed 400 --line-width 2 --color black\n", name); printf(" %s --size 220 --distance 40 --wait 400 --line-width 2 --color black\n", name);
printf("Draw a circle\n"); printf("Draw a circle\n");
printf(" %s --size 100 --step 1 --speed 20 --line-width 1 --color black\n", name); printf(" %s --size 100 --distance 1 --wait 20 --line-width 1 --color black\n", name);
printf("\n"); printf("\n");
} }
@ -64,22 +64,22 @@ int parse_num(int ch, char *opt, char *name) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Parse options // Parse options
int size = 220; int size = 220;
int step = 40; int distance = 40;
int speed = 400; int wait = 400;
int line_width = 2; int line_width = 2;
char color_name[64] = "black"; char color_name[64] = "black";
int ch; int ch;
while ((ch = getopt_long(argc, argv, "hs:t:p:l:c:r:", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "hs:d:w:l:c:r:", longopts, NULL)) != -1)
switch (ch) { switch (ch) {
case 's': case 's':
size = parse_num(ch, optarg, argv[0]); size = parse_num(ch, optarg, argv[0]);
break; break;
case 't': case 'd':
step = parse_num(ch, optarg, argv[0]); distance = parse_num(ch, optarg, argv[0]);
break; break;
case 'p': case 'w':
speed = parse_num(ch, optarg, argv[0]); wait = parse_num(ch, optarg, argv[0]);
break; break;
case 'l': case 'l':
line_width = parse_num(ch, optarg, argv[0]); line_width = parse_num(ch, optarg, argv[0]);
@ -91,17 +91,16 @@ int main(int argc, char* argv[]) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
default: default:
fprintf(stderr, "%s: Unknown option: %c\n", argv[0], (char) ch);
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
draw(argv[0], size, step, speed, line_width, color_name); draw(argv[0], size, distance, wait, line_width, color_name);
} }
void draw(char *name, int size, int step, int speed, int line_width, char *color_name) { void draw(char *name, int size, int distance, int wait, int line_width, char *color_name) {
// Setup display and such // Setup display and such
char *display_name = getenv("DISPLAY"); char *display_name = getenv("DISPLAY");
if (!display_name) { if (!display_name) {
@ -208,14 +207,14 @@ void draw(char *name, int size, int step, int speed, int line_width, char *color
// Draw the circles // Draw the circles
int i = 1; int i = 1;
for (i=1; i<=size; i+=step) { for (i=1; i<=size; i+=distance) {
XDrawArc(display, window, gc, XDrawArc(display, window, gc,
size/2 - i/2, size/2 - i/2, // x, y position size/2 - i/2, size/2 - i/2, // x, y position
i, i, // Size i, i, // Size
0, 360 * 64); // Make it a full circle 0, 360 * 64); // Make it a full circle
XSync(display, False); XSync(display, False);
usleep(speed * 100); usleep(wait * 100);
} }
XFreeGC(display, gc); XFreeGC(display, gc);

Loading…
Cancel
Save