Advertisement
Chris_M_Thomasson

5-star fractal tile...

Apr 7th, 2019
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 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. }
  34.  
  35.  
  36. void ct_bearing(
  37.     ct::plot2d& plot,
  38.     unsigned int r_i,
  39.     unsigned int r_max,
  40.     ct_complex origin,
  41.     double origin_radius,
  42.     double start_angle,
  43.     unsigned int n
  44. ) {
  45.     if (r_i >= r_max) return;
  46.  
  47.     // BASE ANGLE
  48.     double ball_abase = CT_PI2 / n;
  49.  
  50.     // BALL SCALE
  51.     ct_complex d0 = {
  52.         origin.real() + origin_radius,
  53.         origin.imag()
  54.     };
  55.  
  56.     ct_complex d1 = {
  57.         origin.real() + cos(ball_abase) * origin_radius,
  58.         origin.imag() + sin(ball_abase) * origin_radius
  59.     };
  60.  
  61.     double ball_diameter = abs(d1 - d0);
  62.     double ball_radius = ball_diameter / 2;
  63.     double ball_scale = origin_radius / (origin_radius + ball_radius);
  64.  
  65.     double ball_inner_radius = origin_radius - ball_diameter * ball_scale;
  66.  
  67.     //plot.circle(origin, ball_inner_radius, CT_RGBF(0, 1, 1));
  68.     double scale_ball_inner_radius = ball_inner_radius * 1.5;
  69.     ct_bearing(plot, r_i + 1, r_max, origin, scale_ball_inner_radius, start_angle + ball_abase / 2, n);
  70.  
  71.     for (unsigned int i = 0; i < n; ++i)
  72.     {
  73.         double ball_angle_0 = ball_abase * i + start_angle;
  74.  
  75.         ct_complex p0 = {
  76.             cos(ball_angle_0) * origin_radius,
  77.             sin(ball_angle_0) * origin_radius
  78.         };
  79.  
  80.         ct_complex ball_proj_p0 = origin + p0 * ball_scale;
  81.         double ball_proj_radius = ball_radius * ball_scale;
  82.  
  83.         double scale_ball_radius = ball_proj_radius * 1.03;
  84.  
  85.         //plot.circle(ball_proj_p0, scale_ball_radius, CT_RGBF(1, 0, 0));
  86.  
  87.         if (r_i == r_max - 1)
  88.         {
  89.             ct_draw_poly(plot, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
  90.         }
  91.        
  92.  
  93.         ct_bearing(plot, r_i + 1, r_max, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement