MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
juliaM.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file mandelbrot_simple.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Create a Julia set movie.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/julia/index.html
9 @copyright
10 @parblock
11 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 Moves $c$ around a circle just a bit larger than the period 2 disk. A GIF may be rendered from the frames like this:
33
34 time convert -delay 1 -loop 0 -dispose previous juliaM_???.tiff juliaM.gif
35*/
36/*******************************************************************************************************************************************************.H.E.**/
37/** @cond exj */
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40#include "ramCanvas.hpp"
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43typedef mjr::ramCanvas3c8b::colorType ct;
44
45//--------------------------------------------------------------------------------------------------------------------------------------------------------------
46int main(void) {
47 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
48 const int NUMITR = 1024;
49 const double MAXZ = 4.0;
50 const int NUMFRM = 24*16;
51 const int IMXSIZ = 7680/8;
52 const int IMYSIZ = 7680/8;
53 const double ANGMIN = 0.0;
54 const double ANGMAX = std::numbers::pi*2;
55
56 for(int frame=0; frame<NUMFRM; frame++) {
57 mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -2.2, 2.2, -2.2, 2.2);
58 std::cout << "Frame: " << frame << std::endl;
59 double angle = frame*(ANGMAX-ANGMIN)/NUMFRM+ANGMIN;
60 std::complex<double> c = std::complex<double>(std::cos(angle), std::sin(angle)) * 0.35 - std::complex<double>(0.0, -1.0);
61 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
62 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
63 std::complex<double> z = theRamCanvas.int2real(x, y);
64 int count = 0;
65 while((std::norm(z)<MAXZ) && (count<=NUMITR)) {
66 z=std::pow(z, 2) + c;
67 count++;
68 }
69 if(count < NUMITR)
70 theRamCanvas.drawPoint(x, y, ct::csCColdeFireRamp::c(static_cast<ct::csIntType>(count*20)));
71 }
72 }
73 theRamCanvas.writeTIFFfile("juliaM_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
74 }
75 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
76 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
77}
78/** @endcond */
int main(int argc, char *argv[])