-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoving-wheel-graphics.c
116 lines (93 loc) · 1.96 KB
/
moving-wheel-graphics.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
int l = 1;
void ddaline(int x1, int y1, int x2, int y2) //DDA Line Algorithm continues
{
int s, dx, dy, m;
float xi, yi, x, y;
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy))
s = abs(dx);
else
s = abs(dy);
xi = dx / (float) s;
yi = dy / (float) s;
x = x1;
y = y1;
putpixel(x1 + 0.5, y1 + 0.5, 15);
for (m = 0; m < s; m++) {
x += xi;
y += yi;
putpixel(x + 0.5, y + 0.5, 15);
}
}
void plotpoints1(int x, int y, int vx, int vy)
{
putpixel(vx + x, vy + y, 15); //putpixel plots a point in the color defined by color at (x,y)
putpixel(vx - x, vy - y, 15);
putpixel(vx - y, vy + x, 15);
putpixel(vx + y, vy - x, 15);
if (l % 20 == 0) {
ddaline(vx - x, vy - y, vx + x, vy + y);
ddaline(vx - y, vy + x, vx + y, vy - x);
}
l++;
}
void plotpoints2(int x, int y, int vx, int vy)
{
putpixel(vx - x, vy + y, 15);
putpixel(vx + x, vy - y, 15);
putpixel(vx + y, vy + x, 15);
putpixel(vx - y, vy - x, 15);
if (l % 20 == 0) {
ddaline(vx + x, vy - y, vx - x, vy + y);
ddaline(vx - y, vy - x, vx + y, vy + x);
}
l++;
}
void mcircle(int vx, int vy, int r) //Mid point circle Algorithm calling
{
int x = 0, y, p;
y = r;
p = 1 - r;
while (x < y) {
plotpoints1(x, y, vx, vy);
x++;
if (p < 0)
p += 2 * x + 1;
else {
y--;
p += 2 * (x - y) + 1;
}
}
x = y + 1;
while (abs(x) > 0) {
plotpoints2(x, y, vx, vy);
x--;
if (p >= 0)
p = p - 2 * x - 1;
else {
y++;
p = p - 2 * (x - y) - 1;
}
}
}
void main()
{
int gd = DETECT, gm = DETECT;
int i = 0;
initgraph(&gd, &gm, "");
while (!kbhit()) {
if (i > 640)
i = -200;
cleardevice();
mcircle(100 + (i++), 200, 100);
delay(90); // delay
i++;
}
getch();
}