Chris_M_Thomasson

Parametric Experimental Code ver:0.0.0 (pre-alpha)

Jul 25th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.81 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include "ct_g2d.hpp"
  4.  
  5.  
  6. // plot a semicircle wave
  7. struct ct_ap_circle
  8. {
  9.     // the functions input
  10.     struct input
  11.     {
  12.         ct::plot2d& plot;  // the plotter
  13.         ct_complex origin; // origin point
  14.         unsigned int imax; // the number of point per circle
  15.     };
  16.  
  17.     struct output
  18.     {
  19.         unsigned int ret;  // not used
  20.     };
  21.  
  22.  
  23.     static output result_for(
  24.         input const& in,
  25.         unsigned int irecur,
  26.         unsigned int irecur_max
  27.     ) {
  28.         output out = { 0 };
  29.  
  30.         if (irecur >= irecur_max) return out;
  31.  
  32.         ct_float angle_start = 1 / (in.imax - 1.0) * CT_PI2;
  33.  
  34.         ct_complex pt = {
  35.             1, 0
  36.         };
  37.  
  38.         ct_complex ptx = {
  39.             (std::cos(angle_start) +
  40.             std::floor(std::sin(angle_start)) * 2 + 1) * .5,
  41.             std::sin(angle_start) * .5
  42.         };
  43.  
  44.         ct_complex dif = ptx - pt;
  45.         ct_float dis = std::abs(dif) * .5;
  46.  
  47.         for (unsigned int i = 1; i < in.imax; ++i)
  48.         {
  49.             ct_float ir = i / (in.imax - 1.0);
  50.             ct_float angle = CT_PI2 * ir;
  51.  
  52.             ct_complex np = {
  53.                 (std::cos(angle) + std::floor(std::sin(angle)) * 2 + 1) * .5,
  54.                 std::sin(angle) * .5
  55.             };
  56.  
  57.             np = np + in.origin;
  58.  
  59.             ct_float ddd = std::abs(np - pt) * .5;
  60.  
  61.             if (ddd <= dis && i > 1)
  62.             {
  63.                 in.plot.line(pt, np, CT_RGBF(0, 1, 1));
  64.             }
  65.  
  66.             ct_ap_circle::input cap_irn = {
  67.                 in.plot,
  68.                 np,
  69.                 in.imax
  70.             };
  71.  
  72.             result_for(cap_irn, irecur + 1, irecur_max);
  73.  
  74.             pt = np;
  75.         }
  76.  
  77.         return out;
  78.     }
  79. };
  80.  
  81.  
  82. int main()
  83. {
  84.     {
  85.         ct_complex viewp_center = { 0, 0 };
  86.         ct_float viewp_radius = 1.17;// .965;
  87.  
  88.         ct_float aratio = 1080.0 / 1920.0;
  89.         ct_float width = 1920 * 1;
  90.  
  91.         ct::axes2d viewp_axes(viewp_center, viewp_radius);
  92.         ct::plot2d viewp_plot(viewp_axes, width, width * aratio, true);
  93.  
  94.         viewp_plot.clear(CT_RGBF(0, 0, 0));
  95.  
  96.         {
  97.             unsigned int circle_count = 2;
  98.  
  99.             // our input
  100.             ct_ap_circle::input cap_in = {
  101.                 viewp_plot,
  102.                 { 0, 0 },
  103.                 64
  104.             };
  105.  
  106.             // execute! Iteration count is number of circles plotted
  107.             ct_ap_circle::output cap_out =
  108.                 ct_ap_circle::result_for(cap_in, 0, circle_count);
  109.         }
  110.  
  111.         viewp_plot.circle({ 0, 0 }, 1, CT_RGBF(1, 1, 0));
  112.         viewp_plot.circle({ 0, 0 }, 2, CT_RGBF(1, 0, 1));
  113.  
  114.         viewp_plot.save("./output.bmp");
  115.  
  116.         // auto open on windows
  117.         //std::system("mspaint ./output.bmp");
  118.     }
  119.  
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment