dda line program


/*dda algorithm program*/
#include<stdlib.h>
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<math.h>
#include<dos.h>

int   main()
{clrscr();
float i,x,y,x1,y1,x2,y2,dx,dy,length;

printf("enter the value of x1:\t");
scanf("%f",&x1);
 printf("enter the value of y1:\t");
scanf("%f",&y1);
printf("enter the value of x2:\t");
scanf("%f",&x2);
printf("enter the value of y2:\t");
scanf("%f",&y2);
int gdrives=DETECT,gmode;
initgraph(&gdrives,&gmode,"f:\\tc\\bin\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
{
length=dx;
}
else
{
length=dy;
}
dx=(x2-x1)/length;
dy=(y2-y1)/length;
x=x1+.5;
y=y1+.5;
i=1;

while(i<=length)
{
putpixel(x,y,10);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
getch();
closegraph();
}

Comments

Popular posts from this blog

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)