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/io.c | 13 +++++++++++++ src/io/io.h | 24 ++++++++++++++++++++++++ src/io/svg.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/io/svg.h | 10 ++++++++++ src/io/text.c | 10 ++++++++++ src/io/text.h | 10 ++++++++++ 6 files changed, 119 insertions(+) create mode 100644 src/io/io.c create mode 100644 src/io/io.h create mode 100644 src/io/svg.c create mode 100644 src/io/svg.h create mode 100644 src/io/text.c create mode 100644 src/io/text.h (limited to 'src/io') diff --git a/src/io/io.c b/src/io/io.c new file mode 100644 index 0000000..e9f4fb8 --- /dev/null +++ b/src/io/io.c @@ -0,0 +1,13 @@ +#include "io.h" +#include "stdio.h" + +void pattern_nums_to_str(char *str, struct pattern *pattern) +{ + str[0] = 0; + if (pattern->length >= 1) + str += sprintf(str, "%d", pattern_point_to_index(pattern, 0)); + for (int i = 1; i < pattern->length; i++) + { + str += sprintf(str, ",%d", pattern_point_to_index(pattern, i)); + } +} \ No newline at end of file diff --git a/src/io/io.h b/src/io/io.h new file mode 100644 index 0000000..97af398 --- /dev/null +++ b/src/io/io.h @@ -0,0 +1,24 @@ +#ifndef PLOC_GEN_IO_H +#define PLOC_GEN_IO_H + +#include "pattern/pattern.h" + +/* + * Print parameters. + */ +struct print_params +{ + unsigned int count; + /* + * aggregated is true, if the print function gets called on the + * same file over and over again. + */ + bool aggregated; + bool print_count; + bool print_code; + bool print_author; +}; + +void pattern_nums_to_str(char *str, struct pattern *pattern); + +#endif \ No newline at end of file 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 diff --git a/src/io/svg.h b/src/io/svg.h new file mode 100644 index 0000000..75559a2 --- /dev/null +++ b/src/io/svg.h @@ -0,0 +1,10 @@ +#ifndef PLOC_GEN_IO_SVG_H +#define PLOC_GEN_IO_SVG_H + +#include +#include "pattern/pattern.h" +#include "io.h" + +void print_pattern_svg(FILE *out, struct print_params params, struct pattern *pattern); + +#endif \ No newline at end of file diff --git a/src/io/text.c b/src/io/text.c new file mode 100644 index 0000000..a035cc5 --- /dev/null +++ b/src/io/text.c @@ -0,0 +1,10 @@ +#include "text.h" + +void print_pattern_text(FILE *out, struct print_params params, struct pattern *pattern) +{ + for (int i = 0; i < pattern->length; i++) + { + fprintf(out, "%d,", pattern_point_to_index(pattern, i)); + } + fprintf(out, "\n"); +} \ No newline at end of file diff --git a/src/io/text.h b/src/io/text.h new file mode 100644 index 0000000..435294d --- /dev/null +++ b/src/io/text.h @@ -0,0 +1,10 @@ +#ifndef PLOC_GEN_IO_TEXT_H +#define PLOC_GEN_IO_TEXT_H + +#include +#include "pattern/pattern.h" +#include "io.h" + +void print_pattern_text(FILE *out, struct print_params params, struct pattern *pattern); + +#endif \ No newline at end of file -- cgit v1.2.3