MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_wave.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_wave.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Animate a mandelbrot-like fractal with a variable coeficient.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/mandelbrotWave/index.html
9 @copyright
10 @parblock
11 Copyright (c) 1988-2022, 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 Iterate @f$f(x)=z^5+a\cdot z+c@f$ as one would @f$f(z)=z^2+c@f$ to render a Mandelbrot set. Vary the parameter @f$a@f$ by moving it around the unit circle, and
33 drop out an image for each @f$a@f$. The resulting images may be rendered into movies like this:
34
35 - Make a gif
36 convert -delay 1 -loop 0 -dispose previous mandelbrot_wave_???.tiff mandelbrot_wave_mean.gif
37 - Make a smaller gif gif
38 convert -delay 1 -loop 0 -dispose previous -resize 50% mandelbrot_wave_???.tiff mandelbrot_wave_mean_50.gif
39 - For a GIF that runs forward and backward:
40 convert -delay 1 -loop 0 -dispose previous $(ls mandelbrot_wave_???.tiff) $(ls -r mandelbrot_wave_???.tiff) mandelbrot_wave_wavy.gif
41 - Convert all the TIFF files into PNG so we can use ffmpeg to make a WEBM movie
42 ls mandelbrot_wave_???.tiff | xargs -P 0 -I{} sh -c 'echo {}; convert {} $(echo {} | sed "s/\.tiff$/.png/;")'
43 - Convert the PNGs into a WEBM
44 ffmpeg -r 15 -i mandelbrot_wave_%03d.png mandelbrot_wave_mean.webm
45 - Clean up the PNGs
46 rm mandelbrot_wave_???..png
47
48 Note the frames are rendered 8x larger than the final images. I use an 8x, mean scale down to smooth the image out a bit.
49*/
50/*******************************************************************************************************************************************************.H.E.**/
51/** @cond exj */
52
53//--------------------------------------------------------------------------------------------------------------------------------------------------------------
54#include "ramCanvas.hpp"
55
56//--------------------------------------------------------------------------------------------------------------------------------------------------------------
57typedef mjr::ramCanvas3c8b::colorType ct;
58typedef ct::csIntType cit;
59
60//--------------------------------------------------------------------------------------------------------------------------------------------------------------
61int main(void) {
62 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
63 const int NUMITR = 255;
64 const int NUMFRM = 24*16; // Full circle animation
65 //const int NUMFRM = 24*4; // Wave animation
66 const int IMXSIZ = 7680/2;
67 const int IMYSIZ = 7680/2;
68 const int MAXZSQ = 10;
69 const double ANGMIN = 0.0; // Full circle animation
70 const double ANGMAX = std::numbers::pi*2; // Full circle animation
71 // const double ANGMIN = 3.04341788317; // Wave animation
72 // const double ANGMAX = 3.23976742401; // Wave animation
73
74 for(int frame=0; frame<NUMFRM; frame++) {
75 mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -1.5, 1.5, -1.5, 1.5); // Full circle animation
76 // mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -0.7, 0.1, -0.7, 0.1); // Wave animation
77 theRamCanvas.clrCanvasToBlack();
78 std::cout << "Frame: " << frame << " of " << NUMFRM << std::endl;
79 double angle = frame*(ANGMAX-ANGMIN)/NUMFRM+ANGMIN;
80 std::complex<double> a(std::cos(angle), std::sin(angle));
81# pragma omp parallel for schedule(static,1)
82 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
83 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
84 std::complex<double> c(theRamCanvas.int2realX(x), theRamCanvas.int2realY(y));
85 std::complex<double> z(0.0, 0.0);
86 int count = 0;
87 while((std::norm(z)<MAXZSQ) && (count<=NUMITR)) {
88 z = std::pow(z, 5) + a * z + c;
89 count++;
90 }
91 if(count < NUMITR)
92 theRamCanvas.drawPoint(x, y, ct::csCColdeFireRamp::c(static_cast<ct::csIntType>(count*20)));
93 }
94 }
95 theRamCanvas.scaleDownMean(8); // Another good choice: theRamCanvas.scaleDownMax(8);
96 theRamCanvas.writeTIFFfile("mandelbrot_wave_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
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 */
102
103
int main(int argc, char *argv[])