aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorSopár Adrián <dev.adrian.sopar@protonmail.com>2022-07-05 23:02:16 +0200
committerSopár Adrián <dev.adrian.sopar@protonmail.com>2022-07-05 23:02:16 +0200
commitc5cd2b2443dc48aaeb61feac4a96071c7bc9790e (patch)
tree38f611224caf6f3e15b7121b06c1b1e9c5e129b3 /src/io
Init commit.HEADmaster
Diffstat (limited to 'src/io')
-rw-r--r--src/io/io.c13
-rw-r--r--src/io/io.h24
-rw-r--r--src/io/svg.c52
-rw-r--r--src/io/svg.h10
-rw-r--r--src/io/text.c10
-rw-r--r--src/io/text.h10
6 files changed, 119 insertions, 0 deletions
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, "<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
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 <stdio.h>
+#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 <stdio.h>
+#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