Chris_M_Thomasson

Tessy Test 0.0.0

Oct 29th, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. void ct_koch_line(
  2.     ct::plot2d& plot,
  3.     unsigned int irecur_n,
  4.     unsigned int irecur_max,
  5.     ct_complex a,
  6.     ct_complex b,
  7.     ct_float ratio
  8. ) {
  9.     if (irecur_n >= irecur_max) return;
  10.  
  11.     ct_complex dif = b - a;
  12.     ct_complex mid = a + dif * .5;
  13.     ct_complex k0 = a + dif * ratio;
  14.  
  15.     ct_complex k1 = {
  16.         mid.real() - dif.imag() * ratio * .3,
  17.         mid.imag() + dif.real() * ratio * .3
  18.     };
  19.  
  20.     ct_complex k2 = a + dif * ratio * 2.;
  21.  
  22.     ct_float alpha = 1.0;
  23.     plot.line(a, k0, CT_RGBAF(1, 1, 0, alpha));
  24.     plot.line(k0, k1, CT_RGBAF(1, 0, 1, alpha));
  25.     plot.line(k1, k2, CT_RGBAF(1, 0, 1, alpha));
  26.     plot.line(k2, b, CT_RGBAF(1, 1, 0, alpha));
  27.  
  28.     ct_koch_line(plot, irecur_n + 1, irecur_max, a, k0, ratio);
  29.     ct_koch_line(plot, irecur_n + 1, irecur_max, k0, k1, ratio);
  30.     ct_koch_line(plot, irecur_n + 1, irecur_max, k1, k2, ratio);
  31.     ct_koch_line(plot, irecur_n + 1, irecur_max, k2, b, ratio);
  32. }
  33.  
  34. void ct_tessy_test(
  35.     ct::plot2d& plot,
  36.     unsigned int irecur_n,
  37.     unsigned int irecur_max,
  38.     ct_complex a,
  39.     ct_complex b,
  40.     ct_complex c,
  41.     ct_float ratio
  42. ) {
  43.     if (irecur_n >= irecur_max) return;
  44.  
  45.     ct_complex mid = c + (b - c) * .5;
  46.     ct_complex gcenter = a + (mid - a) * ratio;
  47.  
  48.     ct_koch_line(plot, 0, 4, a, gcenter, 1. / 3);
  49.     ct_koch_line(plot, 0, 4, c, gcenter, 1. / 3);
  50.     ct_koch_line(plot, 0, 4, b, gcenter, 1. / 3);
  51.  
  52.     ct_koch_line(plot, 0, 4, gcenter, a, 1. / 3);
  53.     ct_koch_line(plot, 0, 4, gcenter, c, 1. / 3);
  54.     ct_koch_line(plot, 0, 4, gcenter, b, 1. / 3);
  55.  
  56.     ct_float nratio = abs(ratio * 1.0);
  57.  
  58.     ct_tessy_test(plot, irecur_n + 1, irecur_max, a, b, gcenter, nratio);
  59.     ct_tessy_test(plot, irecur_n + 1, irecur_max, b, c, gcenter, nratio);
  60.     ct_tessy_test(plot, irecur_n + 1, irecur_max, c, a, gcenter, nratio);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment