BresenHam’s Circle Drawing Step By Step Procedure Algorithm

To write c program to implement the bresenhams 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 (x,y) and radius(r) of a circle.
3. Initialize the variables
i. a=0;b=r;d=3-(2*r);
4. If(d>=0) then
i. b--;
ii. d=d+10+4*(a-b);
b. else
i. d=d+(4*a)+6
5. Repeat step 4 until a<=b and Increment a by 1 each time.
6. Plot the pixel to display the circle using put pixel function.
7. Display the circle. BRESENHAM’S CIRCLE DRAWING ALGORITHM
Source Code Programming Bresenham’s Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int r,x,y;
float a,b,d;
void bresan();
void pixel(float a,float 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",&x,&y);
printf("Enter the radius :\n");
scanf("%d",&r);
bresan();
getch();
}
void bresan()
{
a=0;
b=r;
d=3-(2*r);
while(a<=b)
{
a++;
if(d>=0)
{
b--;
d=d+10+4*(a-b);
}
else
d=d+(4*a)+6;
pixel(a,b);
}
}
void pixel(float a,float b)
{
putpixel(x+a,y+b,10);
putpixel(x-a,y-b,10);
putpixel(x+a,y-b,10);
putpixel(x-a,y+b,10);
putpixel(x+b,y+a,10);
putpixel(x-b,y-a,10);
putpixel(x+b,y-a,10);
putpixel(x-b,y+a,10);
}
Example Result Output Computer Graphics
Enter the center point:
400
200
Enter the radius:
100