-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDA.cpp
More file actions
57 lines (49 loc) · 1.15 KB
/
DDA.cpp
File metadata and controls
57 lines (49 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Ruwan Duminda Rathnayaka */
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main()
{
float x,y,x1,x2,y1,y2,dx,dy,length;
int i,gd,gm;
/*clrscr(); clrscr() will not work here because this function is old.
we will use system("cls") insted of clrscr()*/
system("cls");
/* to Read Two end points of line */
printf("Enter the value x1:\t");
scanf("%f",&x1);
printf("Enter the value y1:\t");
scanf("%f",&y1);
printf("Enter the value x2:\t");
scanf("%f",&x2);
printf("Enter the value y2:\t");
scanf("%f",&y2);
/* to initialise graphics mode. */
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
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+0.5;
y=y1+0.5;
i=1;
while(i<=length)
{
putpixel(x,y,15);
x=x+dx;
y=y+dy;
delay(100);/*delay fuction is used to suspend execution of a
program for a particular time.*/
}
getch();
closegraph();
}