Tuesday, April 13, 2010

Midpoint Circle Algo

#include
#include
#include
#include
void main()
{
 int xc,yc,r,gd=DETECT,gm;
 void mid_cir(int,int,int);
  printf("Enter the midpoints of circle and radius as xc,yc,r :\n");
 scanf("%d%d%d",&xc,&yc,&r);
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 mid_cir(xc,yc,r);
 getch();
 }
 void mid_cir(int xc,int yc,int r)
 {
  int x=0,y=r,p;
  void display(int,int,int,int);
  p=1-r;
  while(x<=y)
  {
   display(xc,yc,x,y);
   if(p<0)
   p+=2*x+3;
   else
   {
    p+=2*(x-y)+5;
    y--;
   }
  x++;
 }
}
 void display(int xc,int yc,int x,int y)
 {
  putpixel(xc+x,yc+y,14);
  putpixel(xc+x,yc-y,14);
  putpixel(xc-x,yc+y,14);
  putpixel(xc-x,yc-y,14);
  putpixel(xc+y,yc+x,14);
  putpixel(xc+y,yc-x,14);
  putpixel(xc-y,yc+x,14);
  putpixel(xc-y,yc-x,14);
 }

0 comments:

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase