diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-20 23:49:21 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-20 23:49:21 -0400 |
| commit | 7516add571888d32d3d33364a35cd8148ed3bff6 (patch) | |
| tree | 181d183354f69dc096aaba1e4e6172a862b7f981 /src/fractals.c | |
| parent | d68fafdb137a52384d5b405ee288e79bff9f9e8a (diff) | |
add zoom feature to grids and shifted code around
Diffstat (limited to 'src/fractals.c')
| -rw-r--r-- | src/fractals.c | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/fractals.c b/src/fractals.c index 80ff32e..a2a43db 100644 --- a/src/fractals.c +++ b/src/fractals.c @@ -8,16 +8,21 @@ #include "grids.h" #include "fractals.h" - int main(const int argc, char *argv[]) { //default values size_t iterations = 1000; size_t x_res = 100; size_t y_res = 100; + double re_lower_left = -2; + double im_lower_left = -2; + double re_upper_right = 2; + double im_upper_right = 2; + double magnification = 1; + bool verbose = false; //parse command line arguments int opt; - while((opt =getopt(argc, argv, "i:x:y:")) != -1){ + while((opt = getopt(argc, argv, "vhi:x:y:l:u:z:")) != -1){ switch(opt){ case 'i': iterations = strtoull(optarg, NULL, 10); @@ -28,26 +33,46 @@ int main(const int argc, char *argv[]) { case 'y': y_res = strtoull(optarg, NULL, 10); break; + case 'l': + sscanf(optarg, "%lf+%lfi", &re_lower_left, &im_lower_left); + break; + case 'u': + sscanf(optarg, "%lf+%lfi", &re_upper_right, &im_upper_right); + break; + case 'z': + sscanf(optarg, "%lf", &magnification); + if(magnification <= 0){ + fprintf(stderr, "Invalid magnification %f, exitting\n", magnification); + return 1; + } + break; + case 'v': + verbose = true; + break; + case 'h': + fprintf(stderr, "Usage: %s [-v] [-i iterations] [-x x_res] [-y y_res] [-z magnification] [-l lower_left] [-u upper_right]\n", argv[0]); + return 0; default: - fprintf(stderr, "Usage: %s [-i iterations] [-x x_res] [-y y_res]\n", argv[0]); + fprintf(stderr, "Usage: %s [-v] [-i iterations] [-x x_res] [-y y_res] [-z magnification] [-l lower_left] [-u upper_right]\n", argv[0]); return 1; } } + const double complex lower_left = re_lower_left + im_lower_left * I; + const double complex upper_right = re_upper_right + im_upper_right * I; - const double complex lower_left = -2 + -2*I; - const double complex upper_right = 2 + 2*I; grid_t* grid = create_grid(x_res, y_res, lower_left, upper_right); if(!grid) return 1; - const size_t size = grid->size; - size_t* data = grid->data; - for(size_t i = 0; i < size;i++){ - data[i] = multibrot(grid_to_complex(grid, i), iterations, 3); + if(magnification != 1){ + if(verbose) printf("Magnification: %f\n", magnification); + zoom_grid(grid, magnification); } - for(size_t i = 0; i < size; i++){ - printf("%zu%s", data[i], (i % x_res == x_res - 1) ? "\n" : "\t"); - } + + mandelbrot_grid(grid, iterations); + + if(verbose)print_grid_info(grid); + print_grid(grid, iterations); } |
