-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacro.cpp
387 lines (310 loc) · 12 KB
/
macro.cpp
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
using namespace std;
//----------- p5visualizerのマクロ Version 1.1(ここから) -------------
#define VISUALIZE // 提出時にはここをコメントアウトすること。そうしないとTLEする。
#ifdef VISUALIZE
std::ofstream sVisStream("VisCommands.txt");
// ビジュアライザ上で表示される時間を指定します
inline void time(int t) {
sVisStream << "time = " << t << ";" << std::endl;
}
// ビジュアライザ上で常に表示されます
inline void always() {
time(-1);
}
inline void setSingleColor(int colorOrGray, int alpha = 255) {
sVisStream << colorOrGray;
if (alpha < 255) {
sVisStream << ", " << alpha;
}
}
inline void setRGBColor(int r, int g, int b, int alpha = 255) {
sVisStream << r << ", " << g << ", " << b;
if (alpha < 255) {
sVisStream << ", " << alpha;
}
}
// リファレンス https://p5js.org/reference/
// Web上のエディタ https://editor.p5js.org/
//---------- Shape : 2D Primitives ----------
inline void arc(float x, float y, float w, float h, float start, float stop) {
sVisStream << "arc(" << x << ", " << y << ", " << w << ", " << h << ", " << start << ", " << stop << ");" << std::endl;
}
inline void ellipse(float x, float y, float w, float h) {
sVisStream << "ellipse(" << x << ", " << y << ", " << w << ", " << h << ");" << std::endl;
}
inline void circle(float x, float y, float d) {
sVisStream << "circle(" << x << ", " << y << ", " << d << ");" << std::endl;
}
inline void line(float x1, float y1, float x2, float y2) {
sVisStream << "line(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ");" << std::endl;
}
inline void point(float x, float y) {
sVisStream << "point(" << x << ", " << y << ");" << std::endl;
}
inline void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
sVisStream << "quad(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ", " << x3 << ", " << y3 << ", " << x4 << ", " << y4 << ");" << std::endl;
}
inline void rect(float x, float y, float w, float h) {
sVisStream << "rect(" << x << ", " << y << ", " << w << ", " << h << ");" << std::endl;
}
inline void square(float x, float y, float s) {
sVisStream << "square(" << x << ", " << y << ", " << s << ");" << std::endl;
}
inline void triangle(float x1, float y1, float x2, float y2, float x3, float y3) {
sVisStream << "triangle(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ", " << x3 << ", " << y3 << ");" << std::endl;
}
//---------- Shape : Attributes ----------
inline void ellipseMode(const std::string& mode) {
sVisStream << "ellipseMode(" << mode << ");" << std::endl;
}
inline void noSmooth() {
sVisStream << "noSmooth();" << std::endl;
}
inline void rectMode(const std::string& mode) {
sVisStream << "rectMode(" << mode << ");" << std::endl;
}
inline void smooth() {
sVisStream << "smooth();" << std::endl;
}
inline void strokeCap(const std::string& cap) {
sVisStream << "strokeCap(" << cap << ");" << std::endl;
}
inline void strokeJoin(const std::string& join) {
sVisStream << "strokeJoin(" << join << ");" << std::endl;
}
inline void strokeWeight(float weight) {
sVisStream << "strokeWeight(" << weight << ");" << std::endl;
}
//---------- Shape : Curves ----------
inline void bezier(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
sVisStream << "bezier(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ", "
<< x3 << ", " << y3 << ", " << x4 << ", " << y4 << ");" << std::endl;
}
inline void bezierDetail(int detail) {
sVisStream << "bezierDetail(" << detail << ");" << std::endl;
}
inline void bezierPoint(float a, float b, float c, float d, float t) {
sVisStream << "bezierPoint(" << a << ", " << b << ", " << c << ", " << d << ", " << t << ");" << std::endl;
}
inline void bezierTangent(float a, float b, float c, float d, float t) {
sVisStream << "bezierTangent(" << a << ", " << b << ", " << c << ", " << d << ", " << t << ");" << std::endl;
}
inline void curve(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
sVisStream << "curve(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ", "
<< x3 << ", " << y3 << ", " << x4 << ", " << y4 << ");" << std::endl;
}
inline void curveDetail(int detail) {
sVisStream << "curveDetail(" << detail << ");" << std::endl;
}
inline void curveTightness(float tightness) {
sVisStream << "curveTightness(" << tightness << ");" << std::endl;
}
inline void curvePoint(float a, float b, float c, float d, float t) {
sVisStream << "curvePoint(" << a << ", " << b << ", " << c << ", " << d << ", " << t << ");" << std::endl;
}
inline void curveTangent(float a, float b, float c, float d, float t) {
sVisStream << "curveTangent(" << a << ", " << b << ", " << c << ", " << d << ", " << t << ");" << std::endl;
}
//---------- Shape : Vertex ----------
inline void beginContour() {
sVisStream << "beginContour();" << std::endl;
}
inline void beginShape(const std::string& mode = "") {
if (!mode.empty()) {
sVisStream << "beginShape(\"" << mode << "\");" << std::endl;
} else {
sVisStream << "beginShape();" << std::endl;
}
}
inline void bezierVertex(float x1, float y1, float x2, float y2, float x3, float y3) {
sVisStream << "bezierVertex(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ", " << x3 << ", " << y3 << ");" << std::endl;
}
inline void curveVertex(float x, float y) {
sVisStream << "curveVertex(" << x << ", " << y << ");" << std::endl;
}
inline void endContour() {
sVisStream << "endContour();" << std::endl;
}
inline void endShape(const std::string& mode = "") {
if (!mode.empty()) {
sVisStream << "endShape(\"" << mode << "\");" << std::endl;
} else {
sVisStream << "endShape();" << std::endl;
}
}
inline void quadraticVertex(float cx, float cy, float x, float y) {
sVisStream << "quadraticVertex(" << cx << ", " << cy << ", " << x << ", " << y << ");" << std::endl;
}
inline void vertex(float x, float y) {
sVisStream << "vertex(" << x << ", " << y << ");" << std::endl;
}
//---------- Color : Setting ----------
inline void background(int gray, int alpha = 255) {
sVisStream << "background(";
setSingleColor(gray, alpha);
sVisStream << ");" << std::endl;
}
inline void background(int r, int g, int b, int alpha = 255) {
sVisStream << "background(";
setRGBColor(r, g, b, alpha);
sVisStream << ");" << std::endl;
}
inline void background(const std::string& value) {
sVisStream << "background(\"" << value << "\");" << std::endl;
}
inline void clear() {
sVisStream << "clear();" << std::endl;
}
inline void colorMode(const std::string& mode, int max1, int max2, int max3, int maxA) {
sVisStream << "colorMode(" << mode << ", " << max1 << ", " << max2 << ", " << max3 << ", " << maxA << ");" << std::endl;
}
inline void fill(int gray, int alpha = 255) {
sVisStream << "fill(";
setSingleColor(gray, alpha);
sVisStream << ");" << std::endl;
}
inline void fill(int r, int g, int b, int alpha = 255) {
sVisStream << "fill(";
setRGBColor(r, g, b, alpha);
sVisStream << ");" << std::endl;
}
inline void fill(const std::string& value) {
sVisStream << "fill(\"" << value << "\");" << std::endl;
}
inline void noFill() {
sVisStream << "noFill();" << std::endl;
}
inline void noStroke() {
sVisStream << "noStroke();" << std::endl;
}
inline void stroke(int gray, int alpha = 255) {
sVisStream << "stroke(";
setSingleColor(gray, alpha);
sVisStream << ");" << std::endl;
}
inline void stroke(int r, int g, int b, int alpha = 255) {
sVisStream << "stroke(";
setRGBColor(r, g, b, alpha);
sVisStream << ");" << std::endl;
}
inline void stroke(const std::string& value) {
sVisStream << "stroke(\"" << value << "\");" << std::endl;
}
inline void erase() {
sVisStream << "erase();" << std::endl;
}
inline void noErase() {
sVisStream << "noErase();" << std::endl;
}
//---------- Structure ----------
inline void push() {
sVisStream << "push();" << std::endl;
}
inline void pop() {
sVisStream << "pop();" << std::endl;
}
//---------- Typography ----------
inline void textAlign(const std::string& alignX, const std::string& alignY = "") {
if (alignY.empty()) {
sVisStream << "textAlign(" << alignX << ");" << std::endl;
} else {
sVisStream << "textAlign(" << alignX << ", " << alignY << ");" << std::endl;
}
}
inline void textLeading(float leading) {
sVisStream << "textLeading(" << leading << ");" << std::endl;
}
inline void textSize(float size) {
sVisStream << "textSize(" << size << ");" << std::endl;
}
inline void textStyle(const std::string& style) {
sVisStream << "textStyle(" << style << ");" << std::endl;
}
inline void textAscent() {
sVisStream << "textAscent();" << std::endl;
}
inline void textDescent() {
sVisStream << "textDescent();" << std::endl;
}
inline void textWrap(const std::string& wrap) {
sVisStream << "textWrap(\"" << wrap << "\");" << std::endl;
}
inline void text(const std::string& str, float x, float y) {
sVisStream << "text(\"" << str << "\", " << x << ", " << y << ");" << std::endl;
}
inline void textFont(const std::string& fontName) {
sVisStream << "textFont(\"" << fontName << "\");" << std::endl;
}
#else // VISUALIZE
inline void time(int t) {}
inline void always() {}
inline void setSingleColor(int, int = 255) {}
inline void setRGBColor(int, int, int, int = 255) {}
//---------- Shape : 2D Primitives ----------
inline void arc(float, float, float, float, float, float) {}
inline void ellipse(float, float, float, float) {}
inline void circle(float, float, float) {}
inline void line(float, float, float, float) {}
inline void point(float, float) {}
inline void quad(float, float, float, float, float, float, float, float) {}
inline void rect(float, float, float, float) {}
inline void square(float, float, float) {}
inline void triangle(float, float, float, float, float, float) {}
//---------- Shape : Attributes ----------
inline void ellipseMode(const std::string&) {}
inline void noSmooth() {}
inline void rectMode(const std::string&) {}
inline void smooth() {}
inline void strokeCap(const std::string&) {}
inline void strokeJoin(const std::string&) {}
inline void strokeWeight(float) {}
//---------- Shape : Curves ----------
inline void bezier(float, float, float, float, float, float, float, float) {}
inline void bezierDetail(int) {}
inline void bezierPoint(float, float, float, float, float) {}
inline void bezierTangent(float, float, float, float, float) {}
inline void curve(float, float, float, float, float, float, float, float) {}
inline void curveDetail(int) {}
inline void curveTightness(float) {}
inline void curvePoint(float, float, float, float, float) {}
inline void curveTangent(float, float, float, float, float) {}
//---------- Shape : Vertex ----------
inline void beginContour() {}
inline void beginShape(const std::string & = "") {}
inline void bezierVertex(float, float, float, float, float, float) {}
inline void curveVertex(float, float) {}
inline void endContour() {}
inline void endShape(const std::string & = "") {}
inline void quadraticVertex(float, float, float, float) {}
inline void vertex(float, float) {}
//---------- Color : Setting ----------
inline void background(int, int = 255) {}
inline void background(int, int, int, int = 255) {}
inline void background(const std::string&) {}
inline void clear() {}
inline void colorMode(const std::string&, int, int, int, int = 0) {}
inline void fill(int, int = 255) {}
inline void fill(int, int, int, int = 255) {}
inline void fill(const std::string&) {}
inline void noFill() {}
inline void noStroke() {}
inline void stroke(int, int = 255) {}
inline void stroke(int, int, int, int = 255) {}
inline void stroke(const std::string&) {}
inline void erase() {}
inline void noErase() {}
//---------- Structure ----------
inline void push() {}
inline void pop() {}
//---------- Typography ----------
inline void textAlign(const std::string&, const std::string & = "") {}
inline void textLeading(float) {}
inline void textSize(float) {}
inline void textStyle(const std::string&) {}
inline void textAscent() {}
inline void textDescent() {}
inline void textWrap(const std::string&) {}
inline void text(const std::string&, float, float) {}
inline void textFont(const std::string&) {}
#endif // VISUALIZE
//----------- p5visualizerのマクロ(ここまで) -------------