AIM:
To write a "C++" program for the implementation of DDA line drawing algorithm in CS1255 - Graphics and Multimedia Lab.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
class lineDDA
{
private:
int dx,dy,x,y,xi,yi,xa,ya,xb,yb,step,k;
public:
void getdata();
void line();
};
void lineDDA::getdata()
{
cout<<"\n\tEnter xa and ya :";
cin>>xa>>ya;
cout<<"\n\tEnter xb and yb :";
cin>>xb>>yb;
}
void lineDDA::line()
{
dx=abs(xb-xa);
dy=abs(yb-ya);
if(dx>dy)
step=dx;
else
step=dy;
xi=(xb-xa)/step;
yi=(yb-ya)/step;
x=xa;
y=ya;
putpixel(abs(x),abs(y),1);
for(k=1;k<=step;k++)
{
x+=xi;
y+=yi;
putpixel(abs(x),abs(y),1);
}
}
void main()
{
lineDDA l;
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:/TC/BGI");
l.getdata();
l.line();
getch();
closegraph();
}
OUTPUT:
To write a "C++" program for the implementation of DDA line drawing algorithm in CS1255 - Graphics and Multimedia Lab.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
class lineDDA
{
private:
int dx,dy,x,y,xi,yi,xa,ya,xb,yb,step,k;
public:
void getdata();
void line();
};
void lineDDA::getdata()
{
cout<<"\n\tEnter xa and ya :";
cin>>xa>>ya;
cout<<"\n\tEnter xb and yb :";
cin>>xb>>yb;
}
void lineDDA::line()
{
dx=abs(xb-xa);
dy=abs(yb-ya);
if(dx>dy)
step=dx;
else
step=dy;
xi=(xb-xa)/step;
yi=(yb-ya)/step;
x=xa;
y=ya;
putpixel(abs(x),abs(y),1);
for(k=1;k<=step;k++)
{
x+=xi;
y+=yi;
putpixel(abs(x),abs(y),1);
}
}
void main()
{
lineDDA l;
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:/TC/BGI");
l.getdata();
l.line();
getch();
closegraph();
}
OUTPUT:
1 comments:
Write commentsMust be explained .. Please provide an explanation.
ReplyEmoticonEmoticon