MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
apomorph.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file apomorph.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Morph a IFS from an Apollony Gasket to a cloud.@EOL
7 @keywords mistake fractal
8 @std C++20
9 @see https://www.mitchr.me/SS/AGasket/index.html
10 @copyright
11 @parblock
12 Copyright (c) 1988-2015,2017, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
15
16 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
17
18 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20
21 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
22 without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 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
29 DAMAGE.
30 @endparblock
31 @filedetails
32
33 This code started as a programming error. I was trying to generate an Apollony Gasket via an IFS, but had a cut-n-past error -- a 1 where I should have had
34 a zero. The result was something very unlike an Apollony Gasket. So I was curious what the results would be if the parameter was swept from 0 to 1.
35*/
36/*******************************************************************************************************************************************************.H.E.**/
37/** @cond exj */
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40#include "ramCanvas.hpp"
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43int main() {
44 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
45 std::cout << "apomorph start" << std::endl;
46 const int CSIZE = 2160; // Quad HD
47 const int ITRTOSS = 1000; // Throw away first iterations
48 const long NUMITR = 400000000; // Needs to be big
49
50 mjr::ramCanvas3c8b theRamCanvas(CSIZE, CSIZE, -4.0, 4.0, -4.0, 4.0);
51 theRamCanvas.setDrawMode(mjr::ramCanvas3c8b::drawModeType::ADDCLAMP);
52
53 mjr::ramCanvas3c8b::colorType aColor[] = { mjr::ramCanvas3c8b::colorType(1, 0, 0), mjr::ramCanvas3c8b::colorType(0, 1, 0), mjr::ramCanvas3c8b::colorType(0, 0, 1) };
54
55 std::random_device rd;
56 std::minstd_rand0 rEng(rd()); // Fast is better than high quality for this application.
57
58 const double s = 1.73205080757;
59// const std::complex<double> i(0.0, 1.0);
60 const std::complex<double> si(0.0, s);
61 const std::complex<double> c1 = (1.0+s)/(2.0+s);
62 const std::complex<double> c2 = 0.5*(si-1.0);
63 const std::complex<double> c3 = -0.5*(si+1.0);
64 const std::complex<double> c4 = 1.0+s;
65 for(int frame=1; frame<401; frame++) {
66 theRamCanvas.clrCanvasToBlack();
67 std::complex<double> c5(3.0, (frame-1)*0.0025);
68 std::cout << "apomorph frame: " << frame << " " << (frame-1)*0.0025 << std::endl;
69 std::complex<double> z(0.1, 0.2);
70 for (long n=0;n<NUMITR;n++) {
71 std::complex<double> zNxt;
72 if ((n % (NUMITR/100)) == 0) {
73 if ((n % (NUMITR/10)) == 0)
74 std::cout << "|" << std::flush;
75 else
76 std::cout << "." << std::flush;
77 }
78 std::complex<double> f = c5/(c4-z)-c1;
79 std::minstd_rand0::result_type rn = rEng()%3;
80 switch (rn) {
81 case 0:
82 zNxt = f; break;
83 case 1:
84 zNxt = c2/f; break;
85 case 2:
86 zNxt = c3/f; break;
87 }
88 z = zNxt;
89 if (n > ITRTOSS)
90 theRamCanvas.drawPoint(z, aColor[rn]);
91 }
92 std::cout << "|" << std::endl;
93 std::cout << "apomorph dump" << std::endl;
94 theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmStdPow, 1/5.0);
95
96 theRamCanvas.writeTIFFfile("apomorph_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
97 std::cout << "apomorph finish" << std::endl;
98 }
99 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
100 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
101 return 0;
102}
103/** @endcond */
int main(int argc, char *argv[])