Wednesday, 19 February 2014

MID POINT ALGORITHM FOR DRAWING CIRCLE



 /****************************************************************************/ 
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
void drawCircle(int,int,int);
int main()
{
                int x=300,y=300,r=100,i,j;
                int gmode,gdriver=DETECT;
                initgraph(&gdri
                driver,&gmode,"");
                //circle(x,y,r);


                drawCircle(x,y,r);

                getch();
                return 0;
}

void drawCircle(int x0,int y0,int r)
{
                int x=r,y=0;
                int radiusError=1-x;

                while(x>=y)
                {
                                putpixel(x+x0,y+y0,WHITE);
                                putpixel(y+x0,x+y0,WHITE);
                                putpixel(-x+x0,y+y0,WHITE);
                                putpixel(-y+x0,x+y0,WHITE);
                                putpixel(-x+x0,-y+y0,WHITE);
                                putpixel(-y+x0,-x+y0,WHITE);
                                putpixel(x+x0,-y+y0,WHITE);
                                putpixel(y+x0,-x+y0,WHITE);

                                y++;
                                if(radiusError<0)
                                                radiusError+=2*y+1;
                                else
                                {
                                                x--;
                                                radiusError+=2*(y-x+1);
                                }
                }
}

 /****************************************************************************/

No comments:

Post a Comment