11#include " BitmapPlusPlus.hpp"
22#include " color_maps.inl"
33#include < cmath>
4+ #include < filesystem>
45
5- int main (void ) {
6- bmp::Bitmap image (1280 , 960 );
6+ int main () {
7+ bmp::Bitmap image (1280 , 960 );
78
8- double cr, ci;
9- double nextr, nexti;
10- double prevr, previ;
11- constexpr const std::uint16_t max_iterations = 3000 ;
9+ double cr, ci;
10+ double nextr, nexti;
11+ double prevr, previ;
12+ constexpr std::uint16_t max_iterations = 3000 ;
1213
13- for (std::int32_t y = 0 ; y < image.height (); ++y) {
14- for (std::int32_t x = 0 ; x < image.width (); ++x) {
15- cr = 1.5 * (2.0 * x / image.width () - 1.0 ) - 0.5 ;
16- ci = (2.0 * y / image.height () - 1.0 );
14+ for (std::int32_t y = 0 ; y < image.height (); ++y) {
15+ for (std::int32_t x = 0 ; x < image.width (); ++x) {
16+ cr = 1.5 * (2.0 * x / image.width () - 1.0 ) - 0.5 ;
17+ ci = (2.0 * y / image.height () - 1.0 );
1718
18- nextr = nexti = 0 ;
19- prevr = previ = 0 ;
19+ nextr = nexti = 0 ;
20+ prevr = previ = 0 ;
2021
21- for (std::uint16_t i = 0 ; i < max_iterations; ++i) {
22- prevr = nextr;
23- previ = nexti;
22+ for (std::uint16_t i = 0 ; i < max_iterations; ++i) {
23+ prevr = nextr;
24+ previ = nexti;
2425
25- nextr = prevr * prevr - previ * previ + cr;
26- nexti = 2 * prevr * previ + ci;
26+ nextr = prevr * prevr - previ * previ + cr;
27+ nexti = 2 * prevr * previ + ci;
2728
28- if (((nextr * nextr) + (nexti * nexti)) > 4 ) {
29- const double z = sqrt (nextr * nextr + nexti * nexti);
29+ if (((nextr * nextr) + (nexti * nexti)) > 4 ) {
30+ const double z = sqrt (nextr * nextr + nexti * nexti);
3031
31- // https://en.wikipedia.org/wiki/Mandelbrot_set#Continuous_.28smooth.29_coloring
32- const std::uint32_t index = static_cast <std::uint32_t >(1000.0 * log2 (1.75 + i - log2 (log2 (z))) /
33- log2 (max_iterations));
32+ // https://en.wikipedia.org/wiki/Mandelbrot_set#Continuous_.28smooth.29_coloring
33+ const std::uint32_t index = static_cast <std::uint32_t >(1000.0 * log2 (1.75 + i - log2 (log2 (z))) / log2 (max_iterations));
3434
35- image.set (x, y, jet_colormap[index]);
35+ image.set (x, y, jet_colormap[index]);
3636
37- break ;
38- }
39- }
40- }
41- }
37+ break ;
38+ }
39+ }
40+ }
41+ }
4242
43- image.save (std::string (BIN_DIR) + " / mandelbrot.bmp" );
43+ image.save (std::filesystem::path (BIN_DIR) / " mandelbrot.bmp" );
4444
45- return EXIT_SUCCESS;
46- }
45+ return EXIT_SUCCESS;
46+ }
0 commit comments