-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawLine.cpp
More file actions
58 lines (43 loc) · 1.04 KB
/
DrawLine.cpp
File metadata and controls
58 lines (43 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
55
56
#include <stdio.h>
#include <conio.h>
#include "graphics.h"
#include <math.h>
#include <dos.h>
int main() {
// request auto detection
int gdriver = DETECT, gmode, err;
int i, x1, y1, x2, y2, dX, dY, steps;
float x, y, xI, yI;
// initialize graphic mode
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != grOk) {
// error occurred
printf("Graphic Error: %s\n",
grapherrormsg(err));
getch();
return 0;
}
// draw line from (0, 0) to x-axis & y-axis maximum
x1 = y1 = 0;
x2 = getmaxx(), y2 = getmaxy();
dX = x2 - x1;
dY = y2 - y1;
x = x1, y = y1;
steps = abs(dX) > abs(dY) ? dX : dY;
xI = (1.0 * dX) / steps;
yI = (1.0 * dY) / steps;
putpixel((int)x, (int)y, WHITE);
// find the x and y successors and plot the pixels
for (i = 0; i < steps; i++) {
x = x + xI;
y = y + yI;
// put a pixel at the given postion(x, y)
putpixel((int)x, (int)y, WHITE);
// sleep for 10 milliseconds
delay(10);
}
// deallocate memory allocated for graphic screen
closegraph();
return 0;
}