MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_count_movie.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_count_movie.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Simplified code for for web page examples.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/mandelbrot/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 Create a gif like this:
33 time convert -delay 1 -loop 0 -dispose previous mandelbrot_count_movie_???.tiff mandelbrot_count_movie.gif
34 Convert TIFFs to PNGs:
35 ls mandelbrot_count_movie_???.tiff | xargs -P 8 -I{} sh -c 'echo {}; convert {} $(echo {} | sed "s/\.tiff$/.png/;")'
36 Convert PNGs into a WEBM
37 ffmpeg -r 15 -i mandelbrot_count_movie_%03d.png -crf 20 mandelbrot_count_movie.webm
38 Convert TIFFs to PNGs at 45% size:
39 ls mandelbrot_count_movie_???.tiff | xargs -P 8 -I{} sh -c 'echo {}; convert {} -resize 45% $(echo {} | sed "s/\.tiff$/_45.png/;")'
40 Convert 45% PNGs into a WEBM
41 ffmpeg -r 15 -i mandelbrot_count_movie_%03d_45.png -crf 20 mandelbrot_count_movie_45.webm
42*/
43/*******************************************************************************************************************************************************.H.E.**/
44/** @cond exj */
45
46//--------------------------------------------------------------------------------------------------------------------------------------------------------------
47#include "ramCanvas.hpp"
48
49//--------------------------------------------------------------------------------------------------------------------------------------------------------------
50typedef mjr::ramCanvas3c8b::colorType ct;
51
52//--------------------------------------------------------------------------------------------------------------------------------------------------------------
53int main(void) {
54 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
55 const double MAXZSQ = 4.0;
56 const int IMGSIZ = 7680/4;
57
58 const int MXITRS = 157;
59 const double BALSIZ = 0.00019065;
60 const double CNTRX = -0.745258237857;
61 const double CNTRY = 0.130272017858;
62 const int ITRSTP = 1;
63 const int NUMFRM = 304;
64 const int COLMAG = 1;
65
66 // const double BALSIZ = 6.25e-7;
67 // const double CNTRX = 0.241810410968;
68 // const double CNTRY = -0.510269600591;
69 // const int MXITRS = 750;
70 // const int MXITRE = 2000;
71 // const int ITRSTP = 3;
72 // const int NUMFRM = (MXITRE-MXITRS)/ITRSTP+1;
73 // const int COLMAG = 10;
74
75# pragma omp parallel for schedule(static,1)
76 for(int frame=0; frame<NUMFRM; frame++) {
77 int curMaxItr = MXITRS + frame * ITRSTP;
78 mjr::ramCanvas3c8b theRamCanvas(IMGSIZ, IMGSIZ, CNTRX-BALSIZ, CNTRX+BALSIZ, CNTRY-BALSIZ, CNTRY+BALSIZ);
79 std::chrono::time_point<std::chrono::system_clock> frameStartTime = std::chrono::system_clock::now();
80 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
81 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
82 std::complex<double> c = theRamCanvas.int2real(x, y);
83 std::complex<double> z(0.0, 0.0);
84 int count = 0;
85 while((std::norm(z)<MAXZSQ) && (count<=curMaxItr)) {
86 z=std::pow(z, 2) + c;
87 count++;
88 }
89 if(count < curMaxItr)
90 theRamCanvas.drawPoint(x, y, ct::csCColdeFireRamp::c(static_cast<ct::csFltType>(COLMAG*count)/curMaxItr));
91 }
92 }
93 theRamCanvas.writeTIFFfile("mandelbrot_count_movie_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
94 std::chrono::duration<double> frameRunTime = std::chrono::system_clock::now() - frameStartTime;
95# pragma omp critical
96 std::cout << "Frame " << frame << " of " << NUMFRM << " Runtime " << frameRunTime.count() << " sec" << std::endl;
97 }
98 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
99 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
100}
101/** @endcond */
int main(int argc, char *argv[])