MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
demo_colorizer.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file demo_colorizer.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a mandelbrot set using colorizeCanvas.@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 @filedetails
30
31 Function visualization is one of the most popular applications for MRaster users -- especially fractals. MRaster has a few tools to make this kind of thing
32 super simple. This program demonstrates one of the colorize*Canvas functions. These functions take a "color function" as an argument, and use that
33 function to fill a canvas.
34
35*/
36/*******************************************************************************************************************************************************.H.E.**/
37/** @cond exj */
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40#include "ramCanvas.hpp"
41#include "MRMathIVL.hpp"
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44typedef mjr::ramCanvas3c8b rct;
45
46//--------------------------------------------------------------------------------------------------------------------------------------------------------------
47rct::colorType mandelbrot_esc_fun(rct::coordFltType x, rct::coordFltType y) {
48 std::complex<double> z(0.0, 0.0), c(x, y);
49 for(int count = 0; count<256; count++)
50 if (std::abs(z = z * z + c) > 2)
51 return rct::colorType::csCColdeFireRamp::c(static_cast<rct::csIntType>(count*20));
52 return rct::colorType("black");
53}
54
55//--------------------------------------------------------------------------------------------------------------------------------------------------------------
56int main(void) {
57 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
58 rct theRamCanvas(1024, 1024, -2.2, 0.8, -1.5, 1.5);
59
60 theRamCanvas.colorizeFltCanvas(mandelbrot_esc_fun);
61 theRamCanvas.writeTIFFfile("demo_colorizer.tiff");
62
63 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
64 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
65}
66/** @endcond */
int main(int argc, char *argv[])