MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
feather.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file feather.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief The feather fractal.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 2025, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 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
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 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
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 I learned about the "duck" or "feather" fractal from an old blog post: https://algorithmic-worlds.net/blog/blog.php?Post=20110227
32
33 The idea is to iterate a function a fixed number of times for each point in the complex plane, and then color that point according to the magnitude of the
34 mean of the orbit points. In this case we iterate the log of the "iabs" function:
35
36 @f[ \log\left(\Re(z)+\vert\Im(z)\vert+c\right) @f]
37
38 Coloring by the magnitude of the final iterate is interesting; however, I think it's even more interesting to color by the final iterate *relative* to the
39 initial condition. Another interesting choice is to color by the relative argument.
40*/
41/*******************************************************************************************************************************************************.H.E.**/
42/** @cond exj */
43
44//--------------------------------------------------------------------------------------------------------------------------------------------------------------
45#include "ramCanvas.hpp"
46
47//--------------------------------------------------------------------------------------------------------------------------------------------------------------
48typedef mjr::ramCanvas3c8b rcT;
49
50//--------------------------------------------------------------------------------------------------------------------------------------------------------------
51int main(void) {
52 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
53 const int DSCALE = 1;
54 const int USCALE = 1;
55 const int MAXITR = 100;
56 const int width = 1024*USCALE;
57 const int height = 1024*USCALE;
58 rcT theRamCanvas(width, height, -1.0, 1.0, -2.6, 0.0); // Whole feather
59 //rcT theRamCanvas(width, height, 0.5, 1.0, -0.25, 0.0); // Just the upper tip
60
61# pragma omp parallel for schedule(static,1)
62 for(rcT::coordIntType y=0;y<theRamCanvas.getNumPixY();y++) {
63 for(rcT::coordIntType x=0;x<theRamCanvas.getNumPixX();x++) {
64 int count;
65 std::complex<rcT::coordFltType> z(0.0, 0.0);
66 std::complex<rcT::coordFltType> c(theRamCanvas.int2realX(x), theRamCanvas.int2realY(y));
67 std::complex<rcT::coordFltType> orbit_sum(0.0, 0.0);
68 for(count=0; count<MAXITR ; count++) {
69 orbit_sum += z;
70 z = std::log(std::complex<rcT::coordFltType>(std::real(z), std::abs(std::imag(z))) + c);
71 }
72 if (count == MAXITR) {
73 //double clr = (std::arg(orbit_sum / static_cast<double>(MAXITR)-c) + std::numbers::pi) / (2.0*std::numbers::pi); // Relative argument
74 double clr = std::abs(orbit_sum / static_cast<double>(MAXITR)-c); // Distance from initial point
75 //double clr = std::abs(orbit_sum / static_cast<double>(MAXITR)); // Distance from center
76 theRamCanvas.drawPoint(x, y, rcT::colorType::csCColdeColdToHot::c(mjr::math::ivl::wrapCC(clr, 1.0)));
77 }
78 }
79 }
80
81 if (DSCALE > 1)
82 theRamCanvas.scaleDownMax(DSCALE);
83 theRamCanvas.writeTIFFfile("feather.tiff");
84 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
85 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
86}
87/** @endcond */
int main(int argc, char *argv[])