Chris_M_Thomasson

Log Spiral

Jun 30th, 2021
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. namespace ct_log_spiral
  2. {
  3.     void iterate_point(
  4.         ct::plot::cairo::plot_2d& plot,
  5.         glm::vec3 oc,
  6.         unsigned long n,
  7.         unsigned long x,
  8.         unsigned long y
  9.     ) {
  10.         ct_complex c = { oc.x, oc.y };
  11.         ct_complex z = c;
  12.  
  13.         double dis_max = 9999999.0;
  14.  
  15.         // start i at one
  16.         for (unsigned long i = 1; i < n; ++i)
  17.         {
  18.             //ct_complex zp = z * z + c;
  19.  
  20.             ct_complex zp = (std::pow(z, 1.3) - (1.0 / (std::log(z) + 0.11))) + 0.42457;
  21.             double slow = 1.2 + (1 / i);
  22.             zp /= slow;
  23.  
  24.             double dis = std::abs(zp);
  25.  
  26.             dis_max = std::min(dis_max, dis);
  27.  
  28.             if (dis > 4.f)
  29.             {
  30.                 double icolor = i / (n - 1.f);
  31.                 ct::plot::cairo::pixel color = CT_RGBF(icolor * 44., icolor * 15., icolor * 45);
  32.                 plot.set_pixel(x, y, color);
  33.                 return;
  34.             }
  35.  
  36.             z = zp;
  37.         }
  38.  
  39.         ct::plot::cairo::pixel color = CT_RGBF(dis_max * 11.f, 0, 1);
  40.         plot.set_pixel(x, y, color);
  41.     }
  42.  
  43.     void iterate_plane(
  44.         ct::plot::cairo::plot_2d& plot
  45.     ) {
  46.         std::cout << "ct_log_spiral::iterate_plane\n\n";
  47.  
  48.         for (unsigned long y = 0; y < plot.m_height; ++y)
  49.         {
  50.             for (unsigned long x = 0; x < plot.m_width; ++x)
  51.             {
  52.                 glm::vec3 vc = { plot.m_plane.project_to(x, y), 0.f };
  53.  
  54.                 iterate_point(plot, vc, 123, x, y);
  55.             }
  56.  
  57.             std::cout << "y = " << y << "\r";
  58.         }
  59.  
  60.         std::cout << "complete!!!!!!" << "\n";
  61.     }
  62.  
  63.  
  64.  
  65.     void manifest(ct::plot::cairo::plot_2d& plot)
  66.     {
  67.         std::cout << "ct_log_spiral::manifest\n\n";
  68.  
  69.         iterate_plane(plot);
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment