Friday, 27 September 2013

Mid Point Circle Algo


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
 clrscr();
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
 int r,pk,xc,yc,x,y,pk1;
 cout<<"enter the coordinates of center:";
 cin>>xc>>yc;
 cout<<"enter the radius:";
 cin>>r;
 pk=1-r;
 x=0;
 y=r;
 while((x<=y))
 if(pk<0)
 {
  x++;
  putpixel(x+xc,y+yc,RED);
  putpixel(-y+xc,x+yc,RED);
  putpixel(x+xc,-y+yc,RED);
  putpixel(-y+xc,-x+yc,RED);
  putpixel(-x+xc,-y+yc,RED);
  putpixel(-x+xc,y+yc,RED);
  putpixel(y+xc,-x+yc,RED);
  putpixel(y+xc,x+yc,RED);
  pk=pk+(2*x)+1;
  }
  else
  {
   x++;
   y--;
   putpixel(x+xc,y+yc,RED);
   putpixel(-y+xc,x+yc,RED);
   putpixel(x+xc,-y+yc,RED);
   putpixel(-y+xc,-x+yc,RED);
   putpixel(-x+xc,-y+yc,RED);
   putpixel(-x+xc,y+yc,RED);
   putpixel(y+xc,-x+yc,RED);
   putpixel(y+xc,x+yc,RED);
   pk=pk+(2*x)-(2*y)+1;
   }
   getch();
   closegraph();
   }
Jerrin Andrei Web Developer

No comments:

Post a Comment

Total Pageviews

DjKiRu Initative. Powered by Blogger.