Program to draw a line using Integer DDA method

/* Program to draw a line using Integer DDA method */

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int x1,y1,x2,y2,x,y,dy,dx,c=0;
cout<<“\n\t\t\t\*Integer DDA method to draw a line*\n”;
cout<<“\nenter the x coordinates(x1,x2)\n”;
cin>>x1>>x2;
cout<<“\nenter the y coordinates(y1,y2)\n”;
cin>>y1>>y2;
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
int gd=DETECT,gm;
initgraph(&gd,&gm,””);
setbkcolor(WHITE);
if(abs(dx)>=abs(dy))
{
while(x<=x2)
{
putpixel(x,y,8);
c+=dy;
if(c>=dx)
{
c-=dx;
y=y+1;
}
x=x+1;
}
}
else
{
while(y<=y2)
{
putpixel(x,y,8);
c+=dx;
if(c>=dy)
{
c-=dy;
x++;
}
y++;
}
}
setcolor(8);
outtextxy(115,70,”line using Integer DDA Method”);
getch();
closegraph();
}

Leave a Reply

Your email address will not be published. Required fields are marked *