MRaster examples 22.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_con_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 peterdejongEAAO.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief For each pixel, simulate a double pendulum system over 2sec and color the pixel according to the pendulum end state.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 2025, 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 This code makes a movie of time steps of the solution the Lorenz system. Each pixel is a complete simulation of the Lorenz system with the pixel's color
32 encoding the system state (red for x, green for y, and blue for z). The initial values for x range from -20 to 20, for z they range from 20 to 50, and y is
33 always zero.
34
35 For reference the Lorenz system is defined by:
36 @f[ \begin{array}{lcl}
37 \frac{dx}{dt} & = & a(y-x) \\
38 \frac{dy}{dt} & = & x(b-z)-y \\
39 \frac{dz}{dt} & = & xy-cz
40 \end{array} @f]
41
42 Traditional parameter values are:
43
44 @f[ \begin{array}{lcc}
45 a & = & 10 \\
46 b & = & 28 \\
47 c & = & \frac{8}{3}
48 \end{array} @f]
49
50 And the traditional initial conditions are:
51 @f[ \begin{array}{lcc}
52 x & = & \frac{1}{10} \\
53 y & = & 0 \\
54 z & = & 0
55 \end{array} @f]
56
57 This program produces an image sequence which may be rendered into a movie with ffmpeg.
58
59 ffmpeg -y -framerate 15 -i lorenz_mM_%4d.tiff -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 -crf 30 -b:v 0 -preset veryslow lorenz_mM_100_crf30.mp4;
60 ffmpeg -y -framerate 15 -i lorenz_mM_%4d.tiff -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 -crf 20 -b:v 0 -preset veryslow lorenz_mM_100_crf20.mp4;
61 ffmpeg -y -framerate 15 -i lorenz_mM_%4d.tiff -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 -crf 10 -b:v 0 -preset veryslow lorenz_mM_100_crf10.mp4;
62 ffmpeg -y -framerate 15 -i lorenz_mM_%4d.tiff -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 -crf 3 -b:v 0 -preset veryslow lorenz_mM_100_crf03.mp4;
63 ffmpeg -y -framerate 15 -i lorenz_mM_%4d.tiff -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx264 -crf 0 -b:v 0 -preset veryslow lorenz_mM_100_crf00.mp4;
64*/
65/*******************************************************************************************************************************************************.H.E.**/
66/** @cond exj */
67
68//--------------------------------------------------------------------------------------------------------------------------------------------------------------
69#include "ramCanvas.hpp"
70#include "MRMathSTR.hpp"
71#include "MRMathIVL.hpp"
72
73//--------------------------------------------------------------------------------------------------------------------------------------------------------------
74int main(void) {
75 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
76 const int NUMFRM = 40;
77 const int IMXSIZ = 7680/4;
78 const int IMYSIZ = 7680/4;
79
80 // const double a = -2.200;
81 // const double b = -1.970;
82 // const double c = 2.202;
83 // const double d = -2.300;
84 // const double e = 1.000;
85 // const double f = 2.000;
86 // const double g = -1.000;
87 // const double h = 3.000;
88
89 mjr::ramCanvas1c64F xcanvas(IMXSIZ, IMYSIZ);
90 mjr::ramCanvas1c64F ycanvas(IMXSIZ, IMYSIZ);
91
92 //mjr::ramCanvas3c8b pcolorCanvas(IMXSIZ, IMYSIZ, -2, 2, -2, 2);
93mjr::ramCanvas3c8b pcolorCanvas(IMXSIZ, IMYSIZ, -2.2, 0.8, -1.5, 1.5);
94
95 pcolorCanvas.clrCanvasToBlack();
96
97 for(int frame=0; frame<NUMFRM; frame++) {
98# pragma omp parallel for schedule(static,1)
99 for(int yi=0;yi<pcolorCanvas.getNumPixY();yi++) {
100 for(int xi=0;xi<pcolorCanvas.getNumPixX();xi++) {
101 double x, y;
102 if (frame == 0) {
103 x = pcolorCanvas.int2realX(xi);
104 y = pcolorCanvas.int2realY(yi);
105 } else {
106 x = xcanvas.getPxColorRefNC(xi, yi).getC0();
107 y = ycanvas.getPxColorRefNC(xi, yi).getC0();
108 // double xNew = std::sin(a*y + e) - std::cos(b*x + f);
109 // double yNew = std::sin(c*x + g) - std::cos(d*y + h);
110
111
112 // double xNew = std::sin(x*x-y*y+3.69);
113 // double yNew = std::cos(2*x*y+4.511);
114
115 auto z = std::pow(std::complex<double>(x, y), 2) + std::complex<double>(pcolorCanvas.int2realX(xi), pcolorCanvas.int2realY(yi));
116 double xNew = std::real(z);
117 double yNew = std::imag(z);
118
119
120
121
122 x = xNew;
123 y = yNew;
124 }
125 xcanvas.drawPoint(xi, yi, x);
126 ycanvas.drawPoint(xi, yi, y);
127 double r = mjr::math::ivl::wrapCO((x+2)/4, 1.0);
128 double g = 0;
129 double b = mjr::math::ivl::wrapCO((y+2)/4, 1.0);
130 pcolorCanvas.getPxColorRefNC(xi, yi).setChansRGB_dbl(r, g, b);
131 }
132 }
133 pcolorCanvas.writeTIFFfile("peterdejongEAAO_" + mjr::math::str::fmt_int(frame, 4, '0') + ".tiff");
134# pragma omp critical
135 std::cout << "FRAME(" << frame << "): " << "DONE" << std::endl;
136 }
137 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
138 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
139 return 0;
140}
141/** @endcond */
142
int main(int argc, char *argv[])