MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_meanOrbit.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file mandelbrot_meanOrbit.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Color Mandelbrot set using the mean orbit.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 2025, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 We color this Mandelbrot set by characteristics (arg, abs, re, im) of the /mean orbit/ point for the first MAXITR iterations.
32
33*/
34/*******************************************************************************************************************************************************.H.E.**/
35/** @cond exj */
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38#include "ramCanvas.hpp"
39
40//--------------------------------------------------------------------------------------------------------------------------------------------------------------
41typedef mjr::ramCanvas3c8b rcT;
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44int main(void) {
45 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
46 const int DSCALE = 8;
47 const int USCALE = 8;
48 const int MAXITR = 256;
49 const int CSIZE = 1024*USCALE;
50 rcT argRamCanvas(CSIZE, CSIZE, -2.2, 0.8, -1.5, 1.5);
51 rcT absRamCanvas(CSIZE, CSIZE, -2.2, 0.8, -1.5, 1.5);
52 rcT imRamCanvas( CSIZE, CSIZE, -2.2, 0.8, -1.5, 1.5);
53 rcT reRamCanvas( CSIZE, CSIZE, -2.2, 0.8, -1.5, 1.5);
54
55# pragma omp parallel for schedule(static,1)
56 for(rcT::coordIntType y=0;y<argRamCanvas.getNumPixY();y++) {
57 for(rcT::coordIntType x=0;x<argRamCanvas.getNumPixX();x++) {
58 int count;
59 std::complex<rcT::coordFltType> z(0.0, 0.0);
60 std::complex<rcT::coordFltType> c(argRamCanvas.int2realX(x), argRamCanvas.int2realY(y));
61 std::complex<rcT::coordFltType> orbit_sum(0.0, 0.0);
62 for(count=0; count<MAXITR ; count++) {
63 orbit_sum += z;
64 z = z * z + c;
65 if (std::abs(z) > 2)
66 break;
67 }
68 if (count == MAXITR) {
69 std::complex<mjr::ramCanvas1c64F::coordFltType> relative_orbit_mean = orbit_sum / static_cast<double>(MAXITR)-c;
70 rcT::coordFltType clr_arg = (std::arg(relative_orbit_mean) + std::numbers::pi) / (2.0*std::numbers::pi);
71 argRamCanvas.drawPoint(x, y, rcT::colorType::csCColdeColdToHot::c(mjr::math::ivl::wrapCC(clr_arg, 1.0)));
72 rcT::coordFltType clr_abs = std::abs(relative_orbit_mean);
73 absRamCanvas.drawPoint(x, y, rcT::colorType::csCColdeColdToHot::c(mjr::math::ivl::wrapCC(clr_abs, 1.0)));
74 rcT::coordFltType clr_re = std::real(relative_orbit_mean);
75 reRamCanvas.drawPoint(x, y, rcT::colorType::csCColdeColdToHot::c(mjr::math::ivl::wrapCC(clr_re, 1.0)));
76 rcT::coordFltType clr_im = std::imag(relative_orbit_mean);
77 imRamCanvas.drawPoint(x, y, rcT::colorType::csCColdeColdToHot::c(mjr::math::ivl::wrapCC(clr_im, 1.0)));
78 }
79 }
80 }
81
82 if (DSCALE > 1) {
83 argRamCanvas.scaleDownMax(DSCALE);
84 absRamCanvas.scaleDownMax(DSCALE);
85 reRamCanvas.scaleDownMax(DSCALE);
86 imRamCanvas.scaleDownMax(DSCALE);
87 }
88
89 argRamCanvas.drawString("arg", mjr::hershey::font::ROMAN_SL_SANSERIF, 90, 90, "white", 1, 20);
90 absRamCanvas.drawString("abs", mjr::hershey::font::ROMAN_SL_SANSERIF, 90, 90, "white", 1, 20);
91 reRamCanvas.drawString( "re", mjr::hershey::font::ROMAN_SL_SANSERIF, 90, 90, "white", 1, 20);
92 imRamCanvas.drawString( "im", mjr::hershey::font::ROMAN_SL_SANSERIF, 90, 90, "white", 1, 20);
93
94 argRamCanvas.writeTIFFfile("mandelbrot_meanOrbit_arg.tiff");
95 absRamCanvas.writeTIFFfile("mandelbrot_meanOrbit_abs.tiff");
96 reRamCanvas.writeTIFFfile( "mandelbrot_meanOrbit_re.tiff");
97 imRamCanvas.writeTIFFfile( "mandelbrot_meanOrbit_im.tiff");
98
99 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
100 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
101}
102/** @endcond */
int main(int argc, char *argv[])