aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-19 21:16:19 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:50:30 +0200
commit801b92b6d788d9f693612c0120e96b6b1ceb0e0a (patch)
tree51bbca6cd07622eb7009aa0f18f932daf7af728a
parentf413600120ea988386d06d8266d16b56933ab75e (diff)
downloadchilbert-801b92b6d788d9f693612c0120e96b6b1ceb0e0a.tar.gz
chilbert-801b92b6d788d9f693612c0120e96b6b1ceb0e0a.tar.bz2
chilbert-801b92b6d788d9f693612c0120e96b6b1ceb0e0a.zip
Add example programs
-rw-r--r--bin/chilbert_obj.cpp54
-rw-r--r--bin/chilbert_svg.cpp63
2 files changed, 117 insertions, 0 deletions
diff --git a/bin/chilbert_obj.cpp b/bin/chilbert_obj.cpp
new file mode 100644
index 0000000..85fe95a
--- /dev/null
+++ b/bin/chilbert_obj.cpp
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2018 David Robillard <d@drobilla.net>
+
+ This program is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include "chilbert/chilbert.hpp"
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const unsigned long num_points = std::strtoul(argv[1], nullptr, 10);
+ if (num_points == 0 || num_points == ULONG_MAX) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ // Vertices
+ for (uint64_t i = 0; i < num_points; ++i) {
+ std::array<uint32_t, 3> point;
+ chilbert::index_to_coords(point.data(), 16, 3, i);
+ printf("v %u %u %u\n", point[0], point[1], point[2]);
+ }
+
+ // One polyline through all vertices
+ printf("\nl");
+ for (unsigned i = 0; i < num_points - 1; ++i) {
+ printf(" %u", i + 1);
+ }
+ printf("\n");
+
+ return 0;
+}
diff --git a/bin/chilbert_svg.cpp b/bin/chilbert_svg.cpp
new file mode 100644
index 0000000..7c63042
--- /dev/null
+++ b/bin/chilbert_svg.cpp
@@ -0,0 +1,63 @@
+/*
+ Copyright (C) 2018 David Robillard <d@drobilla.net>
+
+ This program is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include "chilbert/chilbert.hpp"
+
+#include <array>
+#include <cmath>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const unsigned long num_points = std::strtoul(argv[1], nullptr, 10);
+ if (num_points == 0 || num_points == ULONG_MAX) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const uint32_t w =
+ uint32_t(sqrt(1 << uint32_t(ceil(log2(num_points))))) - 1;
+
+ // Header
+ printf("<svg xmlns='http://www.w3.org/2000/svg'"
+ " version='1.2' baseProfile='tiny' viewBox='0 0 %u %u'>\n",
+ w,
+ w);
+ printf("<desc>Hilbert Curve</desc>\n");
+ printf("<polyline vector-effect='non-scaling-stroke' fill='none' "
+ "stroke='black' stroke-width='1' points='");
+
+ // One polyline through all vertices
+ for (uint64_t i = 0; i <= num_points; ++i) {
+ std::array<uint32_t, 2> point;
+ chilbert::index_to_coords(point.data(), 32, 2, i);
+ printf("%u,%u ", point[0], point[1]);
+ }
+
+ // Close off document
+ printf("' />\n</svg>\n");
+
+ return 0;
+}