-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_shape.c
285 lines (259 loc) · 7.73 KB
/
func_shape.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "img.h"
void img_drawCirclePoint(struct color c, int x, int y, int r, double degree);
void img_drawCircle(struct color c, int r);
void img_drawCircle2(struct color c, int x, int y, int r);
void img_fillCircle(struct color c, double x, double y, double r);
void img_fillCircle2(struct color c, double x, double y, double r, int min_deg, int max_deg);
void img_fillRectangle(struct color c, int x1, int y1, int width, int height);
void img_drawLine(struct color c, double a, int b, int x1, int x2);
void img_drawLinePolar(struct color c, int ox, int oy, double r, double t);
void img_drawCycloidPoint(struct color c, int a, int dx, int dy, double degree);
void img_drawCycloidPoint2(struct color c, int a, int dx, int dy, double degree, int bold);
void img_drawCycloidPointRev(struct color c, int a, int dx, int dy, double degree);
void img_drawCycloidPointRev2(struct color c, int a, int dx, int dy, double degree, int bold);
void img_drawCycloidRev(struct color c, int a, int dx, int dy, double degree);
void img_drawCycloid(struct color c, int a, double num);
void img_drawCycloid2(struct color c, int a, int dx, int dy, double num);
void img_drawCycloid3(struct color c, int a, int dx, int dy, double degree);
void img_drawTrochoidPoint(struct color c, int a, int b, double degree);
void img_drawTrochoidPoint2(struct color c, int dx, int dy, int a, int b, double degree, int bold);
void img_drawTrochoid(struct color c, int a, int b, double num);
void img_drawTrochoid2(struct color c, int x, int y, int a, int b, double degree);
void img_drawTrochoidPointRev(struct color c, int dx, int dy, int a, int b, double degree);
void img_drawTrochoidPointRev2(struct color c, int dx, int dy, int a, int b, double degree, int bold);
void img_drawTrochoidRev(struct color c, int x, int y, int a, int b, double degree);
double getRadian(double x, double y, double x2, double y2);
double PI();
double PI_2();
double PI_4();
void img_drawCirclePoint(struct color c, int x, int y, int r, double degree)
{
int x2, y2;
double radian;
radian = degree * PI() / 180.0;
x2 = r * cos(radian) + x;
y2 = r * sin(radian) + y;
img_putpixel(c, x2, y2);
}
void img_drawCircle(struct color c, int r)
{
img_drawCircle2(c, r, 0, 0);
}
void img_drawCircle2(struct color c, int x, int y, int r)
{
double degree;
for (degree = 0; degree < 360; degree += 0.1)
{
img_drawCirclePoint(c, x, y, r, degree);
}
}
void img_fillCircle(struct color c, double x, double y, double r)
{
int imin = (int)(x - r - 1), imax = (int)(x + r + 1);
int jmin = (int)(y - r - 1), jmax = (int)(y + r + 1);
int i, j;
for (j = jmin; j <= jmax; ++j)
{
for (i = imin; i <= imax; ++i)
{
if ((x - i) * (x - i) + (y - j) * (y - j) <= r * r)
{
img_putpixel(c, i, j);
}
}
}
}
void img_fillCircle2(struct color c, double x, double y, double r, int min_deg, int max_deg)
{
int imin = (int)(x - r - 1), imax = (int)(x + r + 1);
int jmin = (int)(y - r - 1), jmax = (int)(y + r + 1);
int i, j;
for (j = jmin; j <= jmax; ++j)
{
for (i = imin; i <= imax; ++i)
{
if ((x - i) * (x - i) + (y - j) * (y - j) <= r * r)
{
double radian = getRadian(x, y, i, j);
int degree = radian * 180 / PI();
if (min_deg <= degree && degree <= max_deg)
{
img_putpixel(c, i, j);
}
}
}
}
}
void img_fillRectangle(struct color c, int x1, int y1, int width, int height)
{
int dx, dy, x, y;
for (dx = 0; dx <= width; dx++)
{
for (dy = 0; dy <= height; dy++)
{
x = x1 + dx;
y = y1 + dy;
img_putpixel(c, x, y);
}
}
}
void img_drawLine(struct color c, double a, int b, int x1, int x2)
{
int y;
for (; x1 <= x2; x1++)
{
y = a * x1 + b;
img_putpixel(c, x1, y);
}
}
void img_drawLinePolar(struct color c, int ox, int oy, double r /*radius*/, double t/*theta*/) {
int x, y;
int i;
for (i = 0; i <= r; i++) {
x = ox + i * cos(t);
y = oy + i * sin(t);
img_putpixel(c, x, y);
}
}
void img_drawCycloidPoint(struct color c, int a, int dx, int dy, double degree)
{
int x, y;
double radian;
radian = degree * PI() / 180.0;
x = a * (radian - sin(radian)) + dx;
y = a * (1 - cos(radian)) + dy;
img_putpixel(c, x, y);
}
void img_drawCycloidPoint2(struct color c, int a, int dx, int dy, double degree, int bold)
{
int x, y;
double radian;
radian = degree * PI() / 180.0;
x = a * (radian - sin(radian)) + dx;
y = a * (1 - cos(radian)) + dy;
img_fillCircle(c, x, y, bold);
}
void img_drawCycloidPointRev(struct color c, int a, int dx, int dy, double degree)
{
img_drawCycloidPointRev2(c, a, dx, dy, degree, 0);
}
void img_drawCycloidPointRev2(struct color c, int a, int dx, int dy, double degree, int bold)
{
int x, y, X, Y;
double radian;
radian = degree * PI() / 180.0;
x = a * (radian - sin(radian));
y = a * (1 - cos(radian));
X = -x + dx;
Y = -y + dy;
img_fillCircle(c, X, Y, bold);
}
void img_drawCycloidRev(struct color c, int a, int dx, int dy, double degree)
{
double t;
for (t = 0; t <= degree; t += 0.1)
{
img_drawCycloidPointRev(c, a, dx, dy, t);
}
}
void img_drawCycloid(struct color c, int a, double num)
{
img_drawCycloid2(c, a, 0, 0, num);
}
void img_drawCycloid2(struct color c, int a, int dx, int dy, double num)
{
double degree;
for (degree = 0; degree < 360 * num; degree += 0.1)
{
img_drawCycloidPoint(c, a, dx, dy, degree);
}
}
void img_drawCycloid3(struct color c, int a, int dx, int dy, double degree)
{
double degree2;
for (degree2 = 0; degree2 <= degree; degree2 += 0.1)
{
img_drawCycloidPoint(c, a, dx, dy, degree2);
}
}
void img_drawTrochoidPoint(struct color c, int a, int b, double degree)
{
img_drawTrochoidPoint2(c, 0, 0, a, b, degree, 0);
}
void img_drawTrochoidPoint2(struct color c, int dx, int dy, int a, int b, double degree, int bold)
{
if (a <= 0)
{
return;
}
int x, y;
double radian;
radian = degree * PI() / 180.0;
x = a * radian - b * sin(radian) + dx;
y = a - b * cos(radian) + dy;
img_fillCircle(c, x, y, bold);
}
void img_drawTrochoid(struct color c, int a, int b, double num)
{
double degree;
for (degree = 0; degree < 360 * num; degree += 0.1)
{
img_drawTrochoidPoint(c, a, b, degree);
}
}
void img_drawTrochoid2(struct color c, int x, int y, int a, int b, double degree)
{
double degree2;
for (degree2 = 0; degree2 <= degree; degree2 += 0.1)
{
img_drawTrochoidPoint2(c, x, y, a, b, degree2, 0);
}
}
void img_drawTrochoidPointRev(struct color c, int dx, int dy, int a, int b, double degree)
{
img_drawTrochoidPointRev2(c, dx, dy, a, b, degree, 0);
}
void img_drawTrochoidPointRev2(struct color c, int dx, int dy, int a, int b, double degree, int bold)
{
if (a <= 0)
{
return;
}
int x, y, X, Y;
double radian;
radian = degree * PI() / 180.0;
x = a * radian - b * sin(radian);
y = a - b * cos(radian);
X = -x + dx;
Y = -y + dy;
img_fillCircle(c, X, Y, bold);
}
void img_drawTrochoidRev(struct color c, int x, int y, int a, int b, double degree)
{
double t;
for (t = 0; t <= degree; t += 0.1)
{
img_drawTrochoidPointRev(c, x, y, a, b, t);
}
}
double getRadian(double x, double y, double x2, double y2)
{
double radian = atan2(y2 - y, x2 - x);
return radian;
}
double PI()
{
return M_PI;
}
double PI_2()
{
return M_PI_2;
}
double PI_4()
{
return M_PI_4;
}