MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
biomorph2.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file biomorph2.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a corner centered biomorph fractal nice for a desktop background image.@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 = 100;
44 const int CSIZE = 7680;
45 const int LIM = 4;
46
47 mjr::ramCanvas3c8b theRamCanvasA(CSIZE, CSIZE, -1.0, 1.4, -1.0, 1.4);
48 mjr::ramCanvas3c8b theRamCanvasE(CSIZE, CSIZE, -1.0, 1.4, -1.0, 1.4);
49 mjr::ramCanvas3c8b theRamCanvasK(CSIZE, CSIZE, -1.0, 1.4, -1.0, 1.4);
50 mjr::ramCanvas3c8b theRamCanvasL(CSIZE, CSIZE, -1.0, 1.4, -1.0, 1.4);
51 mjr::ramCanvas3c8b theRamCanvasN(CSIZE, CSIZE, -1.0, 1.4, -1.0, 1.4);
52
53 for(int y=0;y<theRamCanvasA.getNumPixY();y++) {
54 if((y%(CSIZE/10))==0)
55 std::cout << " LINE: " << y << "/" << CSIZE << std::endl;
56 for(int x=0;x<theRamCanvasA.getNumPixX();x++) {
57 std::complex<double> z(theRamCanvasA.int2realX(x), theRamCanvasA.int2realY(y));
58 int count = 0;
59 while( ((std::abs(std::real(z))<LIM) || (std::abs(std::imag(z))<LIM)) && (count<NUMITR) ) {
60 z=std::sin(z)+std::complex<double>(1.0, 1.0);
61 count++;
62 }
63 if(count < NUMITR) {
64 // A
65 theRamCanvasA.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>(count*500)));
66 // E
67 if(std::abs(std::real(z))<std::abs(std::imag(z)))
68 theRamCanvasE.drawPoint(x, y, ct("red"));
69 else
70 theRamCanvasE.drawPoint(x, y, ct("blue"));
71 // K
72 theRamCanvasK.drawPoint(x, y, ct::csCColdeRainbow::c(static_cast<cit>((std::arg(z)+3.14)*255)));
73 // L
74 if(std::abs(std::real(z))<std::abs(std::imag(z)))
75 theRamCanvasL.drawPoint(x, y, ct::csCCu0R::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::real(z))*15), ct::csCCu0R::numC-1)));
76 else
77 theRamCanvasL.drawPoint(x, y, ct::csCCu0B::c(mjr::math::ivl::clamp(static_cast<cit>(std::abs(std::imag(z))*15), ct::csCCu0B::numC-1)));
78 }
79 }
80 }
81 theRamCanvasA.writeTIFFfile("biomorph2A.tiff");
82 theRamCanvasE.writeTIFFfile("biomorph2E.tiff");
83 theRamCanvasK.writeTIFFfile("biomorph2K.tiff");
84 theRamCanvasL.writeTIFFfile("biomorph2L.tiff");
85 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
86 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
87}
88/** @endcond */
int main(int argc, char *argv[])