MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
phoenixI.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file phoenixI.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw Phoenix Julia set fractal insides with distance estimator.@EOL
7 @std C++20
8 @see Writeup with images: https://www.mitchr.me/SS/phoenix/
9 @see MRaster repository: https://github.com/richmit/mraster/
10 @see Doxygen documentation: https://www.mitchr.me/SS/mraster/doc-examples/autodocs/html/
11 @see Related example: https://github.com/richmit/mraster/blob/master/examples/phoenix.cpp
12 @copyright
13 @parblock
14 Copyright (c) 2024, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
17
18 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
21 and/or other materials provided with the distribution.
22
23 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
24 without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 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
31 DAMAGE.
32 @endparblock
33*/
34/*******************************************************************************************************************************************************.H.E.**/
35/** @cond exj */
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38#include "ramCanvas.hpp"
39
40//--------------------------------------------------------------------------------------------------------------------------------------------------------------
41typedef mjr::ramCanvas3c8b::colorType ct;
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44std::vector<std::array<double, 9>> params {
45 /* cr, ci, pr, pi, k, x-min, x-max, y-min, y-max */
46 { 0.566700, 0.00000, -0.50000, 0.00000, 300.0, -1.35, 1.35, -1.35, 1.35}, // 0
47 { 0.544992, 0.00000, -0.47000, 0.00000, 1000.0, -1.35, 1.35, -1.35, 1.35}, // 1
48 { -0.400000, 0.10000, 0.29550, 0.00000, 300.0, -1.10, 1.10, -1.50, 1.50}, // 2
49};
50
51//--------------------------------------------------------------------------------------------------------------------------------------------------------------
52int main(void) {
53 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
54 const int WIDTH = 1920*4*4;
55 const int HEIGHT = 1920*4*4;
56 const int NUMITR = 500;
57 const double MAXZ = 6.0;
58
59# pragma omp parallel for schedule(static,1)
60 for(decltype(params.size()) j=0; j<params.size(); ++j) {
61 const std::complex<double> c(params[j][0], params[j][1]);
62 const std::complex<double> p(params[j][2], params[j][3]);
63 mjr::ramCanvas3c8b theRamCanvas(WIDTH, HEIGHT, params[j][5], params[j][6], params[j][7], params[j][8]);
64 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
65 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
66 std::complex<double> d1(1.0, 0.0);
67 std::complex<double> d2(0.0, 0.0);
68
69 std::complex<double> z1(theRamCanvas.int2realY(y), theRamCanvas.int2realX(x));
70 std::complex<double> z2(0.0, 0.0);
71 int count = 0;
72 while((std::norm(z1)<MAXZ) && (count<=NUMITR)) {
73 std::complex<double> z = z1*z1+c+p*z2;
74 std::complex<double> d = 2.0*d1*z1+p*d2;
75 z2 = z1;
76 z1 = z;
77 d2 = d1;
78 d1 = d;
79 count++;
80 }
81 if(std::norm(z1)<MAXZ)
82 theRamCanvas.drawPoint(x, y, ct::csCCfractal0RYBCW::c(static_cast<ct::csIntType>(std::log(std::abs(d1)+1)*params[j][4])));
83 }
84 }
85 theRamCanvas.scaleDownMean(4);
86 theRamCanvas.writeTIFFfile("phoenixI_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
87 std::cout << "ITER(" << j << "): " << "DONE " << std::endl;
88 }
89
90 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
91 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
92}
93/** @endcond */
int main(int argc, char *argv[])