MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
phoenix.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file phoenix.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw Phoenix Julia set fractals.@EOL
7 @std C++20
8 @see Doxygen documentation: https://www.mitchr.me/SS/mraster/doc-examples/autodocs/html/
9 @see Writeup with images: https://www.mitchr.me/SS/phoenix/
10 @see MRaster repository: https://github.com/richmit/mraster/
11 @copyright
12 @parblock
13 Copyright (c) 2024, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
20 and/or other materials provided with the distribution.
21
22 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
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 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
30 DAMAGE.
31 @endparblock
32 @filedetails
33
34 The Phoenix Fractal is given by the following iteration:
35
36 @f[ z_n = z_{n-1} + c + p\cdot z_{n-1} @f]
37
38 Where @f$ c @f$ and @f$ p @f$ are both complex parameters we may set as we wish.
39
40 This formula is iterated for each point in the complex plane (z) with the initial conditions:
41
42 @f[ \begin{align*}
43 z_{-1} & = \Im(z) + \Re(z)\cdot i \\
44 z_{-2} & = 0
45 \end{align*} @f]
46
47 An exterior distance estimator is given by:
48
49 @f[ d_{n} = 2\cdot d_{n-1}\cdot z_{n-1} + p\cdot d_{n-2} @f]
50
51 With the initial conditions:
52
53 @f[ \begin{align*}
54 d_{-1} & = 1 \\
55 d_{-2} & = 0
56 \end{align*} @f]
57*/
58/*******************************************************************************************************************************************************.H.E.**/
59/** @cond exj */
60
61//--------------------------------------------------------------------------------------------------------------------------------------------------------------
62#include "ramCanvas.hpp"
63#include "MRMathSTR.hpp"
64
65//--------------------------------------------------------------------------------------------------------------------------------------------------------------
66typedef mjr::ramCanvas3c8b::colorType ct;
67
68//--------------------------------------------------------------------------------------------------------------------------------------------------------------
69std::vector<std::array<double, 9>> params {
70 /* cr, ci, pr, pi, k, x-min, x-max, y-min, y-max */
71 { 0.566700, 0.00000, -0.50000, 0.00000, 10.0, -1.35, 1.35, -1.35, 1.35}, // 0
72 { 0.544992, 0.00000, -0.47000, 0.00000, 10.0, -1.35, 1.35, -1.35, 1.35}, // 1
73 { 0.269000, 0.00000, 0.00000, 0.01000, 5.0, -1.10, 1.10, -1.00, 1.00}, // 2
74 { -0.400000, 0.10000, 0.29550, 0.00000, 10.0, -1.10, 1.10, -1.50, 1.50}, // 3
75 { 0.400000, 0.00000, -0.25000, 0.00000, 10.0, -1.30, 1.20, -1.00, 1.00}, // 4
76 { 0.100000, 0.60000, -0.35000, 0.00000, 10.0, -1.30, 1.30, -1.30, 1.30}, // 5
77 { 0.400000, 0.40000, 0.20500, 0.00000, 30.0, -1.30, 1.30, -1.30, 1.30}, // 6
78 { 0.400000, 0.50000, 0.20500, 0.00000, 30.0, -1.30, 1.30, -1.30, 1.30}, // 7
79};
80
81//--------------------------------------------------------------------------------------------------------------------------------------------------------------
82int main(void) {
83 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
84 const int WIDTH = 1920*4;
85 const int HEIGHT = 1920*4;
86 const int NUMITR = 500;
87 const double MAXZ = 4.0;
88
89# pragma omp parallel for schedule(static,1)
90 for(int j=0; j<(int)params.size(); ++j) { // Not using decltype(params.size()) for j because of old OpenMP in MSVC
91 const std::complex<double> c(params[j][0], params[j][1]);
92 const std::complex<double> p(params[j][2], params[j][3]);
93 mjr::ramCanvas3c8b theRamCanvas(WIDTH, HEIGHT, params[j][5], params[j][6], params[j][7], params[j][8]);
94 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
95 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
96 std::complex<double> z1(theRamCanvas.int2realY(y), theRamCanvas.int2realX(x));
97 std::complex<double> z2(0.0, 0.0);
98 int count = 0;
99 while((std::norm(z1)<MAXZ) && (count<=NUMITR)) {
100 std::complex<double> z = z1*z1+c+p*z2;
101 z2 = z1;
102 z1 = z;
103 count++;
104 }
105 if(count < NUMITR)
106 theRamCanvas.drawPoint(x, y, ct::csCCfractal0RYBCW::c(static_cast<ct::csIntType>(count*params[j][4])));
107 }
108 }
109 theRamCanvas.writeTIFFfile("phoenix_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
110 std::cout << "ITER(" << j << "): " << "DONE" << std::endl;
111 }
112
113 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
114 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
115}
116/** @endcond */
int main(int argc, char *argv[])