MRaster examples 21.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
64//--------------------------------------------------------------------------------------------------------------------------------------------------------------
65typedef mjr::ramCanvas3c8b::colorType ct;
66
67//--------------------------------------------------------------------------------------------------------------------------------------------------------------
68std::vector<std::array<double, 9>> params {
69 /* cr, ci, pr, pi, k, x-min, x-max, y-min, y-max */
70 { 0.566700, 0.00000, -0.50000, 0.00000, 10.0, -1.35, 1.35, -1.35, 1.35}, // 0
71 { 0.544992, 0.00000, -0.47000, 0.00000, 10.0, -1.35, 1.35, -1.35, 1.35}, // 1
72 { 0.269000, 0.00000, 0.00000, 0.01000, 5.0, -1.10, 1.10, -1.00, 1.00}, // 2
73 { -0.400000, 0.10000, 0.29550, 0.00000, 10.0, -1.10, 1.10, -1.50, 1.50}, // 3
74 { 0.400000, 0.00000, -0.25000, 0.00000, 10.0, -1.30, 1.20, -1.00, 1.00}, // 4
75 { 0.100000, 0.60000, -0.35000, 0.00000, 10.0, -1.30, 1.30, -1.30, 1.30}, // 5
76 { 0.400000, 0.40000, 0.20500, 0.00000, 30.0, -1.30, 1.30, -1.30, 1.30}, // 6
77 { 0.400000, 0.50000, 0.20500, 0.00000, 30.0, -1.30, 1.30, -1.30, 1.30}, // 7
78};
79
80//--------------------------------------------------------------------------------------------------------------------------------------------------------------
81int main(void) {
82 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
83 const int WIDTH = 1920*4;
84 const int HEIGHT = 1920*4;
85 const int NUMITR = 500;
86 const double MAXZ = 4.0;
87
88# pragma omp parallel for schedule(static,1)
89 for(decltype(params.size()) j=0; j<params.size(); ++j) {
90 const std::complex<double> c(params[j][0], params[j][1]);
91 const std::complex<double> p(params[j][2], params[j][3]);
92 mjr::ramCanvas3c8b theRamCanvas(WIDTH, HEIGHT, params[j][5], params[j][6], params[j][7], params[j][8]);
93 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
94 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
95 std::complex<double> z1(theRamCanvas.int2realY(y), theRamCanvas.int2realX(x));
96 std::complex<double> z2(0.0, 0.0);
97 int count = 0;
98 while((std::norm(z1)<MAXZ) && (count<=NUMITR)) {
99 std::complex<double> z = z1*z1+c+p*z2;
100 z2 = z1;
101 z1 = z;
102 count++;
103 }
104 if(count < NUMITR)
105 theRamCanvas.drawPoint(x, y, ct::csCCfractal0RYBCW::c(static_cast<ct::csIntType>(count*params[j][4])));
106 }
107 }
108 theRamCanvas.writeTIFFfile("phoenix_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
109 std::cout << "ITER(" << j << "): " << "DONE" << std::endl;
110 }
111
112 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
113 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
114}
115/** @endcond */
int main(int argc, char *argv[])