Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<iostream.

h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void ddaline(int x1, int y1, int x2, int y2)
{
float x = x1, y = y1,dx, dy, xinc, yinc;
int step, k;
dx = x2 - x1;
dy = y2 - y1;
putpixel(x, y, WHITE);
if(abs(dx) >= abs(dy))
step = abs(dx);
else
step = abs(dy);
xinc = (float)(dx)/step;
yinc = (float)(dy)/step;
for(k = 0; k <= step; k++)
{
x = x + xinc;
y = y + yinc;
putpixel((int)x, (int)y, WHITE);
} //end of for
}//end of ddaline
void main()
{
clrscr();
int x1, x2, y1, y2;
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "c:/tc/bgi");
setbkcolor(BLUE);
cout<<"Enter the starting co-ordinates: ";
cin>>x1>>y1;
cout<<"Enter the end Co-ordinates : ";
cin>>x2>>y2;
ddaline(x1,y1,x2,y2);
getch();
} //end of main

You might also like