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