#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void dda(int,int,int,int);
int main()
{
int xa,ya,xb,yb;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
//initwindow(1200,721);
printf("\n\n Enter Xa:");
scanf("%d",&xa);
printf("\n\n Enter Ya:");
scanf("%d",&ya);
printf("\n\n Enter Xb:");
scanf("%d",&xb);
printf("\n\n Enter Yb:");
scanf("%d",&yb);
outtextxy(900,200,"LINE IS");
dda(xa,ya,xb,yb);
getch();
closegraph();
return 0;
}
void dda(int x1,int y1,int x2,int y2)
{
int x=x1,y=y1,dx,dy,m;
int i;
dx=(x1-x2);
dy=(y1-y2);
if(abs(dx)>abs(dy))
{
m=abs(dx);
}
else
{
m=abs(dy);
}
putpixel(x,y,15);
for(i=0;i<m;i++)
{
x=x+(dx/m);
y=y+(dy/m);
putpixel(x,y,i+2);
}
}
#include<graphics.h>
#include<conio.h>
#include<math.h>
void dda(int,int,int,int);
int main()
{
int xa,ya,xb,yb;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
//initwindow(1200,721);
printf("\n\n Enter Xa:");
scanf("%d",&xa);
printf("\n\n Enter Ya:");
scanf("%d",&ya);
printf("\n\n Enter Xb:");
scanf("%d",&xb);
printf("\n\n Enter Yb:");
scanf("%d",&yb);
outtextxy(900,200,"LINE IS");
dda(xa,ya,xb,yb);
getch();
closegraph();
return 0;
}
void dda(int x1,int y1,int x2,int y2)
{
int x=x1,y=y1,dx,dy,m;
int i;
dx=(x1-x2);
dy=(y1-y2);
if(abs(dx)>abs(dy))
{
m=abs(dx);
}
else
{
m=abs(dy);
}
putpixel(x,y,15);
for(i=0;i<m;i++)
{
x=x+(dx/m);
y=y+(dy/m);
putpixel(x,y,i+2);
}
}
No comments:
Post a Comment