MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_ltrap.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_ltrap.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Mandelbrot set with an Mandelbrot curve as an orbert trap.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, 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*/
30/*******************************************************************************************************************************************************.H.E.**/
31/** @cond exj */
32
33//--------------------------------------------------------------------------------------------------------------------------------------------------------------
34#include "ramCanvas.hpp"
35
36//--------------------------------------------------------------------------------------------------------------------------------------------------------------
37typedef mjr::ramCanvas3c8b::colorType ct;
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40double lp(std::complex<double> z, int n) {
41 std::complex<double> lpv(0.0, 0.0);
42 for(int i=0; i<n; i++)
43 lpv = std::pow(lpv, 2) + z;
44 return std::abs(lpv) - 2;
45}
46
47//--------------------------------------------------------------------------------------------------------------------------------------------------------------
48int main(void) {
49 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
50 const int IMGSIZ = 7680;
51 const int MAXITR = 1024;
52 const double MAXZSQ = 4.0;
53 const int NUMFRM = 10;
54
55# pragma omp parallel for schedule(static,1)
56 for(int frame=1;frame<=NUMFRM;frame++) {
57# pragma omp critical
58 std::cout << "Frame " << frame << " of " << NUMFRM << std::endl;
59 mjr::ramCanvas3c8b theRamCanvas(IMGSIZ, IMGSIZ, -2.2, 0.8, -1.5, 1.5);
60 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
61 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
62 std::complex<double> c = theRamCanvas.int2real(x, y);
63 std::complex<double> z(0.0, 0.0);
64 double minDval = theRamCanvas.getCanvasWidD();
65 double minDsgn = 0;
66 int count = 0;
67 while((std::norm(z)<MAXZSQ) && (count<=MAXITR)) {
68 z=std::pow(z, 2) + c;
69 double ld = lp(z, frame);
70 if (std::abs(ld) < minDval) {
71 minDval = std::abs(ld);
72 minDsgn = (ld > 0 ? 1 : -1);
73 }
74 count++;
75 }
76 if(count < MAXITR) {
77 ct::csIntType csIdx = static_cast<ct::csIntType>(std::log(1+minDval)*100);
78 if (minDsgn > 0)
79 theRamCanvas.drawPoint(x, y, ct::csCCfractalYB::c(csIdx));
80 else
81 theRamCanvas.drawPoint(x, y, ct::csCCfractalYR::c(csIdx));
82 }
83 }
84 }
85 theRamCanvas.writeTIFFfile("mandelbrot_ltrap_" + mjr::math::str::fmt_int(frame, 2, '0') + ".tiff");
86 }
87 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
88 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
89}
90/** @endcond */
int main(int argc, char *argv[])