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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#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, "vhi:x:y:l:u:z:")) != -1){
switch(opt){
case 'i':
iterations = strtoull(optarg, NULL, 10);
break;
case 'x':
x_res = strtoull(optarg, NULL, 10);
break;
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 [-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;
grid_t* grid = create_grid(x_res, y_res, lower_left, upper_right);
if(!grid) return 1;
if(magnification != 1){
if(verbose) printf("Magnification: %f\n", magnification);
zoom_grid(grid, magnification);
}
//const long double complex c = 0.285L + 0.01L*I;
const long double complex c = -0.835L -0.321L* I;
const double R = 100;
julia_grid(grid, iterations, c, R);
if(verbose)print_grid_info(grid);
print_grid(grid, iterations);
// //write grid to file
// FILE* write_file = fopen("test.grid", "wb");
// write_grid(write_file , grid);
// fclose(write_file);
//
// //attempt to read grid from file
// FILE* read_file = fopen("test2.grid", "rb");
// grid_t* grid2 = read_grid(read_file);
// fclose(read_file);
//
// printf("Grids are %s equal\n", grid_equal(grid, grid2) ? "exactly" :"not exactly");
}
|