Chris_M_Thomasson

Experimental 5-Ary Tile...

Apr 29th, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1.  
  2. void ct_draw_poly(
  3.     ct::plot2d& plot,
  4.     ct_complex origin,
  5.     double radius,
  6.     double start_angle,
  7.     unsigned int n
  8. ) {
  9.     double abase = CT_PI2 / n;
  10.  
  11.     //plot.circle(origin, radius, CT_RGBF(0, 1, 0));
  12.  
  13.     for (unsigned int i = 0; i < n; ++i)
  14.     {
  15.         double angle_0 = abase * i + start_angle;
  16.         double angle_1 = angle_0 + abase;
  17.  
  18.         ct_complex p0_raw = {
  19.             cos(angle_0) * radius,
  20.             sin(angle_0) * radius
  21.         };
  22.  
  23.         ct_complex p1_raw = {
  24.             cos(angle_1) * radius,
  25.             sin(angle_1) * radius
  26.         };
  27.  
  28.         ct_complex p0_proj = origin + p0_raw;
  29.         ct_complex p1_proj = origin + p1_raw;
  30.  
  31.         //plot.line(p0_proj, p1_proj, CT_RGBF(1, 0, 0));
  32.  
  33.         ct_draw_line(plot, p0_proj, p1_proj, 256);
  34.     }
  35. }
  36.  
  37.  
  38. void ct_bearing(
  39.     ct::plot2d& plot,
  40.     unsigned int r_i,
  41.     unsigned int r_max,
  42.     ct_complex origin,
  43.     double origin_radius,
  44.     double start_angle,
  45.     unsigned int n
  46. ) {
  47.     if (r_i >= r_max) return;
  48.  
  49.     // BASE ANGLE
  50.     double ball_abase = CT_PI2 / n;
  51.  
  52.     // BALL SCALE
  53.     ct_complex d0 = {
  54.         origin.real() + origin_radius,
  55.         origin.imag()
  56.     };
  57.  
  58.     ct_complex d1 = {
  59.         origin.real() + cos(ball_abase) * origin_radius,
  60.         origin.imag() + sin(ball_abase) * origin_radius
  61.     };
  62.  
  63.     double ball_diameter = abs(d1 - d0);
  64.     double ball_radius = ball_diameter / 2;
  65.     double ball_scale = origin_radius / (origin_radius + ball_radius);
  66.  
  67.     double ball_inner_radius = origin_radius - ball_diameter * ball_scale;
  68.  
  69.  
  70.     double scale_ball_inner_radius = ball_inner_radius * 1.48;
  71.  
  72.     //plot.circle_filled(origin, scale_ball_inner_radius, CT_RGBF(1, 1, 1));
  73.     ct_bearing(plot, r_i + 1, r_max, origin, scale_ball_inner_radius, start_angle + ball_abase / 2, n);
  74.  
  75.  
  76.     for (unsigned int i = 0; i < n; ++i)
  77.     {
  78.         double ball_angle_0 = ball_abase * i + start_angle;
  79.  
  80.         ct_complex p0 = {
  81.             cos(ball_angle_0) * origin_radius,
  82.             sin(ball_angle_0) * origin_radius
  83.         };
  84.  
  85.         ct_complex ball_proj_p0 = origin + p0 * ball_scale;
  86.         double ball_proj_radius = ball_radius * ball_scale;
  87.  
  88.         double scale_ball_radius = ball_proj_radius * 1.03;
  89.  
  90.         //plot.circle(ball_proj_p0, scale_ball_radius, CT_RGBF(1, 0, 0));
  91.  
  92.         if (r_i == r_max - 1)
  93.         {
  94.             //plot.circle_filled(ball_proj_p0, scale_ball_radius * .75, CT_RGBF(0, 1, 1));
  95.             ct_draw_poly(plot, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
  96.         }
  97.  
  98.  
  99.         ct_bearing(plot, r_i + 1, r_max, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
  100.     }
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment