MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
simone_attractor_bmovie.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file simone_attractor_bmovie.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw fractals inspired by the book Symmetry in Chaos.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/sic/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 See simone_attractor.cpp for more about this attractor. Here we use the same method, but animate by letting the @f$ a @f$ and @f$ b @f$ parameters vary.
33 The following commands are used to combine the results into movies.
34
35 ffmpeg -y -framerate 15 -i simone_attractor_bmovie_%4d.tiff -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -crf 10 -b:v 0 -preset veryslow simone_attractor_bmovie_100_crf10.mp4;
36 ffmpeg -y -framerate 15 -i simone_attractor_bmovie_%4d.tiff -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -crf 0 -b:v 0 -preset veryslow simone_attractor_bmovie_100_crf00.mp4;
37 magick -delay 1 -loop 0 -dispose previous simone_attractor_bmovie_????.tiff simone_attractor_bmovie_100.gif
38
39*/
40/*******************************************************************************************************************************************************.H.E.**/
41/** @cond exj */
42
43//--------------------------------------------------------------------------------------------------------------------------------------------------------------
44#include "ramCanvas.hpp"
45#include "MRMathSTR.hpp"
46
47//--------------------------------------------------------------------------------------------------------------------------------------------------------------
48int main(void) {
49 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
50 const int BSIZ = 6400;
51 const int NUMFRM = 15*6;
52 const double R = 0.002;
53 const double ANGMIN = 0.0;
54 const double ANGMAX = std::numbers::pi*2;
55 const uint64_t MAXITR = 10000000;
56
57# pragma omp parallel for schedule(static,1)
58 for(int frame=0; frame<NUMFRM; frame++) {
59 mjr::ramCanvas1c16b theRamCanvas(BSIZ, BSIZ, -0.6, 0.6, -0.25, 1.0);
60 decltype(theRamCanvas)::coordFltType angle = frame*(ANGMAX-ANGMIN)/NUMFRM+ANGMIN;
61 decltype(theRamCanvas)::coordFltType a = 0.382110 + R * std::cos(angle);
62 decltype(theRamCanvas)::coordFltType b = -1.012590 + R * std::sin(angle);
63 decltype(theRamCanvas)::coordFltType xn = 0;
64 decltype(theRamCanvas)::coordFltType yn = 0;
65 for(uint64_t i=0;i<MAXITR;i++) {
66 decltype(theRamCanvas)::coordFltType tmp = std::sin(xn*xn-yn*yn+a);
67 yn = std::cos(2*xn*yn+b);
68 xn = tmp;
69 if(i>1000) {
70 decltype(theRamCanvas)::coordIntType ix = theRamCanvas.real2intX(xn);
71 decltype(theRamCanvas)::coordIntType iy = theRamCanvas.real2intY(yn);
72 if (theRamCanvas.isOnCanvas(ix, iy))
73 theRamCanvas.getPxColorRefNC(ix, iy).tfrmAdd(1);
74 }
75 }
76 theRamCanvas.autoHistStrech();
77 theRamCanvas.applyHomoPixTfrm(&decltype(theRamCanvas)::colorType::tfrmPow, 1/4.0);
78 theRamCanvas.rotate90CW();
79 theRamCanvas.scaleDownMean(8);
80 theRamCanvas.autoHistStrech();
81# pragma omp critical
82 std::cout << "FRAME(" << frame << "): DONE" << std::endl;
83 theRamCanvas.writeTIFFfile("simone_attractor_bmovie_" + mjr::math::str::fmt_int(frame, 4, '0') + ".tiff",
84 mjr::ramCanvasPixelFilter::ColorSchemeOnChan<decltype(theRamCanvas),
85 mjr::color3c8b,
86 mjr::color3c8b::csCColdeFireRamp>(theRamCanvas));
87
88 }
89 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
90 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
91 return 0;
92}
93/** @endcond */
int main(int argc, char *argv[])