How To Write Source Code For Mid Point Circle Drawing Algorithm

To write the c program to implement the Midpoint Circle Drawing Algorithm.
Step By Step Procedure Algorithm
1. Include the graphics header file and obtain graphics mode and driver.
2. Get the center point (a,b)and radius r of the circle.
3. Initialize the variables and decision parameter as,x=0;y=r;p=1-r;
4. If (p<0)then the next point along the circle is (x+1,y) and p=p+2*x+1;
Else the next point along the circle is (x=1,y-1) and p=p+2*(x-y)+1;
5. Repeat step4 until x<y.
6. Plot the pixel to display the circle using put pixel function.
7. Display the circle. Mid Point Circle Drawing Algorithm
Source Code Programming Computer Graphics
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x,y,p,r,d,a,b;
void mid();
void pixel(int a,int b);
void main()
{
int gm,gr;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
printf("Enter the center point:\n");
scanf("%d%d",&a,&b);
printf("Enter the radius:\n");
scanf("%d",&r);
mid();
getch();
}
void mid()
{
x=0;
y=r;
p=1-r;
while(x<y)
{
pixel(a,b);
if(p<0)
x=x+1;
else
{
x=x+1;
y=y-1;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
}
}
void pixel(int a,int b)
{
putpixel(a+x,b+y,10);
putpixel(a-x,b+y,10);
putpixel(a+x,b-y,10);
putpixel(a-x,b-y,10);
putpixel(a+y,b+x,10);
putpixel(a-y,b-x,10);
putpixel(a+y,b-x,10);
putpixel(a-y,b+x,10);
}
Computer Graphics Example Output Result
Enter the center point:
300
200
Enter the radius:
100

Related post