MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
biomorph1.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file biomorph1.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw some classical versions of Clifford Pickover's biomorph fractals.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, 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*/
30/*******************************************************************************************************************************************************.H.E.**/
31/** @cond exj */
32
33//--------------------------------------------------------------------------------------------------------------------------------------------------------------
34#include "ramCanvas.hpp"
35#include "MRMathIVL.hpp"
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38typedef mjr::ramCanvas3c8b::colorType ct;
39typedef ct::csIntType cit;
40
41//--------------------------------------------------------------------------------------------------------------------------------------------------------------
42int main(void) {
43 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
44 const int NUMITR = 2000;
45 const int CSIZE = 7680;
46 const int LIM = 4;
47 int count;
48 std::complex<double> oneone(1,1), z;
49
50 mjr::ramCanvas3c8b theRamCanvasA(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
51 mjr::ramCanvas3c8b theRamCanvasB(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
52 mjr::ramCanvas3c8b theRamCanvasC(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
53 mjr::ramCanvas3c8b theRamCanvasD(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
54 mjr::ramCanvas3c8b theRamCanvasE(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
55 mjr::ramCanvas3c8b theRamCanvasF(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
56 mjr::ramCanvas3c8b theRamCanvasG(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
57 mjr::ramCanvas3c8b theRamCanvasH(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
58 mjr::ramCanvas3c8b theRamCanvasI(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
59 mjr::ramCanvas3c8b theRamCanvasJ(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
60 mjr::ramCanvas3c8b theRamCanvasK(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
61 mjr::ramCanvas3c8b theRamCanvasL(CSIZE, CSIZE, 0.2, 1.2, 0.2, 1.2);
62
63 for(int y=0;y<theRamCanvasA.getNumPixY();y++) {
64 if((y%(CSIZE/10))==0)
65 std::cout << " LINE: " << y << "/" << CSIZE << std::endl;
66 for(int x=0;x<theRamCanvasA.getNumPixX();x++) {
67 for(z=std::complex<double>(theRamCanvasA.int2realX(x),theRamCanvasA.int2realY(y)),count=0;
68 ((std::abs(std::real(z))<LIM)||(std::abs(std::imag(z))<LIM))&&(count<=NUMITR);
69 count++,z=static_cast<std::complex<double>>(std::pow(z, 5))+oneone) ;
70 if(count < NUMITR) {
71 // A
72 theRamCanvasA.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(count*500)));
73 // B
74 theRamCanvasB.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(std::norm(z)/1000)));
75 // C
76 theRamCanvasC.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(std::abs(std::imag(z)))));
77 // D
78 theRamCanvasD.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(std::abs(std::real(z)))));
79 // E
80 if(std::abs(std::real(z))<std::abs(std::imag(z)))
81 theRamCanvasE.drawPoint(x, y, "red");
82 else
83 theRamCanvasE.drawPoint(x, y, "blue");
84 // F
85 if(std::abs(std::real(z))<std::abs(std::imag(z)))
86 theRamCanvasF.drawPoint(x, y, ct::csCCu0R::c(static_cast<cit>(std::abs(std::real(z)))));
87 else
88 theRamCanvasF.drawPoint(x, y, ct::csCCu0B::c(static_cast<cit>(std::abs(std::imag(z)))));
89 // G
90 if(std::abs(std::real(z))<std::abs(std::imag(z)))
91 theRamCanvasG.drawPoint(x, y, ct::csCCu0R::c(static_cast<cit>(std::norm(z)/1000)));
92 else
93 theRamCanvasG.drawPoint(x, y, ct::csCCu0B::c(static_cast<cit>(std::norm(z)/1000)));
94 // H
95 if(std::real(z) < 0) {
96 if(std::imag(z) < 0) {
97 theRamCanvasH.drawPoint(x, y, ct::csCCu0R::c(static_cast<cit>(std::abs(std::real(z)))));
98 } else {
99 theRamCanvasH.drawPoint(x, y, ct::csCCu0B::c(static_cast<cit>(std::abs(std::real(z)))));
100 }
101 } else {
102 if(std::imag(z) < 0) {
103 theRamCanvasH.drawPoint(x, y, ct::csCCu0M::c(static_cast<cit>(std::abs(std::real(z)))));
104 } else {
105 theRamCanvasH.drawPoint(x, y, ct::csCCu0C::c(static_cast<cit>(std::abs(std::real(z)))));
106 }
107 }
108 // I
109 if(std::real(z) < 0) {
110 if(std::imag(z) < 0) {
111 if(std::imag(z) < std::real(z) ) {
112 theRamCanvasI.drawPoint(x, y, "red");
113 } else {
114 theRamCanvasI.drawPoint(x, y, "yellow");
115 }
116 } else {
117 theRamCanvasI.drawPoint(x, y, "blue");
118 }
119 } else {
120 if(std::imag(z) < 0) {
121 theRamCanvasI.drawPoint(x, y, "magenta");
122 } else {
123 if(std::imag(z) < std::real(z) ) {
124 theRamCanvasI.drawPoint(x, y, "cyan");
125 } else {
126 theRamCanvasI.drawPoint(x, y, "green");
127 }
128 }
129 }
130 // J
131 if(std::real(z) < 0) {
132 if(std::imag(z) < 0) {
133 if(std::imag(z) < std::real(z) ) {
134 theRamCanvasJ.drawPoint(x, y, ct::csCCu0R::c(static_cast<cit>(std::abs(std::real(z)))));
135 } else {
136 theRamCanvasJ.drawPoint(x, y, ct::csCCu0Y::c(static_cast<cit>(std::abs(std::real(z)))));
137 }
138 } else {
139 theRamCanvasJ.drawPoint(x, y, ct::csCCu0B::c(static_cast<cit>(std::abs(std::real(z)))));
140 }
141 } else {
142 if(std::imag(z) < 0) {
143 theRamCanvasJ.drawPoint(x, y, ct::csCCu0M::c(static_cast<cit>(std::abs(std::real(z)))));
144 } else {
145 if(std::imag(z) < std::real(z) ) {
146 theRamCanvasJ.drawPoint(x, y, ct::csCCu0C::c(static_cast<cit>(std::abs(std::real(z)))));
147 } else {
148 theRamCanvasJ.drawPoint(x, y, ct::csCCu0G::c(static_cast<cit>(std::abs(std::real(z)))));
149 }
150 }
151 }
152 // K
153 theRamCanvasK.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>((std::arg(z)+3.14)*255)));
154 // L
155 if(std::abs(std::real(z))<std::abs(std::imag(z)))
156 theRamCanvasL.drawPoint(x, y, ct::csCCu0R::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::real(z))/100), 255)));
157 else
158 theRamCanvasL.drawPoint(x, y, ct::csCCu0B::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::imag(z))/100), 255)));
159 }
160 }
161 }
162 theRamCanvasA.writeTIFFfile("biomorph1A.tiff");
163 theRamCanvasB.writeTIFFfile("biomorph1B.tiff");
164 theRamCanvasC.writeTIFFfile("biomorph1C.tiff");
165 theRamCanvasD.writeTIFFfile("biomorph1D.tiff");
166 theRamCanvasE.writeTIFFfile("biomorph1E.tiff");
167 theRamCanvasF.writeTIFFfile("biomorph1F.tiff");
168 theRamCanvasG.writeTIFFfile("biomorph1G.tiff");
169 theRamCanvasH.writeTIFFfile("biomorph1H.tiff");
170 theRamCanvasI.writeTIFFfile("biomorph1I.tiff");
171 theRamCanvasJ.writeTIFFfile("biomorph1J.tiff");
172 theRamCanvasK.writeTIFFfile("biomorph1K.tiff");
173 theRamCanvasL.writeTIFFfile("biomorph1L.tiff");
174 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
175 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
176}
177/** @endcond */
int main(int argc, char *argv[])