-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDigitalDifferentialAnalyzer.CPP
More file actions
54 lines (42 loc) · 1.04 KB
/
Copy pathDigitalDifferentialAnalyzer.CPP
File metadata and controls
54 lines (42 loc) · 1.04 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
//Digital Differential Analyzer
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
struct point {
float x;
float y;
};
void main() {
clrscr();
int gd = DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
point beg, end, Line;
float slope;
int j, i;
cout<<"Enter co-ordinates of initial point: ";
cin>>beg.x>>beg.y;
cout<<"Enter co-ordinates of last point: ";
cin>>end.x>>end.y;
Line = beg;
////////////////////////////////////////////////
line(20, 25, 20, 454); //x-axis
line(15, 449, 619, 449); //y-axis
////////////////////////////////////////////////
slope = fabs((end.y-beg.y)/(end.x-beg.x));
if(slope <= 1) {
for(i=0; i<int(end.x-beg.x); i++) {
putpixel(Line.x, 449-Line.y, GREEN);
Line.x += 1;
Line.y += slope;
}
} else {
for(i=0; i<int(end.y-beg.y); i++) {
putpixel(Line.x, 449-Line.y, GREEN);
Line.x += 1/slope;
Line.y += 1;
}
}
getch();
closegraph();
}