Chris_M_Thomasson

5-ary Base Code

May 16th, 2019
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. // Parametric Recursive 5-Ary Base Algorithm
  2.  
  3. ct_complex
  4. ct_map_x(
  5.     ct_complex const& z,
  6.     ct_float sign = 1
  7. ) {
  8.     ct_complex I = { 0, sign };
  9.  
  10.     ct_complex m = (I + z) / (I - z);
  11.  
  12.     //{Re[(I+z)/(I-z)),Im[(I+z)/(I-z))
  13.     return m;
  14. }
  15.  
  16.  
  17. void ct_draw_line(
  18.     ct::plot2d& plot,
  19.     ct_complex p0,
  20.     ct_complex p1,
  21.     unsigned int n
  22. ) {
  23.     ct_complex dif = p1 - p0;
  24.  
  25.     double base = 1.0 / n;
  26.  
  27.     for (unsigned int i = 0; i < n; ++i)
  28.     {
  29.         double ratio = base * i;
  30.  
  31.         ct_complex p = p0 + dif * ratio;
  32.  
  33.         ct_complex p_proj = p;
  34.         //ct_complex p_proj = ct_map_x(p, -1);
  35.  
  36.  
  37.  
  38.         plot.set_pixelf(p_proj, CT_RGBF(1, 1, 0));
  39.         //plot.set_pixelf(-p_proj, CT_RGBF(1, 0, 1));
  40.     }
  41. }
  42.  
  43.  
  44. void ct_draw_poly(
  45.     ct::plot2d& plot,
  46.     ct_complex origin,
  47.     double radius,
  48.     double start_angle,
  49.     unsigned int n
  50. ) {
  51.     double abase = CT_PI2 / n;
  52.  
  53.     //plot.circle(origin, radius, CT_RGBF(0, 1, 0));
  54.  
  55.     for (unsigned int i = 0; i < n; ++i)
  56.     {
  57.         double angle_0 = abase * i + start_angle;
  58.         double angle_1 = angle_0 + abase;
  59.  
  60.         ct_complex p0_raw = {
  61.             cos(angle_0) * radius,
  62.             sin(angle_0) * radius
  63.         };
  64.  
  65.         ct_complex p1_raw = {
  66.             cos(angle_1) * radius,
  67.             sin(angle_1) * radius
  68.         };
  69.  
  70.         ct_complex p0_proj = origin + p0_raw;
  71.         ct_complex p1_proj = origin + p1_raw;
  72.  
  73.         //plot.line(p0_proj, p1_proj, CT_RGBF(1, 0, 0));
  74.  
  75.         ct_draw_line(plot, p0_proj, p1_proj, 256);
  76.     }
  77. }
  78.  
  79.  
  80. void ct_bearing(
  81.     ct::plot2d& plot,
  82.     unsigned int r_i,
  83.     unsigned int r_max,
  84.     ct_complex origin,
  85.     double origin_radius,
  86.     double start_angle,
  87.     unsigned int n
  88. ) {
  89.     if (r_i >= r_max) return;
  90.  
  91.     // BASE ANGLE
  92.     double ball_abase = CT_PI2 / n;
  93.  
  94.     // BALL SCALE
  95.     ct_complex d0 = {
  96.         origin.real() + origin_radius,
  97.         origin.imag()
  98.     };
  99.  
  100.     ct_complex d1 = {
  101.         origin.real() + cos(ball_abase) * origin_radius,
  102.         origin.imag() + sin(ball_abase) * origin_radius
  103.     };
  104.  
  105.     double ball_diameter = abs(d1 - d0);
  106.     double ball_radius = ball_diameter / 2;
  107.     double ball_scale = origin_radius / (origin_radius + ball_radius);
  108.  
  109.     double ball_inner_radius = origin_radius - ball_diameter * ball_scale;
  110.  
  111.  
  112.     double scale_ball_inner_radius = ball_inner_radius * 1.479;
  113.  
  114.     //plot.circle_filled(origin, scale_ball_inner_radius, CT_RGBF(1, 1, 1));
  115.     ct_bearing(plot, r_i + 1, r_max, origin, scale_ball_inner_radius, start_angle + ball_abase / 2, n);
  116.  
  117.  
  118.     for (unsigned int i = 0; i < n; ++i)
  119.     {
  120.         double ball_angle_0 = ball_abase * i + start_angle;
  121.  
  122.         ct_complex p0 = {
  123.             cos(ball_angle_0) * origin_radius,
  124.             sin(ball_angle_0) * origin_radius
  125.         };
  126.  
  127.         ct_complex ball_proj_p0 = origin + p0 * ball_scale;
  128.         double ball_proj_radius = ball_radius * ball_scale;
  129.  
  130.         double scale_ball_radius = ball_proj_radius * 1.03;
  131.  
  132.         //plot.circle(ball_proj_p0, scale_ball_radius, CT_RGBF(1, 0, 0));
  133.  
  134.         if (r_i == r_max - 1)
  135.         {
  136.             //plot.circle_filled(ball_proj_p0, scale_ball_radius * .75, CT_RGBF(0, 1, 1));
  137.             //plot.line(origin, -ball_proj_p0 * scale_ball_radius, CT_RGBF(1, 1, 1));
  138.             ct_draw_poly(plot, ball_proj_p0, scale_ball_radius, ball_angle_0 + ball_abase, n);
  139.         }
  140.  
  141.  
  142.         ct_bearing(plot, r_i + 1, r_max, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
  143.     }
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment