int main(int argc, char** argv) { srand(time(NULL)); double cx = -0.45; double cy = 0.0; double rw = 2 * 1.6; double rh = 2; if (argc < 7) { print_usage(argv[0]); return 1; } int state = 0; int r_iter = (int) convert_to_ll(argv[1], &state); long long r_point = convert_to_ll(argv[2], &state); int g_iter = (int) convert_to_ll(argv[3], &state); long long g_point = convert_to_ll(argv[4], &state); int b_iter = (int) convert_to_ll(argv[5], &state); long long b_point = convert_to_ll(argv[6], &state); if (state == -1) { print_usage(argv[0]); return 1; } int iters[] = { r_iter, g_iter, b_iter }; long long points[] = { r_point, g_point, b_point }; Pixmap* px[3]; int i; for (i = 0; i < 3; i++) { px[i] = px_create(1280, 800); generate_fractal(cx, cy, rw, rh, px[i], iters[i], points[i]); px_normalize(px[i], 255); } Pixmap* pxc = px_combine_rgb(px[0], px[1], px[2]); px_dump_ppm(pxc, 255, "./buddhabrot.ppm"); px_destroy(px[0]); px_destroy(px[1]); px_destroy(px[2]); px_destroy(pxc); return 0; }
/* parse input for arguments and then call generate_fractal() with those arguments */ int main(int argc, char **argv) { char *file_name = "out.png"; float width = DEFAULT_WIDTH; float height = DEFAULT_HEIGHT; int workers = DEFAULT_WORKERS; unsigned int arg; for (arg = 1; arg < argc; arg++) { if (!strcmp(argv[arg], "-f") || !strcmp(argv[arg], "--file")) { arg++; if (arg < argc) file_name = argv[arg]; else { fprintf(stderr, "error: usage ./fractal [-s <scale>] [-f <file>] [-d <width> <height>]\n"); exit(1); } } else if (!strcmp(argv[arg], "-n") || !strcmp(argv[arg], "--workers")) { arg++; if (arg < argc) workers = atoi(argv[arg]); else { fprintf(stderr, "error: usage ./fractal [-s <scale>] [-f <file>] [-d <width> <height>]\n"); exit(1); } } else if (!strcmp(argv[arg], "-d") || !strcmp(argv[arg], "--dimensions")) { if (arg + 2 < argc) { width = strtof(argv[arg + 1], NULL); height = strtof(argv[arg + 2], NULL); } else { fprintf(stderr, "error: usage ./fractal [-s <scale>] [-f <file>] [-d <width> <height>]\n"); exit(1); } arg += 2; } else { fprintf(stderr, "error: usage ./fractal [-s <scale>] [-f <file>] [-d <width> <height>]\n"); exit(1); } } return generate_fractal(file_name, width, height, workers); }