Loading [MathJax]/extensions/tex2jax.js
MRaster examples 22.0.0.0
Image Processing Library
All Files Functions Pages
mandelbrot_biomorph.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_biomorph.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw the classic mandelbrot_biomorph fractal.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/mandelbrot_biomorph/index.html
9 @copyright
10 @parblock
11 Copyright (c) 1988-2022, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30*/
31/*******************************************************************************************************************************************************.H.E.**/
32/** @cond exj */
33
34//--------------------------------------------------------------------------------------------------------------------------------------------------------------
35#include "ramCanvas.hpp"
36#include "MRMathIVL.hpp"
37
38//--------------------------------------------------------------------------------------------------------------------------------------------------------------
39typedef mjr::ramCanvas3c8b::colorType ct;
40typedef ct::csIntType cit;
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43int main(void) {
44 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
45 const int NUMITR = 1024;
46 const int IMXSIZ = 7680/2;
47 const int IMYSIZ = 7680/2;
48 const int LIM = 10;
49
50 mjr::ramCanvas3c8b theRamCanvasA(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
51 mjr::ramCanvas3c8b theRamCanvasE(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
52 mjr::ramCanvas3c8b theRamCanvasK(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
53 mjr::ramCanvas3c8b theRamCanvasL(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
54 mjr::ramCanvas3c8b theRamCanvasM(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
55 mjr::ramCanvas3c8b theRamCanvasN(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
56
57 for(int y=0;y<theRamCanvasA.getNumPixY();y++) {
58 for(int x=0;x<theRamCanvasA.getNumPixX();x++) {
59 std::complex<double> c = theRamCanvasA.int2real(x, y);
60 std::complex<double> z(0.0, 0.0);
61 std::complex<double> zL(0.0, 0.0);
62 int count = 0;
63 while( ((std::abs(std::real(z))<LIM) || (std::abs(std::imag(z))<LIM)) && (count<NUMITR) ) {
64 zL = z;
65 z=std::pow(z, 2) + c;
66 count++;
67 }
68 if(count < NUMITR) {
69 // A
70 theRamCanvasA.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(count*500)));
71 // E
72 if(std::abs(std::real(z))<std::abs(std::imag(z)))
73 theRamCanvasE.drawPoint(x, y, ct("red"));
74 else
75 theRamCanvasE.drawPoint(x, y, ct("blue"));
76 // K
77 theRamCanvasK.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>((std::arg(z)+3.14)*255)));
78 // L
79 if(std::abs(std::real(z))<std::abs(std::imag(z)))
80 theRamCanvasL.drawPoint(x, y, ct::csCCu0R::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::real(z))*15), ct::csCCu0R::numC-1)));
81 else
82 theRamCanvasL.drawPoint(x, y, ct::csCCu0B::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::imag(z))*15), ct::csCCu0B::numC-1)));
83 // M
84 if(std::abs(std::real(zL)) < LIM)
85 theRamCanvasM.drawPoint(x, y, ct::csCCfractalYB::c(std::abs(std::real(zL))/LIM));
86 else if(std::abs(std::imag(zL)) < LIM)
87 theRamCanvasM.drawPoint(x, y, ct::csCCfractalYR::c(std::abs(std::imag(zL))/LIM));
88 else
89 theRamCanvasM.drawPoint(x, y, "white");
90 // N
91 if(std::abs(std::real(zL)) < LIM)
92 theRamCanvasN.drawPoint(x, y, ct::csCCdiag01::c(std::abs(std::real(zL))/LIM));
93 else if(std::abs(std::imag(zL)) < LIM)
94 theRamCanvasN.drawPoint(x, y, ct::csCCdiag10::c(std::abs(std::imag(zL))/LIM));
95 else
96 theRamCanvasN.drawPoint(x, y, "white");
97 }
98 }
99 }
100 theRamCanvasA.writeTIFFfile("mandelbrot_biomorphA.tiff");
101 theRamCanvasE.writeTIFFfile("mandelbrot_biomorphE.tiff");
102 theRamCanvasK.writeTIFFfile("mandelbrot_biomorphK.tiff");
103 theRamCanvasL.writeTIFFfile("mandelbrot_biomorphL.tiff");
104 theRamCanvasM.writeTIFFfile("mandelbrot_biomorphM.tiff");
105 theRamCanvasN.writeTIFFfile("mandelbrot_biomorphN.tiff");
106 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
107 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
108}
109/** @endcond */
int main(int argc, char *argv[])