//Program to draw circle using second order mid point approach
Source code
#include<dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void plotcircle(int x,int y,int a,int b)
{
int xmax=getmaxx();
int ymax=getmaxy();
putpixel(x+xmax/2+a,ymax/2-y-b,15);
putpixel(xmax/2+y+a,ymax/2-x-b,15);
putpixel(x+xmax/2+a,ymax/2+y-b,15);
putpixel(y+xmax/2+a,ymax/2+x-b,15);
putpixel(xmax/2-x+a,ymax/2-y-b,15);
putpixel(xmax/2-y+a,ymax/2-x-b,15);
putpixel(xmax/2-x+a,ymax/2+y-b,15);
putpixel(xmax/2-y+a,ymax/2+x-b,15);
}
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax,x,y,i,de=3,dse;
int r,a,b,d;
printf("Enter the value radius and center ");
scanf("%d%d%d",&r,&a,&b);
dse=5-2*r;
clrscr();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();
x=xmax/2;
y=ymax/2;
d=1-r;
for(i=0;i<xmax;i++)
putpixel(i,y,15);
for(i=0;i<ymax;i++)
putpixel(x,i,15);
x=0;
y=r;
while(y>=x)
{
if(d<0)
{
d+=de;
de+=2;
dse+=2;
x++;
}
else
{
d+=dse;
de+=2;
dse+=4;
x++;
y--;
}
plotcircle(x,y,a,b);
delay(100);
}
/* clean up */
getch();
closegraph();
return 0;
}
No comments:
Post a Comment