From 01dc4997dc11cb97de7486371d636caaa5d95eec Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 11 Nov 2018 10:40:35 +0100 Subject: [PATCH] rogueviz:: added the sunflower spirals --- rogueviz-sunflower.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++ rogueviz.cpp | 1 + 2 files changed, 93 insertions(+) create mode 100644 rogueviz-sunflower.cpp diff --git a/rogueviz-sunflower.cpp b/rogueviz-sunflower.cpp new file mode 100644 index 00000000..74b449e3 --- /dev/null +++ b/rogueviz-sunflower.cpp @@ -0,0 +1,92 @@ +// non-Euclidean sunflower spirals (aka golden spirals or Fibonacci spirals) +// Copyright (C) 2018 Zeno and Tehora Rogue, see 'hyper.cpp' for details + +// use: commandline parameter -sunflower +// e.g.: hyper -sunflower 10000 0.01 + +// for spherical geometry, density is set automatically to cover the whole sphere + +namespace hr { + +namespace sunflower { + +int qty = 100; +ld density = 1, zdensity; + +static const int maxfib = 300000; + +hyperpoint ps[maxfib]; + +hyperpoint p(int i) { + ld step = M_PI * (3 - sqrt(5)); + return spin(i * step) * xpush(sphere ? (i+.5) * M_PI / qty : euclid ? sqrt((i+.5) * density) : acosh(1 + (i+.5) * density)) * C0; + } + +int inext[maxfib], inext2[maxfib]; + +const vector fibs = + {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811}; + +bool sunflower_cell(cell *c, transmatrix V) { + density = zdensity / 100; + if(c == cwt.at) { + for(int i=0; ii) break; + if(hdist(ps[i], ps[i-a]) < ba) + bb = ba, bj = bi, ba = hdist(ps[i], ps[i-a]), bi = i-a; + else if(hdist(ps[i], ps[i-a]) < bb) + bb = hdist(ps[i], ps[i-a]), bj = i-a; + } + inext[i] = bi; + inext2[i] = bj; + } + + for(int i=0; i