Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.39 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.    int main()
  4.    {
  5.         int width, height;
  6.         printf("Enter the size of the fractal, height and width:\n");
  7.         scanf("%d", &height);
  8.         scanf("%d", &width);
  9.  
  10.         int max_iter = 56;
  11.  
  12.         int x, y;
  13.         for (y = 0; y <= height; y++) {
  14.                 for (x = 0; x <= width; x++) {
  15.                         double x0 = -0.521;
  16.                         double y0 = 0.520;
  17.  
  18.                         double xi = (3.5 / width) * x - 1.7;
  19.                         double yi = (2.0 / height) * y - 1.0;
  20.  
  21.                         int iteration = 0;
  22.  
  23.                         while ((xi * xi + yi * yi) < 4 && (iteration < max_iter)) {
  24.                                 double xtemp = xi * xi - yi * yi + x0;
  25.                                 yi = 2.0 * xi * yi + y0;
  26.                                 xi = xtemp;
  27.                                 iteration++;
  28.                         }
  29.  
  30.                         if (iteration == max_iter || iteration == 0) {
  31.                                 printf(" ");
  32.                         } else {
  33.                                 switch ((iteration - 1) % 8) {
  34.                                 case 0:
  35.                                         printf(".");
  36.                                         break;
  37.                                 case 1:
  38.                                         printf(":");
  39.                                         break;
  40.                                 case 2:
  41.                                         printf("c");
  42.                                         break;
  43.                                 case 3:
  44.                                         printf("o");
  45.                                         break;
  46.                                 case 4:
  47.                                         printf("C");
  48.                                         break;
  49.                                 case 5:
  50.                                         printf("O");
  51.                                         break;
  52.                                 case 6:
  53.                                         printf("8");
  54.                                         break;
  55.                                 case 7:
  56.                                         printf("@");
  57.                                         break;
  58.                                 }
  59.  
  60.                         }
  61.                 }
  62.                 printf("\n");
  63.         }
  64.  
  65.         return 0;
  66.    }
Add Comment
Please, Sign In to add comment