Advertisement
nguyenvanquan7826

Circle

Aug 29th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #define color YELLOW
  4. #define DELAY 50
  5. using namespace std;
  6. void Put8Pixel(int x, int y, int x0, int y0)
  7. {
  8.     putpixel(x + x0, y + y0, color);
  9.     putpixel(y + y0, x + x0, color);
  10.     putpixel(y + y0, -x + x0, color);
  11.     putpixel(x + x0, -y + y0, color);
  12.     putpixel(-x + x0, -y + y0, color);
  13.     putpixel(-y + y0, -x + x0, color);
  14.     putpixel(-y + y0, x + x0, color);
  15.     putpixel(-x + x0, y + y0, color);
  16. }
  17.  
  18. void myCircle(int x0, int y0, int R)
  19. {
  20.     float p = 1 - R;
  21.     int x = 0;
  22.     float y = R;
  23.     Put8Pixel(x, y, x0, y0);
  24.     cout<<"("<<x<<","<<y<<")   "<<p<<endl;
  25.     while (x<y)
  26.     {
  27.         if (p<0)
  28.         {
  29.             //cout<<"("<<x<<","<<y<<")  : "<<"p = 2*"<<x<<"+3 = "<<p<<endl;
  30.             p += 2*x + 3;
  31.         }
  32.         else
  33.         {
  34.             //cout<<"("<<x<<","<<y<<")  : p = 2*("<<x<<"-"<<y<<") +5 = "<<p<<endl;
  35.             p += 2*(x - y) + 5;
  36.             y--;
  37.         }
  38.         x++;
  39.         Put8Pixel(x, y, x0, y0);
  40.         //delay(DELAY);
  41.     }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47.     int gd,gm=VGAMAX; gd=DETECT;
  48.     initgraph(&gd,&gm,NULL);        // khoi tao cua so do hoa
  49.     int x = 120, y = 120, R = 100;
  50.     myCircle(x, y, R);
  51.     cin.get();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement