TITLE:2. Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
TITLE:Write C++/Java program to draw circle using Bresenham‘s algorithm. Inherit pixel class.
#include<iostream>
#include<graphics.h>
using namespace std;
class Pixel
{
public:
void pixel(int X,int Y,int x,int y)
{
putpixel(X+x, Y+y, RED);
putpixel(X-x, Y+y, RED);
putpixel(X+x, Y-y, RED);
putpixel(X-x, Y-y, RED);
putpixel(X+y, Y+x, RED);
putpixel(X-y, Y+x, RED);
putpixel(X+y, Y-x, RED);
putpixel(X-y, Y-x, RED);
}
};
class Bresenham : public Pixel
{
public:
void Bres_algo(int X,int Y,int r)
{
int x=0;
int y=r;
int d = 3-(2*r);
pixel(X,Y,x,y);
do
{
if(d<0)
{
d = d+(4*x)+6;
}
else
{
d = d+4*(x-y)+10;
y--;
}
x++;
pixel(X,Y,x,y);
}while(x<=y);
}
};
int main()
{
int X,Y,r;
Bresenham b;
cout<<"\nBRESENHAM CIRCLE DRAWING.....";
cout<<"\n Enter the co-ordinates (X,Y) :";
cin>>X>>Y;
cout<<"\n Enter the Radius :";
cin>>r;
int gd = DETECT, gm;
initgraph(&gd,&gm,NULL);
b.Bres_algo(X,Y,r);
getch();
delay(100000);
closegraph();
return 0;
}
OUTPUT:

No comments:
Post a Comment