#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");
int x1=50,y1=100,x2=100,y2=300,dx,dy,length;
int i=1;
float x,y,xi,yi;
/* cout<<"Enter Starting Point:";
cin>>x1>>y1;
cout<<"Enter Ending Point :";
cin>>x2>>y2;*/
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
length=abs(dx);
else
length=abs(dy);
xi=(float)dx/length;
yi=(float)dy/length;
x=x1;
y=y1;
putpixel(x,y,WHITE);
while(i<=length)
{
x=x+xi;
y=y+yi;
i++;
putpixel(int(x),int(y),WHITE);
}
getch();
closegraph();
}
No comments:
Post a Comment