// 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-qd 10000 1 // e.g.: hyper -sunflower-dr 1 4.5 // Commandlines for https://twitter.com/ZenoRogue/status/1247900522905886723 : // Part 1: // -geo 1 -sunflower-node 1 -sunflower-qd "1..10..20..60..100..140..180..220..|1000..1040..|2000..2040..|5000..5040..|10000..10040" 1 -zoom "sqrt(1000/(100+sunq))" -animperiod 20000 -shott 0 -back A0E0A0 -lw 16 -shotxy 1000 1000 -shotaa 2 // Part 2: // -rugtsize 8192 -rugon -run -rugv 4000000 -run -sunflower-dr "0.001..0.002..0.005..0.01..0.02..0.04..0.06..0.07..0.08..0.09" 3..4.1..4.5..4.5..4.5..4.5..4.5..4.5..4.5 -lw 4 -sunflower-out 1 -shott 0 -back A0E0A0 -shotxy 1000 1000 -shotaa 2 -sunflower-adj 16 -animrec 600 curv%04d.png // rotate the rug; press F10; wait until rug has millions of vertices; press F10; animation will be recorded // Part 3: // -rugtsize 8192 -rugon -rugv 1000000 -sunflower-dr .5 4.5 -lw 16 -shott 0 -back A0E0A0 -shotxy 1000 1000 -shotaa 2 -sunflower-adj 6 // (rotation animation set manually) // Part 4: // -geo 2 -sunflower-dr .1 pi -shott 0 -back A0E0A0 -shotxy 1000 1000 -shotaa 2 -animmove "2*pi" 0 0 #include "rogueviz.h" namespace rogueviz { namespace sunflower { bool nodes; ld qty = 100; ld density = 1, zdensity; ld range; ld yshift; ld distance_per_rug; bool adjust_rug; /* which property to infer from the other two: 'd'ensity, 'q'ty or 'r'ange */ char infer; vector ps; int iqty; ld qfrac; bool outward = false; ld step_angle = M_PI * (3 - sqrt(5)); hyperpoint p(int i) { ld step = step_angle; return spin((outward ? i : i-iqty) * step) * xpush(sphere ? (acos(1 - (i+.5+qfrac) * density)) : euclid ? sqrt((i+.5+qfrac) * density) : acosh(1 + (i+.5+qfrac) * density)) * C0; } vector inext, inext2; vector fibs; color_t sunflower1 = 0xC04000FF; color_t sunflower2 = 0xFFD500FF; color_t sunflower3 = 0x000000FF; bool overlay = false; bool sunflower_cell(cell *c, shiftmatrix V) { density = zdensity / 100; ld qd; if(sphere) { if(infer == 'r') range = qty * density * 90._deg; else qd = range / 90._deg; } else if(euclid) { if(infer == 'r') range = sqrt(qty * density); else qd = range * range; } else { if(infer == 'r') range = acosh(1 + qty * density); else qd = (cosh(range) - 1); } if(infer == 'q') qty = qd / density; if(infer == 'd') density = qd / qty; if(adjust_rug) { using namespace rug; model_distance = sqrt(zdensity) * distance_per_rug; } iqty = qty; qfrac = qty - iqty; if(outward) qfrac = 0; if(iqty < 0 || iqty > 2000000) return false; if(fibs.empty()) { ld best_error = 1; vector sgns; for(int i=1; i .5; if(sgn) v = 1-v; if(v < best_error) fibs.push_back(i), sgns.push_back(sgn), best_error = v; } println(hlog, "fibs = ", fibs); println(hlog, "sgns = ", sgns); } ps.resize(iqty); inext.resize(iqty); inext2.resize(iqty); while(fibs.back() < iqty) { /* to do: might not work correctly if step_angle is changed */ auto add = fibs.back() + *(fibs.end()-2); fibs.push_back(add); } 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; } if(sunflower1 || sunflower2 || sunflower3) for(int i=0; i& v) { if(s != "mixed") return; using namespace tour; v.push_back( tour::slide{"sunflower spirals", 18, LEGAL::ANY | QUICKGEO, "A sunflower sends out its n-th seed at angle 180° (3-sqrt(5)). " "As new seeds are created, older seeds are pushed out. Therefore. " "the distance d(n) of the n-th seed from the center will be such that " "the area of a circle of radius d(n) changes linearly with n.\n\n" "In the Euclidean plane, this process creates an interesting " "phenomenon: if we try to compute the number of spirals at a given " "distance from the center, we usually obtain a Fibonacci number. " "The further from the start we are, the larger Fibonacci number we " "get.\n\n" "Because of the exponential growth in the hyperbolic plane, we " "get to larger Fibonacci numbers faster.\n\n" "Press 123 to change the geometry, 5 to see this in the Hypersian Rug model. " "Press o to change the density.", [] (presmode mode) { slide_url(mode, 'y', "YouTube link", "https://www.youtube.com/watch?v=bKzibaNqEog"); slide_url(mode, 't', "Twitter link", "https://twitter.com/ZenoRogue/status/1247900522905886723"); setCanvas(mode, '0'); if((mode == pmStop || mode == pmGeometry) && rug::rugged) rug::close(); if(mode == pmKey) { if(rug::rugged) rug::close(); else rug::init(); } if(mode == pmStart) { stop_game(); enable(); tour::slide_backup(range, sphere ? 2 : euclid ? 10 : 4.3); tour::slide_backup(zdensity, 1); tour::slide_backup(infer, 'q'); insert_param(); start_game(); } }} ); }); } }