aboutsummaryrefslogtreecommitdiff
path: root/src/io/svg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/svg.c')
-rw-r--r--src/io/svg.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/io/svg.c b/src/io/svg.c
new file mode 100644
index 0000000..a8e2129
--- /dev/null
+++ b/src/io/svg.c
@@ -0,0 +1,52 @@
+#include "svg.h"
+
+void print_pattern_svg(FILE *out, struct print_params params, struct pattern *pattern)
+{
+ // Init variables.
+ double horizontal = 100 / (pattern->type.height + 1);
+ double vertical = 100 / (pattern->type.width + 1);
+ int hd = horizontal; // Horizontal distance
+ int vd = vertical; // Vertical distance
+ // Print
+ fprintf(out, "<svg width=\"500\" height=\"500\" style=\"background-color:black\">");
+ fprintf(out, "<rect width=\"100%%\" height=\"100%%\" fill=\"black\" />");
+
+ if (params.print_code)
+ {
+ char code[128];
+ pattern_nums_to_str(code, pattern);
+ fprintf(out, "<text x=\"0\" y=\"1em\" font-size=\"2em\" fill=\"white\">Code:%s</text>", code);
+ }
+ if (params.print_count)
+ fprintf(out, "<text x=\"0\" y=\"2em\" font-size=\"2em\" fill=\"white\">Count:%d</text>", params.count);
+ if (params.print_author)
+ fprintf(out, "<text x=\"500\" y=\"500\" font-size=\"1em\" fill=\"white\" text-anchor=\"end\">adriansopar.hu</text>");
+
+ // TODO: Print text!
+ // Print points.
+ for (int y = 0; y < pattern->type.height; y++)
+ {
+ for (int x = 0; x < pattern->type.width; x++)
+ {
+ fprintf(out,
+ "<circle cx=\"%f%%\" cy=\"%f%%\" r=\"%d%%\" fill=\"white\" />",
+ (double)(x + 1) * hd, (double)(y + 1) * vd, 3);
+ }
+ }
+ // Print pattern.
+ struct coord prev;
+ for (int i = 0; i < pattern->length; i++)
+ {
+ struct coord current = pattern->path[i];
+ fprintf(out,
+ "<circle cx=\"%f%%\" cy=\"%f%%\" r=\"6%%\" stroke=\"#00ff00\" stroke-width=\"2\" fill=\"none\" />",
+ (double)(current.x + 1) * hd, (double)(current.y + 1) * vd);
+ if (i > 0)
+ fprintf(out,
+ "<line x1=\"%f%%\" y1=\"%f%%\" x2=\"%f%%\" y2=\"%f%%\" stroke=\"white\" stroke-width=\"6%%\" stroke-opacity=\"0.5\" />",
+ (double)(prev.x + 1) * hd, (double)(prev.y + 1) * vd,
+ (double)(current.x + 1) * hd, (double)(current.y + 1) * vd);
+ prev = current;
+ }
+ fprintf(out, "</svg>");
+} \ No newline at end of file