Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* (Z^2 + ((RE(Z) + IM(Z)) / 2.1)) - 0.83
- Very Crude and Quick Example by Chris M. Thomasson for Sparky...
- :^D
- __________________________________________________________________
- */
- #include <iostream>
- #include <EasyBMP.h>
- #include <complex>
- typedef std::complex<double> complex_t;
- void iterate_point(BMP& bmp, complex_t c, unsigned int x, unsigned int y)
- {
- complex_t z = c;
- complex_t d = z;
- double g = 500.0;
- unsigned int imax = 168;
- for (unsigned int i = 0; i < imax; ++i)
- {
- //(Z^2 + ((RE(Z) + IM(Z)) / 2.1)) - 0.83
- z = (z*z + ((z.real() + z.imag()) / 2.1)) - 0.83;
- double e = std::abs(z);
- //if (e > 10)
- if (z.real() / d.real() > g && z.imag() / d.imag() > g)
- {
- RGBApixel color;
- color.Alpha = 255;
- color.Red = std::abs(std::sin((z.real() * z.imag()) / 7) * 255);
- color.Green = (i * 3) % 256;
- color.Blue = std::abs(std::cos((z.real() * z.imag()) / 13) * 255);
- bmp.SetPixel(x, y, color);
- return;
- }
- d = z;
- }
- RGBApixel color;
- color.Alpha = 255;
- color.Red = 0;
- color.Green = 0;
- color.Blue = 255;
- bmp.SetPixel(x, y, color);
- }
- void iterate_plane(BMP& bmp, unsigned int width, unsigned height)
- {
- double xmin = -1.7;
- double xmax = 1.3;
- double ymin = -1.3;
- double ymax = 1.7;
- double xstep = (xmax - xmin) / (width - 1.0);
- double ystep = (ymax - ymin) / (height - 1.0);
- for (unsigned int y = 0; y < height; ++y)
- {
- for (unsigned int x = 0; x < width; ++x)
- {
- complex_t c(xmin + x * xstep, ymin + y * ystep);
- iterate_point(bmp, c, x, y);
- }
- std::cout << "y = " << y << "\r";
- }
- std::cout << "\r\n";
- }
- int main()
- {
- {
- BMP this_bmp;
- unsigned int bmp_width = 340;
- unsigned int bmp_height = 340;
- this_bmp.SetSize(bmp_width, bmp_height);
- this_bmp.SetBitDepth(24);
- iterate_plane(this_bmp, bmp_width, bmp_height);
- this_bmp.WriteToFile("C:\\Users\\Chris\\Desktop\\hello_fractal.bmp");
- }
- std::cout << "Done\r\n";
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement