Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <complex.h>
- #include <time.h>
- void MVisualisierung (float x_min, float x_max, float y_min, float y_max, int w, int h, int n_max){
- int i, j, k_x, k_y, temp;
- int n = 0;
- float delta_x = (x_max - x_min)/w;
- float delta_y = (y_max - x_min)/h;
- float x;
- float y;
- float complex c, z;
- FILE* visu;
- int** array = (int**) calloc(w, sizeof(int*));
- for (i = 0; i < w; i++){
- array[i] = (int*) calloc(h, sizeof(int));
- }
- for (k_x = 0; k_x < w; k_x++){
- for (k_y = 0; k_y < h; k_y++){
- x = x_min + (k_x - 0.5) * delta_x;
- y = y_min + (k_y - 0.5) * delta_y;
- c = x + I*y;
- z = 0;
- n = 0;
- while (cabsf(z) < 2 && n <= n_max){
- z = z*z + c;
- n++;
- }
- array[k_x][k_y] = pow((float)n/n_max, 0.2) * 255;
- }
- }
- visu = fopen("visualized.pgm", "wb");
- fprintf(visu, "P2\n");
- fprintf(visu, "%d %d\n", h, w);
- fprintf(visu, "255\n");
- for(i = 0; i < h; i++){
- for(j = 0; j < w; j++){
- temp = array[i][j];
- fprintf(visu, "%d ", temp);
- //printf("%d ", (int)arr[i][j]);
- }
- fprintf(visu, "\n");
- //printf("\n");
- }
- fclose(visu);
- free(array);
- }
- int main (){
- clock_t start;
- clock_t ende;
- start = clock();
- MVisualisierung (-1.9, 0.6, -1.1, 1.1, 2500, 2200, 1024);
- ende = clock();
- printf("Dauer: %.10f sekunden\n", (double)(ende - start) / CLOCKS_PER_SEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement