Advertisement
Chris_M_Thomasson

Inverse Julia IFS Experiment pow 3

Dec 22nd, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1.  
  2. struct ifs
  3. {
  4.     struct plane
  5.     {
  6.         complex_t m_cpoint;
  7.         double m_radius;
  8.     };
  9.  
  10.     complex_t m_jp;
  11.  
  12.     void plot_plane(
  13.         BMP& bmp,
  14.         plane const& p,
  15.         complex_t jp,
  16.         unsigned int imax,
  17.         double xpow
  18.     ){
  19.         complex_t z = { 0.0, 0.0 };
  20.         double prob = 0.5;
  21.  
  22.         unsigned int roots = (unsigned int)std::ceil(std::abs(xpow));
  23.         double root_angle = 6.28 / xpow;
  24.  
  25.         for (unsigned int i = 0; i < imax; ++i)
  26.         {
  27.             double dx = z.real() - jp.real();
  28.             double dy = z.imag() - jp.imag();
  29.  
  30.             double r2 = std::sqrt(dx*dx + dy*dy);
  31.             double w2 = std::atan2(dy, dx);
  32.             double a = w2 / xpow;
  33.             double r = std::pow(r2, 1.0 / xpow);
  34.  
  35.             // Hard code at pow 3
  36.             unsigned int random_root = 0;
  37.             double rn = random();
  38.             if (rn < 0.09)
  39.             {
  40.                 random_root = 0;
  41.             }
  42.  
  43.             else if (rn < 0.97)
  44.             {
  45.                 random_root = 1;
  46.             }
  47.  
  48.             else
  49.             {
  50.                 random_root = 2;
  51.             }
  52.  
  53.             double rangle = root_angle * random_root;
  54.  
  55.             double x1 = r * std::cos(a + rangle);
  56.             double y1 = r * std::sin(a + rangle);
  57.  
  58.             z.real(x1);
  59.             z.imag(y1);
  60.  
  61.             unsigned int ix0 = x1 * p.m_radius + p.m_cpoint.real();
  62.             unsigned int iy0 = y1 * p.m_radius + p.m_cpoint.imag();
  63.  
  64.             unsigned int ix1 = -x1 * p.m_radius + p.m_cpoint.real();
  65.             unsigned int iy1 = -y1 * p.m_radius + p.m_cpoint.imag();
  66.  
  67.            
  68.  
  69.             if (ix0 < bmp.TellWidth() && iy0 < bmp.TellHeight())
  70.             {
  71.                 RGBApixel color = bmp.GetPixel(ix0, iy0);
  72.  
  73.                 color.Alpha = 255;
  74.                 color.Red = color.Red + 18;
  75.                 color.Green = color.Green + 1;
  76.                 color.Blue = color.Blue + 3;
  77.  
  78.                  bmp.SetPixel(ix0, iy0, color);
  79.             }
  80.  
  81.            
  82.             if (ix1 < bmp.TellWidth() && iy1 < bmp.TellHeight())
  83.             {
  84.                 RGBApixel color= bmp.GetPixel(ix1, iy1);
  85.  
  86.                 color.Alpha = 255;
  87.                 color.Red = color.Red + 11;
  88.                 color.Green = color.Green;
  89.                 color.Blue = color.Blue + 2;
  90.  
  91.                  bmp.SetPixel(ix1, iy1, color);
  92.             }
  93.         }
  94.     }
  95. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement