Advertisement
Guest User

Aufgabe 2

a guest
Nov 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <complex.h>
  5. #include <time.h>
  6.  
  7. void MVisualisierung (float x_min, float x_max, float y_min, float y_max, int w, int h, int n_max){
  8.    
  9.    
  10.     int i, j, k_x, k_y, temp;
  11.     int n = 0;
  12.     float delta_x = (x_max - x_min)/w;
  13.     float delta_y = (y_max - x_min)/h;
  14.     float x;
  15.     float y;
  16.     float complex c, z;
  17.     FILE* visu;
  18.     int** array = (int**) calloc(w, sizeof(int*));
  19.     for (i = 0; i < w; i++){
  20.         array[i] = (int*) calloc(h, sizeof(int));
  21.     }
  22.    
  23.     for (k_x = 0; k_x < w; k_x++){
  24.        
  25.         for (k_y = 0; k_y < h; k_y++){
  26.            
  27.             x = x_min + (k_x - 0.5) * delta_x;
  28.             y = y_min + (k_y - 0.5) * delta_y;
  29.             c = x + I*y;
  30.             z = 0;
  31.             n = 0;
  32.            
  33.             while (cabsf(z) < 2 && n <= n_max){
  34.                 z = z*z + c;
  35.                 n++;
  36.             }
  37.            
  38.             array[k_x][k_y] = pow((float)n/n_max, 0.2) * 255;
  39.         }
  40.     }
  41.    
  42.     visu = fopen("visualized.pgm", "wb");
  43.     fprintf(visu, "P2\n");
  44.     fprintf(visu, "%d %d\n", h, w);
  45.     fprintf(visu, "255\n");
  46.    
  47.     for(i = 0; i < h; i++){
  48.        
  49.         for(j = 0; j < w; j++){
  50.            
  51.             temp =  array[i][j];
  52.             fprintf(visu, "%d ", temp);
  53.            
  54.             //printf("%d ", (int)arr[i][j]);
  55.            
  56.         }
  57.        
  58.         fprintf(visu, "\n");
  59.         //printf("\n");
  60.        
  61.     }
  62.    
  63.     fclose(visu);
  64.     free(array);
  65.  
  66. }
  67.  
  68. int main (){
  69.  
  70.     clock_t start;
  71.     clock_t ende;
  72.    
  73.     start = clock();
  74.     MVisualisierung (-1.9, 0.6, -1.1, 1.1, 2500, 2200, 1024);
  75.     ende = clock();
  76.            
  77.     printf("Dauer: %.10f sekunden\n", (double)(ende - start) / CLOCKS_PER_SEC);
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement