Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am wondering if you can reproduce the rendering just based on the code below?
- _______________________________________
- // BMP is from the following open source C++ bitmap lib:
- // http://easybmp.sourceforge.net
- // complex_t is a C++ complex number of type double
- typedef std::complex<double> complex_t;
- // random() returns a pseudo-random number in interval of [0...1]
- double random()
- {
- return (std::rand() / (RAND_MAX - 1.0));
- }
- #define PI 3.1415926535897
- #define PI2 (PI*2.0)
- struct ifs_sparky_single_point
- {
- // A center point and a radius.
- struct plane
- {
- complex_t m_cpoint;
- double m_radius;
- };
- /*
- void plotbmp(
- BMP& bmp,
- plane const& p,
- complex_t jp,
- unsigned int imax,
- double xpow
- );
- inputs:
- bmp is the bitmap
- plane is a const reference to the circle we are going to project into bmp
- jp is a single complex Julia point in rectangular form
- imax is the total number iterations
- xpow is power of jp
- outputs: none
- */
- void plotbmp(
- BMP& bmp,
- plane const& p,
- complex_t jp,
- unsigned int imax,
- double xpow
- ){
- // our iterate point z starting at zero.
- complex_t z = { 0.0, 0.0 };
- // Our root angle we will use in conjunction with
- // with the result of the probability function.
- double root_angle = PI2 / xpow;
- for (unsigned int i = 0; i < imax; ++i)
- {
- // Get the difference between z and jp
- complex_t d = z - jp;
- // Get the distance between z and jp
- double radius = abs(d);
- // Get the angle between z and jp
- double angle = atan2(d.imag(), d.real());
- // Reverse the angle
- double pangle = angle / xpow;
- // Reverse the radius
- double pradius = std::pow(radius, 1.0 / xpow);
- // For now, lets look at an expanded probability function for pow of 3.
- // random_root is a random integer between 0 and 2
- int random_root = 0;
- // rn is a random number between 0 and 1
- double rn = random();
- // Here is a probability you can try for a pow 3.
- // it seems to work with pow of 2 in seahorse valley as well.
- // random_root is from [0...2] wrt following probabilities wrt 3:
- if (rn < 0.01)
- {
- random_root = 0;
- }
- else if (rn < 0.98)
- {
- random_root = 1;
- }
- else
- {
- random_root = 2;
- }
- // Get the angle of our random_root via our root_angle
- double rangle = root_angle * random_root;
- // Get the x any y components of our next iterate of z.
- double x = pradius * std::cos(pangle + rangle);
- double y = pradius * std::sin(pangle + rangle);
- // Update z components with x and y for the next iteration.
- z.real(x);
- z.imag(y);
- // For now we plot two points. We should plot all of the possible roots!
- // Try to plot two points in the bitmap (bmp) with plane (p)...
- // calc bitmap plot 0 z
- unsigned int ix0 = x * p.m_radius + p.m_cpoint.real();
- unsigned int iy0 = -y * p.m_radius + p.m_cpoint.imag();
- // calc bitmap plot 1 z
- unsigned int ix1 = -x * p.m_radius + p.m_cpoint.real();
- unsigned int iy1 = y * p.m_radius + p.m_cpoint.imag();
- // try to plot 0 z
- if (ix0 < bmp.TellWidth() && iy0 < bmp.TellHeight())
- {
- RGBApixel color = bmp.GetPixel(ix0, iy0);
- color.Alpha = 255;
- if (color.Red < 248)
- {
- color.Red = color.Red + 7;
- }
- color.Green = color.Green + 1;
- //color.Blue = 255;
- bmp.SetPixel(ix0, iy0, color);
- }
- // try to plot 1 z
- if (ix1 < bmp.TellWidth() && iy1 < bmp.TellHeight())
- {
- RGBApixel color= bmp.GetPixel(ix1, iy1);
- color.Alpha = 255;
- // color.Red = color.Red + 18;
- if (color.Red < 248)
- {
- color.Red = color.Red + 7;
- }
- //color.Green = 255;
- color.Blue = color.Blue + 1;
- bmp.SetPixel(ix1, iy1, color);
- }
- // give some sort of progress report in the console... ;^)
- if (! (i % 100000))
- {
- std::printf("i = %lf\r", i / 10000000.0);
- }
- }
- }
- };
- // Here is an example usage
- {
- // seed the C global random number generator
- // This should not matter all that much wrt the result
- std::srand(19354411);
- // our ifs single point Julia inverse iteration
- ifs_sparky_single_point ifss;
- // The actual seed Julia point in rectangular form
- complex_t jp = { -0.744, 0.19 };
- // The plane based on the bitmap this_bmp
- ifs_sparky_single_point::plane p = {
- { this_bmp.TellWidth() / 2.0, this_bmp.TellHeight() / 2.0 },
- this_bmp.TellHeight() * 0.5 //2.5
- };
- // Plot the plane on the bitmap this_bmp
- ifss.plotbmp(this_bmp, p, jp, 100000.0, 2); // 2.995
- }
- _______________________________________
- How much of the above can you understand?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement