#include #include #include #include #include #include #include #define x_MIN -2.0 #define x_MAX 1.0 #define y_MIN 0 #define y_MAX 1.0 #define BMP_HEIGHT 1080 #define BMP_WIDTH 1920 #define N_MAX 250 void toMath(int X, int Y, double* x, double* y) { if ((X < 0) || (X > BMP_WIDTH) || (Y < 0) || (Y > BMP_HEIGHT)) { printf("Fehler: 0 <= %d <= %d\n", X, BMP_WIDTH); printf(" oder 0 <= %d <= %d verletzt!\n", Y, BMP_HEIGHT); *x = x_MIN; *y = y_MIN; return; } *x = x_MIN + ((double) X * (x_MAX - x_MIN)) / BMP_WIDTH; *y = y_MIN + ((double) (BMP_HEIGHT - Y) * (y_MAX - y_MIN)) / BMP_HEIGHT; } int mandelbrot(double x, double y, double zx, double zy, int n, int n_max, double threshold) { if ((n < n_max) && ((zx * zx + zy * zy) < threshold)) { double zx_new = (zx * zx - zy * zy + x); double zy_new = (2 * zx * zy + y); if ((zx_new == zx) && (zy_new == zy)) { return n_max; } n = mandelbrot(x, y, zx_new, zy_new, n + 1, n_max, threshold); } return n; } int main(){ float z; clock_t begin, begin2, end, end2; uint32_t X = 0, Y = 0; begin = clock(); uint32_t* data = (uint32_t*) malloc(BMP_WIDTH * BMP_HEIGHT * sizeof(uint32_t)); int n = 0; double x = 0.0, y = 0.0; int n_max = 500; double threshold = 4.0; for (int Y = 0; Y < BMP_HEIGHT; Y++) { for (int X = 0; X < BMP_WIDTH; X++) { double x, y; toMath(X, Y, &x, &y); int n = mandelbrot(x, y, 0.0, 0.0, 0, n_max, threshold); data[Y * BMP_WIDTH + X] = n; } } end = clock(); printf("Rekursion Ende\n"); //getchar(); // for(int i = 0; i < BMP_HEIGHT*BMP_WIDTH; i++){ // printf("%d\n",data[i]); // } begin2 = clock(); uint32_t* data2 = (uint32_t*) malloc(BMP_WIDTH * BMP_HEIGHT * sizeof(uint32_t)); for (int Y = 0; Y < BMP_HEIGHT; Y++) { for (int X = 0; X < BMP_WIDTH; X++) { double x, y, x2; toMath(X, Y, &x, &y); double cx = x; double cy = y; int m = 0; while(m <=n_max && (x*x)+(y*y) < 4){ x2 = x; x = (x*x) - (y*y) + cx; y = 2.0*x2*y + cy; m++; } data2[Y * BMP_WIDTH + X] = m; } } end2 = clock(); printf("Schleife Ende\n"); // for(int i = 0; i < BMP_WIDTH * BMP_HEIGHT; i++){ // if(data[i] != data[2]){ // printf("Unterschied\n"); // } // } printf("Rekursion:\n"); printf("begin: %d\n", begin); printf("end: %d\n", end); printf("clocks zwischen begin und end: %d\n", end - begin); z=end - begin; z/=CLOCKS_PER_SEC; printf("Zeit zwischen begin und end: %f Sekunden\n", z); printf("CLOCKS_PER_SEC: %d\n", CLOCKS_PER_SEC); printf("Schleifen:\n"); printf("begin: %d\n", begin2); printf("end: %d\n", end2); printf("clocks zwischen begin und end: %d\n", end2 - begin2); z=end2 - begin2; z/=CLOCKS_PER_SEC; printf("Zeit zwischen begin und end: %f Sekunden\n", z); printf("CLOCKS_PER_SEC: %d\n", CLOCKS_PER_SEC); for(int i = 0; i < BMP_HEIGHT*BMP_WIDTH; i++){ printf("Schleife: %d -- Rekursion: %d\n",data2[i], data[i]); getch(); } }