#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
struct co_ordinate
{
int x,y;
};
class ddaline
{
public:
co_ordinate point[2];
void input_parameter()
{
cout<<"enter starting point co_ordinate:- ";
cin>>point[0].x>>point[0].y;
cout<<"enter ending point co_ordinate:- ";
cin>>point[1].x>>point[1].y;
}
void draw_line();
};//end of class ddaline
void ddaline :: draw_line()
{
int x,y,dx,dy,x_increament,y_increament,steps,i;
dx=point[1].x-point[0].x;
dy=point[1].y-point[0].y;
if(abs(dx)>abs(dy))
steps=dx;
else
steps=dy;
x_increament=dx/steps;
y_increament=dy/steps;
x=point[0].x;
y=point[0].y;
putpixel(x,y,5);
for(i=0;i<steps;i++)
{
x=x+x_increament;
y=y+y_increament;
putpixel(x,y,5);
}
}//end of function drawline
void main()
{
clrscr();
ddaline d;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
d.input_parameter();
d.draw_line();
getch();
}
#include<conio.h>
#include<graphics.h>
#include<math.h>
struct co_ordinate
{
int x,y;
};
class ddaline
{
public:
co_ordinate point[2];
void input_parameter()
{
cout<<"enter starting point co_ordinate:- ";
cin>>point[0].x>>point[0].y;
cout<<"enter ending point co_ordinate:- ";
cin>>point[1].x>>point[1].y;
}
void draw_line();
};//end of class ddaline
void ddaline :: draw_line()
{
int x,y,dx,dy,x_increament,y_increament,steps,i;
dx=point[1].x-point[0].x;
dy=point[1].y-point[0].y;
if(abs(dx)>abs(dy))
steps=dx;
else
steps=dy;
x_increament=dx/steps;
y_increament=dy/steps;
x=point[0].x;
y=point[0].y;
putpixel(x,y,5);
for(i=0;i<steps;i++)
{
x=x+x_increament;
y=y+y_increament;
putpixel(x,y,5);
}
}//end of function drawline
void main()
{
clrscr();
ddaline d;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
d.input_parameter();
d.draw_line();
getch();
}
No comments:
Post a Comment