From f98f768869eac86701bd7291c966df46fd6df97d Mon Sep 17 00:00:00 2001 From: turret Date: Thu, 29 Jun 2023 17:00:38 -0500 Subject: donut: add cli arguments --- donut.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'donut.c') diff --git a/donut.c b/donut.c index 250d0ce..b136c36 100644 --- a/donut.c +++ b/donut.c @@ -23,13 +23,15 @@ #include #include #include -#define __USE_MISC #include #include #include #include +char *argv0; +#include "arg.h" + #define BETWEEN(x, min, max) min < x && x< max const float theta_spacing = 0.07; @@ -80,7 +82,32 @@ void drawTorus (float *b, const float *Az, const float *Bz) { free(z); } -int main() { +void usage() { + fprintf(stderr, "usage: %s [-h] [-s scale] [-r speed]\n", argv0); + exit(1); +} + +int main(int argc, char **argv) { + /*#define SCALE 2 + #define ROTATION_SPEED_FACTOR 1*/ + + int SCALE = 2; + int ROTATION_SPEED_FACTOR = 1; + + ARGBEGIN { + case 's': + SCALE = atoi(EARGF(usage())); + break; + case 'r': + ROTATION_SPEED_FACTOR = atoi(EARGF(usage())); + break; + case 'h': + usage(); + break; + default: + break; + } ARGEND + Display *dis = XOpenDisplay((char*)0); int screen = DefaultScreen(dis); unsigned long black = BlackPixel(dis, screen), white = WhitePixel(dis, screen); @@ -137,8 +164,7 @@ int main() { A += (rtime-stime) * (0.04f * ROTATION_SPEED_FACTOR) / (1000/FPS_MAX);// / (1000/FPS_MAX), 0.04f * ROTATION_SPEED_FACTOR); B += (rtime-stime) * (0.02f * ROTATION_SPEED_FACTOR) / (1000/FPS_MAX);// / (1000/FPS_MAX), 0.04f * ROTATION_SPEED_FACTOR); - printf("%.1f %d ", (rtime-stime), 1000/(FPS_MAX)); - printf("fps: %.1f %d \r", 1000/(rtime-stime), FPS_MAX); + printf("fps: %.1f \r", 1000/(rtime-stime)); } } -- cgit v1.2.3