Advertisement
Chris_M_Thomasson

Inverse Julia IFS test 0

Dec 27th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. I am wondering if you can reproduce the rendering just based on the code below?
  2.  
  3. _______________________________________
  4. // BMP is from the following open source C++ bitmap lib:
  5. // http://easybmp.sourceforge.net
  6.  
  7.  
  8. // complex_t is a C++ complex number of type double
  9. typedef std::complex<double> complex_t;
  10.  
  11.  
  12. // random() returns a pseudo-random number in interval of [0...1]
  13.  
  14. double random()
  15. {
  16. return (std::rand() / (RAND_MAX - 1.0));
  17. }
  18.  
  19.  
  20. #define PI 3.1415926535897
  21. #define PI2 (PI*2.0)
  22.  
  23.  
  24. struct ifs_sparky_single_point
  25. {
  26. // A center point and a radius.
  27. struct plane
  28. {
  29. complex_t m_cpoint;
  30. double m_radius;
  31. };
  32.  
  33.  
  34. /*
  35. void plotbmp(
  36. BMP& bmp,
  37. plane const& p,
  38. complex_t jp,
  39. unsigned int imax,
  40. double xpow
  41. );
  42.  
  43. inputs:
  44. bmp is the bitmap
  45. plane is a const reference to the circle we are going to project into bmp
  46. jp is a single complex Julia point in rectangular form
  47. imax is the total number iterations
  48. xpow is power of jp
  49.  
  50. outputs: none
  51. */
  52.  
  53. void plotbmp(
  54. BMP& bmp,
  55. plane const& p,
  56. complex_t jp,
  57. unsigned int imax,
  58. double xpow
  59. ){
  60. // our iterate point z starting at zero.
  61. complex_t z = { 0.0, 0.0 };
  62.  
  63. // Our root angle we will use in conjunction with
  64. // with the result of the probability function.
  65. double root_angle = PI2 / xpow;
  66.  
  67. for (unsigned int i = 0; i < imax; ++i)
  68. {
  69. // Get the difference between z and jp
  70. complex_t d = z - jp;
  71.  
  72. // Get the distance between z and jp
  73. double radius = abs(d);
  74.  
  75. // Get the angle between z and jp
  76. double angle = atan2(d.imag(), d.real());
  77.  
  78. // Reverse the angle
  79. double pangle = angle / xpow;
  80.  
  81. // Reverse the radius
  82. double pradius = std::pow(radius, 1.0 / xpow);
  83.  
  84. // For now, lets look at an expanded probability function for pow of 3.
  85.  
  86. // random_root is a random integer between 0 and 2
  87. int random_root = 0;
  88.  
  89. // rn is a random number between 0 and 1
  90. double rn = random();
  91.  
  92. // Here is a probability you can try for a pow 3.
  93. // it seems to work with pow of 2 in seahorse valley as well.
  94. // random_root is from [0...2] wrt following probabilities wrt 3:
  95. if (rn < 0.01)
  96. {
  97. random_root = 0;
  98. }
  99.  
  100. else if (rn < 0.98)
  101. {
  102. random_root = 1;
  103. }
  104.  
  105. else
  106. {
  107. random_root = 2;
  108. }
  109.  
  110. // Get the angle of our random_root via our root_angle
  111. double rangle = root_angle * random_root;
  112.  
  113. // Get the x any y components of our next iterate of z.
  114. double x = pradius * std::cos(pangle + rangle);
  115. double y = pradius * std::sin(pangle + rangle);
  116.  
  117. // Update z components with x and y for the next iteration.
  118. z.real(x);
  119. z.imag(y);
  120.  
  121.  
  122. // For now we plot two points. We should plot all of the possible roots!
  123. // Try to plot two points in the bitmap (bmp) with plane (p)...
  124.  
  125. // calc bitmap plot 0 z
  126. unsigned int ix0 = x * p.m_radius + p.m_cpoint.real();
  127. unsigned int iy0 = -y * p.m_radius + p.m_cpoint.imag();
  128.  
  129. // calc bitmap plot 1 z
  130. unsigned int ix1 = -x * p.m_radius + p.m_cpoint.real();
  131. unsigned int iy1 = y * p.m_radius + p.m_cpoint.imag();
  132.  
  133. // try to plot 0 z
  134. if (ix0 < bmp.TellWidth() && iy0 < bmp.TellHeight())
  135. {
  136. RGBApixel color = bmp.GetPixel(ix0, iy0);
  137.  
  138. color.Alpha = 255;
  139.  
  140. if (color.Red < 248)
  141. {
  142. color.Red = color.Red + 7;
  143. }
  144.  
  145. color.Green = color.Green + 1;
  146. //color.Blue = 255;
  147.  
  148. bmp.SetPixel(ix0, iy0, color);
  149. }
  150.  
  151. // try to plot 1 z
  152. if (ix1 < bmp.TellWidth() && iy1 < bmp.TellHeight())
  153. {
  154. RGBApixel color= bmp.GetPixel(ix1, iy1);
  155.  
  156.  
  157. color.Alpha = 255;
  158.  
  159. // color.Red = color.Red + 18;
  160.  
  161. if (color.Red < 248)
  162. {
  163. color.Red = color.Red + 7;
  164. }
  165.  
  166. //color.Green = 255;
  167. color.Blue = color.Blue + 1;
  168.  
  169. bmp.SetPixel(ix1, iy1, color);
  170. }
  171.  
  172. // give some sort of progress report in the console... ;^)
  173. if (! (i % 100000))
  174. {
  175. std::printf("i = %lf\r", i / 10000000.0);
  176. }
  177. }
  178. }
  179. };
  180.  
  181.  
  182. // Here is an example usage
  183. {
  184. // seed the C global random number generator
  185. // This should not matter all that much wrt the result
  186. std::srand(19354411);
  187.  
  188. // our ifs single point Julia inverse iteration
  189. ifs_sparky_single_point ifss;
  190.  
  191. // The actual seed Julia point in rectangular form
  192. complex_t jp = { -0.744, 0.19 };
  193.  
  194. // The plane based on the bitmap this_bmp
  195. ifs_sparky_single_point::plane p = {
  196. { this_bmp.TellWidth() / 2.0, this_bmp.TellHeight() / 2.0 },
  197. this_bmp.TellHeight() * 0.5 //2.5
  198. };
  199.  
  200. // Plot the plane on the bitmap this_bmp
  201. ifss.plotbmp(this_bmp, p, jp, 100000.0, 2); // 2.995
  202.  
  203. }
  204. _______________________________________
  205.  
  206.  
  207.  
  208. How much of the above can you understand?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement