Implementation of DDA Line Drawing Algorithm [CS1255 - Graphics and Multimedia Lab]

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:

Previous
Next Post »

1 comments:

Write comments
May 5, 2014 at 5:41 PM delete

Must be explained .. Please provide an explanation.

Reply
avatar

If you still didn't find what you're looking for, you can search this website below: