Program To Draw Lines in Given Co-Ordinates Using DDA Algorithm
Program To Draw Lines in Given Co-Ordinates Using DDA Algorithm
algorithm */
Source Code
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
float x,y,x1,y1,x2,y2,dx,dy,length,a,b;
int i,gd=DETECT,gm;
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);
initgraph(&gd,&gm,"c:\\tc\\bgi");
a=getmaxx();
b=getmaxy();
line(a/2,0,a/2,b);
line(0,b/2,a,b/2);
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;/*factor .5 is added to round the values*/
y=y1+.5;/*factor .5 is added to round the values*/
i=1;
while(i<=length)
{
putpixel((a/2)+x,(b/2)-y,15);
x=x+dx;
y=y+dy;
i=i+1;
}
getch();
}
Output:
IIMT ENGINEERING COLLEGE
MEERUT
Computer Graphics
Lab File
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Index