aboutsummaryrefslogtreecommitdiff
path: root/unit_circle.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-05-20 23:53:22 +0200
committerAdrian Kummerlaender2016-05-20 23:53:22 +0200
commitfefb5de652f3f07eda7bfb79ebb0134b64e5bd19 (patch)
treea5271847547d68b4265047d3ff9e9c0e367d6217 /unit_circle.cc
parentd87a9b0960ddd4397325fe7240b484ec9f79e7af (diff)
downloadvoronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar.gz
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar.bz2
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar.lz
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar.xz
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.tar.zst
voronoi-fefb5de652f3f07eda7bfb79ebb0134b64e5bd19.zip
Implement unit circle example
`unit_circle.sh` generates a animated GIF of the circle states between p=1 and p=3.
Diffstat (limited to 'unit_circle.cc')
-rw-r--r--unit_circle.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/unit_circle.cc b/unit_circle.cc
new file mode 100644
index 0000000..283fb53
--- /dev/null
+++ b/unit_circle.cc
@@ -0,0 +1,39 @@
+#include <imgen.h>
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+
+int p_norm(double p, int x, int y) {
+ return static_cast<int>(std::nearbyint(
+ std::pow(
+ std::pow(std::abs(x), p) + std::pow(std::abs(y), p),
+ 1.0 / p
+ )
+ ));
+}
+
+void generate_p_unit_circle(
+ const double lower,
+ const double upper,
+ const double epsilon
+) {
+ for ( double p = lower; p < upper + epsilon; p = p + epsilon ) {
+ imgen::write_ppm(
+ "unit_circle_" + std::to_string(p) + ".ppm",
+ 128,
+ 128,
+ [p](std::ptrdiff_t x, std::ptrdiff_t y) -> imgen::color {
+ if ( p_norm(p, x, y) <= 32 ) {
+ return imgen::black();
+ } else {
+ return imgen::white();
+ }
+ }
+ );
+ }
+}
+
+int main(int, char*[]) {
+ generate_p_unit_circle(1.0, 3.0, 0.05);
+}