Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. void kolo(int x, int y, int r,unsigned char color)
  7. {
  8.         int x1,y1,yk = 0;
  9.         int sigma,delta,f;
  10.  
  11.         x1 = 0;
  12.         y1 = r;
  13.         delta = 2*(1-r);
  14.  
  15.         do
  16.         {
  17.                 putpixel(x+x1,y+y1,color);
  18.                 putpixel(x-x1,y+y1,color);
  19.                 putpixel(x+x1,y-y1,color);
  20.                 putpixel(x-x1,y-y1,color);
  21.  
  22.                 f = 0;
  23.                 if (y1 < yk)
  24.                         break;
  25.                 if (delta < 0)
  26.                 {
  27.                         sigma = 2*(delta+y1)-1;
  28.                         if (sigma <= 0)
  29.                         {
  30.                                 x1++;
  31.                                 delta += 2*x1+1;
  32.                                 f = 1;
  33.                         }
  34.                 }
  35.                 else
  36.                 if (delta > 0)
  37.                 {
  38.                         sigma = 2*(delta-x1)-1;
  39.                         if (sigma > 0)
  40.                         {
  41.                                 y1--;
  42.                                 delta += 1-2*y1;
  43.                                 f = 1;
  44.                         }
  45.                 }
  46.                 if (!f)
  47.                 {
  48.                         x1++;
  49.                         y1--;
  50.                         delta += 2*(x1-y1-1);
  51.                 }
  52.         }
  53.         while(1);
  54. }
  55.  
  56. int main()
  57. {
  58.     int r=50;
  59.     int x=r+1;
  60.     int y=r+1;
  61.    
  62. initwindow(480,480);
  63.  
  64. while(1)
  65.     {
  66.         if(kbhit())
  67.             switch(getch())
  68.             {
  69.                 case 75://Left
  70.                     if((x-r-1)>0){
  71.                         cleardevice();
  72.                         kolo(--x, --y, r,2);
  73.                      };
  74.                     break;
  75.                 case 77://Right
  76.                 if((x+r+1)<480){
  77.                         cleardevice();
  78.                         kolo(++x, ++y, r,2);
  79.                      };
  80.                     break;
  81.                 case 72://Up
  82.                     if((r+1)<50){
  83.                         cleardevice();
  84.                         kolo(x, y, ++r,2);
  85.                      };
  86.                     break;
  87.                 case 80://Down
  88.                     if((r-1)>5){
  89.                         cleardevice();
  90.                         kolo(x, y, --r,2);
  91.                      };
  92.                     break;
  93.                 case 27://ESC
  94.                     closegraph();
  95.                     return 0;
  96.             }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement