#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
clrscr();
int gd,gm;
gd=DETECT;
gm=0;
int xa,ya,xb,yb;
cout<<"Enter ordinate of first point";
cin>>xa;
cout<<"Enter abissca of first point";
cin>>ya;
cout<<"Enter ordinate of second point";
cin>>xb;
cout<<"Enter abissca of second point";
cin>>yb;
double dx,dy,steps,p;
dx=xb-xa;
dy=yb-ya;
if(dx>=dy)
steps=abs(dx);
else
steps=abs(dy);
p=2*(dy)-dx;
initgraph(&gd,&gm,"Z:\tc\BGI");
putpixel(xa,ya,4);
for(int i=0;i<steps;i++)
{
if(p>=0)
{
putpixel(xa+1,ya+1,4);
p+=2*(dy-dx);
}
else
{
putpixel(xa+1,ya,4);
p+=2*(dy);
}
}
getch();
}
0 comments :