BRESENHAMS CIRCLE DRAWING-RECURSIVE (C++):
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
class bre
{
float x1,y1,r;
public:
bre(){}
void brecrc(int,int,int);
void disp(int,int,int,int);
};
void bre::brecrc(int t1,int t2,int t3)
{
x1=t1;y1=t2;r=t3;
float x,y,temp,s,e;
int i;
x=0;y=r;
s=3-2*r;
while(x<=y)
{
if(s<=0)
{
s=s+4*x+6;
x=x+1;
}
else
{
s=s+4*(x-y)+10;
x=x+1;
y=y-1;
}
disp(x,y,x1,y1);
getch();
}
}
void bre :: disp(int x,int y,int x1,int y1)
{
putpixel(x+x1,y+y1,WHITE);
putpixel(x+x1,y1-y,WHITE);
putpixel(x1-x,y+y1,WHITE);
putpixel(x1-x,y1-y,WHITE);
putpixel(x1+y,y1+x,WHITE);
putpixel(x1+y,y1-x,WHITE);
putpixel(x1-y,y1+x,WHITE);
putpixel(x1-y,y1-x,WHITE);
}
void main()
{
int ch,gd=DETECT,gm; char ans;
float a,c,d,e;
bre b;
initgraph(&gd,&gm,"C:\\TC\\bgi");
cleardevice();
do
{
cout<<" MENU(bres Method):->\n1.Circle draw.\n2.object.\n Enter your choice=>";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the Centre and radius of circle to be drawn=>";
cin>>a>>c>>d;
cleardevice();
b.brecrc(a,c,d);
break;
case 2:
cleardevice();
b.brecrc(100,100,50);
b.brecrc(150,100,50);
b.brecrc(200,100,50);
b.brecrc(250,100,50);
cleardevice();
break;
default:
cout<<"You Entered wrong choice.";
break;
}
cout<<"Do you want to continue(y/n) =>";
cin>>ans;
}while(ans=='y'||ans=='Y');
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
class bre
{
float x1,y1,r;
public:
bre(){}
void brecrc(int,int,int);
void disp(int,int,int,int);
};
void bre::brecrc(int t1,int t2,int t3)
{
x1=t1;y1=t2;r=t3;
float x,y,temp,s,e;
int i;
x=0;y=r;
s=3-2*r;
while(x<=y)
{
if(s<=0)
{
s=s+4*x+6;
x=x+1;
}
else
{
s=s+4*(x-y)+10;
x=x+1;
y=y-1;
}
disp(x,y,x1,y1);
getch();
}
}
void bre :: disp(int x,int y,int x1,int y1)
{
putpixel(x+x1,y+y1,WHITE);
putpixel(x+x1,y1-y,WHITE);
putpixel(x1-x,y+y1,WHITE);
putpixel(x1-x,y1-y,WHITE);
putpixel(x1+y,y1+x,WHITE);
putpixel(x1+y,y1-x,WHITE);
putpixel(x1-y,y1+x,WHITE);
putpixel(x1-y,y1-x,WHITE);
}
void main()
{
int ch,gd=DETECT,gm; char ans;
float a,c,d,e;
bre b;
initgraph(&gd,&gm,"C:\\TC\\bgi");
cleardevice();
do
{
cout<<" MENU(bres Method):->\n1.Circle draw.\n2.object.\n Enter your choice=>";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the Centre and radius of circle to be drawn=>";
cin>>a>>c>>d;
cleardevice();
b.brecrc(a,c,d);
break;
case 2:
cleardevice();
b.brecrc(100,100,50);
b.brecrc(150,100,50);
b.brecrc(200,100,50);
b.brecrc(250,100,50);
cleardevice();
break;
default:
cout<<"You Entered wrong choice.";
break;
}
cout<<"Do you want to continue(y/n) =>";
cin>>ans;
}while(ans=='y'||ans=='Y');
getch();
}
No comments:
Post a Comment
Thanks for your valuable comment