From c5cd2b2443dc48aaeb61feac4a96071c7bc9790e Mon Sep 17 00:00:00 2001 From: Sopár Adrián Date: Tue, 5 Jul 2022 23:02:16 +0200 Subject: Init commit. --- src/io/svg.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/io/svg.c (limited to 'src/io/svg.c') 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, ""); + fprintf(out, ""); + + if (params.print_code) + { + char code[128]; + pattern_nums_to_str(code, pattern); + fprintf(out, "Code:%s", code); + } + if (params.print_count) + fprintf(out, "Count:%d", params.count); + if (params.print_author) + fprintf(out, "adriansopar.hu"); + + // 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, + "", + (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, + "", + (double)(current.x + 1) * hd, (double)(current.y + 1) * vd); + if (i > 0) + fprintf(out, + "", + (double)(prev.x + 1) * hd, (double)(prev.y + 1) * vd, + (double)(current.x + 1) * hd, (double)(current.y + 1) * vd); + prev = current; + } + fprintf(out, ""); +} \ No newline at end of file -- cgit v1.2.3