Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. void print_byte_array(byte* arr, int w, int h) {
  2.     printf("\n[ ");
  3.     for (int y = 0; y < h; y++) {
  4.         for (int x = 0; x < w; x++) {
  5.             printf("%d, ", arr[x+y*h]);
  6.         }
  7.         printf("\n  ");
  8.     }
  9.     printf("]\n");
  10. }
  11. #define plot(x,y) arr[(x)+((y)*20)] = 1
  12.  
  13. void symmetry(int x,int y,int xc,int yc,byte* arr)
  14. {
  15.  plot(xc+x,yc-y);//For pixel (x,y)
  16.  plot(xc+y,yc-x);//For pixel (y,x)
  17.  plot(xc+y,yc+x);//For pixel (y,-x)
  18.  plot(xc+x,yc+y);//For pixel (x,-y)
  19.  plot(xc-x,yc+y);//For pixel (-x,-y)
  20.  plot(xc-y,yc+x);//For pixel (-y,-x)
  21.  plot(xc-y,yc-x);//For pixel (-y,x)
  22.  plot(xc-x,yc-y);//For pixel (-x,y)
  23. }
  24.  
  25. void raster_circle(int xc,int yc,int rad) {
  26.     byte arr[20*15];
  27.     ZeroMemory(arr,20*15);
  28.    int x = 0;
  29.  int y = rad;
  30.  int p = 1-rad;
  31.  symmetry(x,y,xc,yc,(byte*)arr);
  32.  
  33.  
  34.  for(x= 0;y>x;x++)
  35.     {
  36.     if(p<0)
  37.        p += 2*x + 3;
  38.     else
  39.       {
  40.        p += 2*(x-y) + 5;
  41.        y--;
  42.       }
  43.     symmetry(x,y,xc,yc,(byte*)arr);
  44.      }
  45.  
  46.     print_byte_array((byte*)arr,20,15);
  47. }
Add Comment
Please, Sign In to add comment