Implementing Bresenham’s Circle Drawing Algorithm in C++

Here is implementation of Bresenham’s Circle Drawing algorithm in C++.

void circ_bre(int x,int y,int rad);
void display(int,int,int,int);
void main()
int gd = DETECT, gm, x,y,r;
cout<<"Bresenhams circle generation algorithm "; cout<<"\nEnter the center co-ordinates for circle "; cin>>x>>y;
cout<<"\nEnter the radius of the circle"; cin>>r;
void circ_bre(int x,int y,int rad)
float dp; //initialising the descision parameter.
int x1,y1;
x1 = 0; //initialisng the X,Y cordinates.
y1 = rad;
dp = 3 – 2*rad;
while(x1<=y1) { if(dp<=0) dp += (4 * x1) + 6; else { dp += 4*(x1-y1)+10; y1--; } x1++; display(x1,y1,x,y); } } void display (int x1,int y1,int x,int y) { putpixel(x1+x,y1+y,WHITE); //plotting the pixels. putpixel(x1+x,y-y1,WHITE); putpixel(x-x1,y1+y,WHITE); putpixel(x-x1,y-y1,WHITE); putpixel(x+y1,y+x1,WHITE); putpixel(x+y1,y-x1,WHITE); putpixel(x-y1,y+x1,WHITE); putpixel(x-y1,y-x1,WHITE); } [/cpp] Output:

Output of Bresenham's Circle Drawing algortihm
Output of Bresenham’s Circle Drawing algortihm

Leave a Reply

Your email address will not be published. Required fields are marked *