-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdda-line-drawing.cpp
More file actions
52 lines (45 loc) · 934 Bytes
/
dda-line-drawing.cpp
File metadata and controls
52 lines (45 loc) · 934 Bytes
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
#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;
int main()
{
int gd = DETECT, gm, x1, y1, x2, y2, k, j;
float x, y, xi, yi, s, dx, dy;
initgraph(&gd, &gm, "C:\\TC\\BGI");
//cout<<"Enter x1 y1: ";
//cin>>x1>>y1;
//cout<<"Enter x2 y2: ";
//cin>>x2>>y2;
x1 = y1 = 100;
x2 = y2 = 200;
for(int i=0, j=1; i<4; i++, j++) {
dx = x2 - x1;
dy = y2 - y1;
putpixel(x, y, 8);
s = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
xi = dx/ s;
yi = dy/ s;
x = x1;
y = y1;
for(k=0; k<s; k++)
{
x += xi;
y += yi;
putpixel(int(x + 0.5), int(y + 0.5), 14);
//delay(20);
}
x1 = x2;
y1 = y2;
if(j%2==0) {
x2 += 100;
y2 += 100;
}
else {
x2 -= 100;
y2 += 100;
}
}
getch();
closegraph();
}