Saturday, 8 March 2014

PROGRAM FOR CIRCLE


/*CSEMATTER.BLOSPOT.IN
PROGRAM-PROGRAM TO DRAW A CIRCLE IN GRAPHICS*/


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{    void plotpoint(int,int,int,int);
 int x,y,xc,yc,r,gm,gd=DETECT,p=0;
    initgraph(&gd,&gm,"C:\TC\BGI");
      printf("enter the value of centre coordinates");
      scanf("%d %d",&xc,&yc);
      printf("enter the value of x and radius");
      scanf("%d %d",&x,&r);
    p=1-r;
    y=r;
    plotpoint(xc,yc,x,y);
    while(x<=y)
    {
        x++;
        if(p<0)
        {
            p+=2*x+3;
        }
        else
        {
            y--;
            p+=2*(x-y)+5;

        }
        plotpoint(xc,yc,x,y);
    }
    getch();
    closegraph();

}
void plotpoint(int xc,int yc,int x,int y)
{
    putpixel(xc+x,yc+y,15);
    putpixel(xc-x,yc+y,15);
    putpixel(xc+x,yc-y,15);
    putpixel(xc-x,yc-y,15);
    putpixel(xc+y,yc+x,15);
    putpixel(xc-y,yc+x,15);
    putpixel(xc+y,yc-x,15);
    putpixel(xc-y,yc-x,15);
}


No comments:

Post a Comment