MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
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
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38typedef mjr::ramCanvas3c8b::colorType ct;
39typedef ct::csIntType cit;
40
41//--------------------------------------------------------------------------------------------------------------------------------------------------------------
42int main(void) {
43 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
44 const int NUMITR = 1024;
45 const int IMXSIZ = 7680/2;
46 const int IMYSIZ = 7680/2;
47 const int LIM = 10;
48
49 mjr::ramCanvas3c8b theRamCanvasA(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
50 mjr::ramCanvas3c8b theRamCanvasE(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
51 mjr::ramCanvas3c8b theRamCanvasK(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
52 mjr::ramCanvas3c8b theRamCanvasL(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
53 mjr::ramCanvas3c8b theRamCanvasM(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
54 mjr::ramCanvas3c8b theRamCanvasN(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);
55
56 for(int y=0;y<theRamCanvasA.getNumPixY();y++) {
57 for(int x=0;x<theRamCanvasA.getNumPixX();x++) {
58 std::complex<double> c = theRamCanvasA.int2real(x, y);
59 std::complex<double> z(0.0, 0.0);
60 std::complex<double> zL(0.0, 0.0);
61 int count = 0;
62 while( ((std::abs(std::real(z))<LIM) || (std::abs(std::imag(z))<LIM)) && (count<NUMITR) ) {
63 zL = z;
64 z=std::pow(z, 2) + c;
65 count++;
66 }
67 if(count < NUMITR) {
68 // A
69 theRamCanvasA.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(count*500)));
70 // E
71 if(std::abs(std::real(z))<std::abs(std::imag(z)))
72 theRamCanvasE.drawPoint(x, y, ct("red"));
73 else
74 theRamCanvasE.drawPoint(x, y, ct("blue"));
75 // K
76 theRamCanvasK.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>((std::arg(z)+3.14)*255)));
77 // L
78 if(std::abs(std::real(z))<std::abs(std::imag(z)))
79 theRamCanvasL.drawPoint(x, y, ct::csCCu0R::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::real(z))*15), ct::csCCu0R::numC-1)));
80 else
81 theRamCanvasL.drawPoint(x, y, ct::csCCu0B::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::imag(z))*15), ct::csCCu0B::numC-1)));
82 // M
83 if(std::abs(std::real(zL)) < LIM)
84 theRamCanvasM.drawPoint(x, y, ct::csCCfractalYB::c(std::abs(std::real(zL))/LIM));
85 else if(std::abs(std::imag(zL)) < LIM)
86 theRamCanvasM.drawPoint(x, y, ct::csCCfractalYR::c(std::abs(std::imag(zL))/LIM));
87 else
88 theRamCanvasM.drawPoint(x, y, "white");
89 // N
90 if(std::abs(std::real(zL)) < LIM)
91 theRamCanvasN.drawPoint(x, y, ct::csCCdiag01::c(std::abs(std::real(zL))/LIM));
92 else if(std::abs(std::imag(zL)) < LIM)
93 theRamCanvasN.drawPoint(x, y, ct::csCCdiag10::c(std::abs(std::imag(zL))/LIM));
94 else
95 theRamCanvasN.drawPoint(x, y, "white");
96 }
97 }
98 }
99 theRamCanvasA.writeTIFFfile("mandelbrot_biomorphA.tiff");
100 theRamCanvasE.writeTIFFfile("mandelbrot_biomorphE.tiff");
101 theRamCanvasK.writeTIFFfile("mandelbrot_biomorphK.tiff");
102 theRamCanvasL.writeTIFFfile("mandelbrot_biomorphL.tiff");
103 theRamCanvasM.writeTIFFfile("mandelbrot_biomorphM.tiff");
104 theRamCanvasN.writeTIFFfile("mandelbrot_biomorphN.tiff");
105 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
106 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
107}
108/** @endcond */
int main(int argc, char *argv[])