-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg.cpp
43 lines (35 loc) · 1.01 KB
/
svg.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
#include <bits/stdc++.h>
using namespace std;
#include "primitives.cpp"
//NO_LONGLINES_CHECK
//BEGIN_CODE
struct SVG {
FILE *out;
ld sc = 50;
void open() {
out = fopen("image.svg", "w");
fprintf(out, "<svg xmlns='http://www.w3.org/2000/svg' viewBox='-1000 -1000 2000 2000'>\n");
}
void line(pt a, pt b) {
a = a * sc, b = b * sc;
fprintf(out, "<line x1='%Lf' y1='%Lf' x2='%Lf' y2='%Lf' stroke='black'/>\n", a.x, -a.y, b.x, -b.y);
}
void circle(pt a, ld r = -1, string col = "red") {
r = (r == -1 ? 10 : sc * r);
a = a * sc;
fprintf(out, "<circle cx='%Lf' cy='%Lf' r='%Lf' fill='%s'/>\n", a.x, -a.y, r, col.c_str());
}
void text(pt a, string s) {
a = a * sc;
fprintf(out, "<text x='%Lf' y='%Lf' font-size='10px'>%s</text>\n", a.x, -a.y, s.c_str());
}
void close() {
fprintf(out, "</svg>\n");
fclose(out);
out = 0;
}
~SVG() {
if (out)
close();
}
} svg;